This commit is contained in:
邹宗楠
2025-07-30 15:04:03 +08:00
parent 40c1a73751
commit 266af058d6
7 changed files with 1854 additions and 1699 deletions

View File

@@ -7,7 +7,6 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"strconv"
"strings"
@@ -18,13 +17,12 @@ func Sign(appKey, appSecret, method string, timestamp int64, paramJson string) s
// 按给定规则拼接参数
paramPattern := "app_key" + appKey + "method" + method + "param_json" + paramJson + "timestamp" + strconv.FormatInt(timestamp, 10) + "v2"
signPattern := appSecret + paramPattern + appSecret
fmt.Println("sign_pattern:" + signPattern)
return Hmac(signPattern, appSecret)
}
func SpiSign(appKey, appSecret, timestamp string, paramJson interface{}, signMethod string) string {
sortedParamStr := Marshal(paramJson)
paramPattern := "app_key" + appKey + "param_json" + sortedParamStr +"timestamp" + timestamp
paramPattern := "app_key" + appKey + "param_json" + sortedParamStr + "timestamp" + timestamp
signPattern := appSecret + paramPattern + appSecret
if signMethod == "hmac-sha256" {
return Hmac(signPattern, appSecret)
@@ -67,5 +65,3 @@ func Marshal(o interface{}) string {
marshal := strings.TrimSpace(buffer.String()) // Trim掉末尾的换行符
return marshal
}