回调签名改为与开放 API 一致的字典序拼接风格
- 签名串由 timestamp+换行+bodyhash 改为 body_sha256=<hash>×tamp=<unix秒>(ASCII 字典序 & 拼接) - 同步更新对接文档
This commit is contained in:
@@ -379,10 +379,14 @@ func (s *CallbackService) Run(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// BuildCallbackSign 供接收方校验:HMAC-SHA256(secret, timestamp + "\n" + sha256(body))。
|
||||
// BuildCallbackSign 供接收方校验。签名风格与开放 API 一致:
|
||||
// 参数按 ASCII 字典序 + "&" 拼接,body 以 SHA256 摘要参与签名。
|
||||
//
|
||||
// content = body_sha256=<sha256hex(body)>×tamp=<unix秒>
|
||||
// X-Sign = hex(HMAC-SHA256(secret, content))
|
||||
func BuildCallbackSign(secret, timestamp, body string) string {
|
||||
bodyHash := sha256.Sum256([]byte(body))
|
||||
content := timestamp + "\n" + hex.EncodeToString(bodyHash[:])
|
||||
content := "body_sha256=" + hex.EncodeToString(bodyHash[:]) + "×tamp=" + timestamp
|
||||
mac := hmac.New(sha256.New, []byte(secret))
|
||||
_, _ = mac.Write([]byte(content))
|
||||
return hex.EncodeToString(mac.Sum(nil))
|
||||
|
||||
Reference in New Issue
Block a user