收藏
回答

golang 微信h5支付,显示签名错误,请检查后再试 是什么问题?

signParams := map[string]string{

"appid":            app_id,

"mch_id":           mch_id,

"nonce_str":        nonceStr,

"body":             body,

"out_trade_no":     outTradeNo,

"total_fee":        fmt.Sprintf("%d", totalFee),

"spbill_create_ip": spbillCreateIP,

"notify_url":       notifyURL,

"trade_type":       tradeType,

}

sign := generateSign(signParams, key)

fmt.Println("Sign:", sign)


func generateSign(params map[string]string, key string) string {

var keys []string

for k := range params {

if k != "sign" && params[k] != "" {

keys = append(keys, k)

}

}

sort.Strings(keys)

var signStr string

for _, k := range keys {

signStr += k + "=" + params[k] + "&"

}

signStr += "key=" + key

hash := md5.Sum([]byte(signStr))

return strings.ToUpper(hex.EncodeToString(hash[:]))

}




回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容