请求头
{
"GO-OPS-X-APPID":"你的appid",
"GO-OPS-X-SIGNATURE":"签名值",
"GO-OPS-X-TIMESTAMP":"时间戳",
"GO-OPS-X-NONCE":"请求唯一id"
}
签名
使用sha1作为签名算法,seckey作为签名使用key,依次把apikey、nonce、timestame、body 写入签名内容中,最后对签名结果进行base64转码。
Golang 示例
func GetSign(apikey string, seckey string, nonce, timestamp string, body []byte) (r string) {
key := []byte(seckey)
mac := hmac.New(sha1.New, key)
mac.Write([]byte(apikey))
mac.Write([]byte(nonce))
mac.Write([]byte(timestamp))
mac.Write(body)
r = base64.StdEncoding.EncodeToString(mac.Sum(nil))
return
}
python
def getSign(self, nonce, timestamp, body):
mac = hmac.new(bytes(self.seckey, encoding='utf-8'), None, hashlib.sha1)
mac.update(bytes(self.apikey, encoding='utf-8'))
mac.update(bytes(nonce, encoding='utf-8'))
mac.update(bytes(str(timestamp), encoding='utf-8'))
mac.update(bytes(body, encoding='utf-8'))
return base64.b64encode(mac.digest()).decode()