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[:]))
}
微信支付接口签名校验工具
https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=20_1
可以用在线工具验证一下计算的签名,https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=20_1,另外你确定你的key是正确的吗?