# 签名验证
# 签名算法
部分服务端接口需要使用 session_key 进行用户身份校验,为了保持 session_key 私密性,接口不明文传输 session_key,而是通过校验登录态签名 signature 完成。
登录态签名的生成方式可表示为:signature = hmac_sha256(session_key, rawData),其中 rawData 为开发者在请求服务端接口时携带的参数(Request Body)。
# 示例代码(Golang):
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
)
func signature(rawData []byte, sessionKey string) string {
h := hmac.New(sha256.New, []byte(sessionKey))
h.Write(rawData)
raw := h.Sum(nil)
return hex.EncodeToString(raw)
}