云鼎测试新订单

This commit is contained in:
苏尹岚
2020-07-30 13:47:14 +08:00
parent ca3222cc64
commit 93bc9ce8ff
3 changed files with 73 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
package jdshop
import (
"encoding/base64"
"encoding/hex"
"encoding/json"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
)
var (
KeyList []*Key
)
type Key struct {
ID string `json:"id"`
KeyExp int64 `json:"key_exp"`
KeyStatus int `json:"key_status"`
KeyDigest string `json:"key_digest"`
KeyType string `json:"key_type"`
KeyString string `json:"key_string"`
KeyEffective int64 `json:"key_effective"`
Version int `json:"version"`
}
func InitKey() {
keyResult, err := api.JdShopAPI.KeyGet()
if err != nil {
return
}
for _, v := range keyResult.Response.ServiceKeyList[0].Keys {
data, _ := json.Marshal(v)
vv := &Key{}
err = json.Unmarshal(data, &vv)
KeyList = append(KeyList, 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
}
}
globals.SugarLogger.Debugf("no key can equal..")
return key
}