licence

package module
v0.1.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 13 Imported by: 0

README

licence

Description

Go 版序列号

Installation
go get gitee.com/eshax/licence
Usage
  • go.mod
module licence.test

go 1.19

require gitee.com/eshax/licence v0.1.3
  • main.go
package main

import (
    "os"
    "gitee.com/eshax/licence"
)

func main() {

    //
    // 固定码(项目内自定义)
    //
    fixedCode := "test"


    //
    // 查询机器码, 根据当前程序所在的硬件环境计算机器码
    // 
    MachineCode := licence.GetMachineCode(fixedCode)


    //
    // 生成激活码, 根据已知某个服务器的机器码后, 附加限制日期以及参数后, 生成激活码
    //
    date := "2023-12-31"
    param := licence.Parameters{
        Testing:        true,
        UseQRCode:      true,
        UseQRCodeCount: 3,
        AllowPB:        true,
        AllowBM:        true,
    }
    machineCode := "BM26H8L9"
    ActivationCode, err := licence.CreateActivationCode(machineCode, date, param, fixedcode)


    //
    // 验证激活码, 当前服务器验证序列号
    //
    activationCode := "5PA-LP213R-B5E"
    activationStatus, date, parameters, err := CheckActivationCode(activationCode, fixedCode)
}

Documentation

Index

Constants

View Source
const (
	// 日期显示格式
	DateFormat = "2006-01-02"
)
View Source
const (
	// 保留位
	Reserve = "00"
)

Variables

This section is empty.

Functions

func CreateActivationCode added in v0.1.2

func CreateActivationCode(machineCode string, date string, params Parameters, fixedCode string) (activationCode string, err error)

生成激活码

input:
	machineCode: 机器码
	       date: 日期 (Format: 2006-12-03)
	     params: 参数 (Struct: Parameters)
	  fixedCode: 固定码
output:
	activationCode: 激活码 (XXXX-XXXX-XXXX)
	           err: 异常信息

func CreateQRCode added in v0.1.6

func CreateQRCode(qr QRCode, fixedCode string) (batchCode string, qrCodeList []string, err error)

根据玻片批次码,批量生产二维码数据

func GetMachineCode

func GetMachineCode(fixedcode string) string

获取机器码 @param fixedcode 参与MD5计算

func VerifyDate added in v0.1.7

func VerifyDate(date string) bool

检查日期格式

2006-01-02

Types

type Categorys added in v0.1.6

type Categorys int
const (
	Category_B Categorys = iota
	Category_P
	Category_K
	Category_L
	Category_Y
	Category_R
)

func GetCategory added in v0.1.6

func GetCategory(c string) Categorys

func (Categorys) String added in v0.1.6

func (c Categorys) String() string

type Parameters added in v0.1.5

type Parameters struct {
	Testing        bool // [0] true:测试版 false:正式版
	UseQRCode      bool // [1] true:强制使用玻片二维码
	UseQRCodeCount int  // [2-3] 允许使用二维码的次数 (0, 1, 3, 5) (0:无限制)
	AllowRD        bool // [26] R带(核型) (True:允许)
	AllowYS        bool // [27] 羊水(核型) (True:允许)
	AllowPB        bool // [28] 外周血(形态/核型) (True:允许)
	AllowBM        bool // [29] 骨髓(形态/核型) (True:允许)
}

func CheckActivationCode added in v0.1.2

func CheckActivationCode(activationCode string, fixedCode string) (status bool, date string, parameters Parameters, err error)

在生产服务器上验证激活码

input:
	activationcode: 激活码
	     fixedcode: 固定码
output:
	    status: 激活状态
	      date: 到期日期
	parameters: 参数
	       err: 异常信息

type QRCode added in v0.1.6

type QRCode struct {
	Category Categorys // 类型
	Batch    int       // 批号, 采用34进制 (占用4个字节) (0 ~ 1336335)
	No       int       // 编号, 采用34进制 (占用2个字节) (0 ~ 1155)
	UseTimes int       // 限制扫描的次数 (1个字节) 采用34进制 (0 ~ 33) (0:无限制)
}

批次二维码、标签二维码

B 0001 00 1 00 AB
|    |  | |  |  +--- (2字节) 签名
|    |  | |  +------ (2字节) 保留
|    |  | +--------- (1字节) 限制次数
|    |  +----------- (1字节) 编号 (每一批中实际最大的号做为这一批的批次码, 小于的做为标签码) (理论最大值: 1155)
|    +-------------- (2字节) 批号 (最大值1336335)
+------------------- (4字节) 类型 BPKLYR

func CheckQRCode added in v0.1.6

func CheckQRCode(qrcode string, fixedCode string) (status bool, qr QRCode, err error)

检验标签码

input:
	   qrcode: 标签码字符串
	fixedCode: 固定码
output:
	status: 检验状态
	    qr: 标签码 (Struct: QRCode)
	   err: 异常状态信息

func (QRCode) String added in v0.1.6

func (qr QRCode) String(fixedCode string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL