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
|
}
|