transfer_middleware/until/common/zltx.go

30 lines
601 B
Go
Raw Normal View History

2024-06-07 11:11:04 +08:00
package common
import (
"fmt"
"sort"
"strings"
)
func ZltxSign(postData map[string]interface{}, secret string) string {
// 第一步把key升序
keys := make([]string, 0, len(postData))
for key := range postData {
keys = append(keys, key)
}
sort.Strings(keys)
// 第二步:生成签名
// 拼接用于生成签名的原始字符串
rawStr := ""
for _, key := range keys {
value := fmt.Sprintf("%v", postData[key])
if rawStr != "" {
rawStr += "&"
}
rawStr += fmt.Sprintf("%s=%s", key, value)
}
rawStr += "&key=" + secret
return strings.ToUpper(GetMD5Hash(rawStr))
}