请求头

  1. {
  2. "GO-OPS-X-APPID":"你的appid",
  3. "GO-OPS-X-SIGNATURE":"签名值",
  4. "GO-OPS-X-TIMESTAMP":"时间戳",
  5. "GO-OPS-X-NONCE":"请求唯一id"
  6. }

签名

使用sha1作为签名算法,seckey作为签名使用key,依次把apikey、nonce、timestame、body 写入签名内容中,最后对签名结果进行base64转码。

  • Golang 示例

    1. func GetSign(apikey string, seckey string, nonce, timestamp string, body []byte) (r string) {
    2. key := []byte(seckey)
    3. mac := hmac.New(sha1.New, key)
    4. mac.Write([]byte(apikey))
    5. mac.Write([]byte(nonce))
    6. mac.Write([]byte(timestamp))
    7. mac.Write(body)
    8. r = base64.StdEncoding.EncodeToString(mac.Sum(nil))
    9. return
    10. }
  • python

    1. def getSign(self, nonce, timestamp, body):
    2. mac = hmac.new(bytes(self.seckey, encoding='utf-8'), None, hashlib.sha1)
    3. mac.update(bytes(self.apikey, encoding='utf-8'))
    4. mac.update(bytes(nonce, encoding='utf-8'))
    5. mac.update(bytes(str(timestamp), encoding='utf-8'))
    6. mac.update(bytes(body, encoding='utf-8'))
    7. return base64.b64encode(mac.digest()).decode()