This commit is contained in:
duyu 2024-07-24 11:17:25 +08:00
parent 5ab328ea53
commit bd9151d3f3
1 changed files with 8 additions and 3 deletions

View File

@ -25,7 +25,7 @@ func getMD5Hash(input string) string {
return hex.EncodeToString(hash[:])
}
func GenMD5Sign(data map[string]interface{}, secretKey string) string {
func GenMD5Sign(data map[string]interface{}, secretKey string) (string,string) {
keys := make([]string, 0, len(data))
for key := range data {
if key != "sign" && key != "Sign" {
@ -43,8 +43,9 @@ func GenMD5Sign(data map[string]interface{}, secretKey string) string {
rawStr += fmt.Sprintf("%s=%s", key, value)
}
rawStr += "&key=" + secretKey
// fmt.Println(rawStr)
sign := strings.ToUpper(getMD5Hash(rawStr))
return sign
return sign,rawStr
}
func VerifySign() gin.HandlerFunc {
@ -81,8 +82,12 @@ func VerifySign() gin.HandlerFunc {
return
}
//验证签名是否正确
hash := GenMD5Sign(data, merchant.PrivateKey)
data["time_stamp"] = int(data["time_stamp"].(float64))
hash,rawStr := GenMD5Sign(data, merchant.PrivateKey)
// fmt.Println(hash)
logger.Info(c, "RawStr", rawStr)
logger.Info(c, "Sign", hash)
if hash != data["sign"] {
common.Error(c, 400, "签名错误")
c.Abort()