This commit is contained in:
苏尹岚
2020-12-01 16:52:53 +08:00
parent 017ba5966a
commit 43186f5b12
3 changed files with 68 additions and 26 deletions

View File

@@ -11,7 +11,8 @@ import (
)
var (
KeyList []*Key
KeyList []*Key
KeyList2 []*Key
)
type Key struct {
@@ -36,14 +37,33 @@ func InitKey() {
err = json.Unmarshal(data, &vv)
KeyList = append(KeyList, vv)
}
keyResult2, err := api.JdShop2API.KeyGet()
if err != nil {
return
}
for _, v := range keyResult2.Response.ServiceKeyList[0].Keys {
data, _ := json.Marshal(v)
vv := &Key{}
err = json.Unmarshal(data, &vv)
KeyList2 = append(KeyList2, vv)
}
globals.SugarLogger.Debugf("jdshop key refreshed..")
}
func GetKey(keySign string) (key string) {
for _, v := range KeyList {
data, _ := base64.StdEncoding.DecodeString(v.ID)
if keySign == hex.EncodeToString(data) {
return v.KeyString
func GetKey(keySign, vendorOrgCode string) (key string) {
if vendorOrgCode == "1" {
for _, v := range KeyList {
data, _ := base64.StdEncoding.DecodeString(v.ID)
if keySign == hex.EncodeToString(data) {
return v.KeyString
}
}
} else {
for _, v := range KeyList2 {
data, _ := base64.StdEncoding.DecodeString(v.ID)
if keySign == hex.EncodeToString(data) {
return v.KeyString
}
}
}
globals.SugarLogger.Debugf("no key can equal..")