zhangzengfei
2023-11-28 3a706d3378aa3626501370352963883fd2783558
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package util
 
import (
    "basic.com/valib/logger.git"
    "encoding/base64"
    "encoding/json"
    "errors"
    "io/ioutil"
    "strings"
)
 
func GetVamicroPath() string {
    /*myPath := utils.GetExePath()
    parentP := string([]rune(myPath)[0:strings.LastIndex(myPath, "/")])
    if !strings.HasSuffix(parentP, "vamicro") {
        parentP = parentP + "/vamicro"
    }*/
    //fmt.Println("vamicro path" + parentP)
    return "/opt/vasystem"
}
 
//获取授权文件
func GetAuthorization() string {
    snFile := GetVamicroPath() + "/auth.txt"
    if FileExists(snFile) {
        sn, err := ioutil.ReadFile(snFile)
        if nil == err {
            return string(sn)
        }
    }
    return ""
}
 
//获取激活码
func GetSn() string {
    snFile := GetVamicroPath() + "/sn.txt"
    if FileExists(snFile) {
        sn, err := ioutil.ReadFile(snFile)
        if nil == err {
            return strings.TrimSpace(string(sn))
        }
    }
    return ""
}
 
type AuthorizationInfo struct {
    Sn string `json:"sn,omitempty"` //请求码
 
    DevCount       int        `json:"devCount,omitempty"`       //设备数量
    ChCount        int        `json:"chCount,omitempty"`        //通道数量
    CameraCount    int        `json:"cameraCount,omitempty"`    //摄像机数量
    ActiveDevCount int        `json:"activeDevCount,omitempty"` //激活设备数量
    ServeYear      int        `json:"serveYear,omitempty"`
    DevId          string     `json:"devId,omitempty"`          //机器ID
    ActivateCode   string     `json:"activateCode,omitempty"`   //授权码
    ExpirationTime int64      `json:"expirationTime,omitempty"` //授权过期时间
    OldDeviceId    string     `json:"oldDeviceId,omitempty"`    //旧机器ID
    Sdks           []string   `json:"sdks,omitempty"`           //SDK 列表
    Apps           []string   `json:"apps,omitempty"`           //APP 列表
    Setting        PdtSetting `json:"Setting,omitempty"`        //产品限制(使用时间等)
    Edition        string     `json:"edition,omitempty"`        //产品版本
    MachineCode    string     `json:"machineCode,omitempty"`    //机器码
    InstallTime    string     `json:"installTime,omitempty"`    //安装时间
    DeviceType     string     `json:"deviceType,omitempty"`     //设备类型
    DeviceMode     string     `json:"deviceMode,omitempty"`     //设备型号
    VGpu           string     `json:"vGpu,omitempty"`           //设备端实际的显卡型号
 
    UserType   string `json:"userType,omitempty"`   //个人:personal  公司: company
    PhoneNum   string `json:"phoneNum,omitempty"`   //手机号码
    Name       string `json:"name,omitempty"`       //姓名或公司名称
    ProvinceId string `json:"provinceId,omitempty"` //省
    CityId     string `json:"cityId,omitempty"`     //市
    CountyId   string `json:"countyId,omitempty"`   //县
    Email      string `json:"email,omitempty"`      //邮箱
}
 
func GetAuthorizationInfo(cipher string) (authinfo AuthorizationInfo, err error) {
    var authinfo1 AuthorizationInfo
    if cipher == "" {
        return authinfo1, errors.New("GetAuthorizationInfo invalid cipher")
    }
 
    //logger.Debug("authinfo", cipher)
    screct, err := base64.StdEncoding.DecodeString(cipher)
    if nil != err {
        logger.Error("GetAuthorization base64.StdEncoding.DecodeString failed, err:", err.Error())
        return authinfo1, err
    }
    decodeBytes, err := RsaDecrypt(screct)
    if err != nil {
        logger.Error("GetAuthorization utils.RsaDecrypt failed, err:", err.Error())
        return authinfo1, err
    }
 
    err = json.Unmarshal(decodeBytes, &authinfo1)
    if err != nil {
        logger.Error("GetAuthorization json.Unmarshal failed, err:", err.Error())
        return authinfo1, err
    }
 
    //logger.Debug(authinfo1)
    return authinfo1, nil
}