代码拉取完成,页面将自动刷新
同步操作将从 北京小程科技有限公司/微信 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package wechat
import (
"bytes"
"crypto/hmac"
"crypto/md5"
"crypto/sha256"
"encoding/hex"
"fmt"
"strings"
)
// JSAPI支付,统一下单获取支付参数后,再次计算出小程序用的paySign
func GetMiniPaySign(appId, nonceStr, prepayId, signType, timeStamp, apiKey string) (paySign string) {
// 原始字符串
raw := fmt.Sprintf("appId=%s&nonceStr=%s&package=%s&signType=%s&timeStamp=%s&key=%s",
appId, nonceStr, prepayId, signType, timeStamp, apiKey)
buffer := new(bytes.Buffer)
buffer.WriteString(raw)
signStr := buffer.String()
// 加密签名
var hashSign []byte
if signType == SignTypeHmacSHA256 {
hash := hmac.New(sha256.New, []byte(apiKey))
hash.Write([]byte(signStr))
hashSign = hash.Sum(nil)
} else {
hash := md5.New()
hash.Write([]byte(signStr))
hashSign = hash.Sum(nil)
}
paySign = strings.ToUpper(hex.EncodeToString(hashSign))
return
}
// JSAPI支付,统一下单获取支付参数后,再次计算出微信内H5支付需要用的paySign
func GetH5PaySign(appId, nonceStr, packages, signType, timeStamp, apiKey string) (paySign string) {
// 原始字符串
raw := fmt.Sprintf("appId=%s&nonceStr=%s&package=%s&signType=%s&timeStamp=%s&key=%s",
appId, nonceStr, packages, signType, timeStamp, apiKey)
buffer := new(bytes.Buffer)
buffer.WriteString(raw)
signStr := buffer.String()
// 加密签名
var hashSign []byte
if signType == SignTypeHmacSHA256 {
hash := hmac.New(sha256.New, []byte(apiKey))
hash.Write([]byte(signStr))
hashSign = hash.Sum(nil)
} else {
hash := md5.New()
hash.Write([]byte(signStr))
hashSign = hash.Sum(nil)
}
paySign = strings.ToUpper(hex.EncodeToString(hashSign))
return
}
// APP支付,统一下单获取支付参数后,再次计算APP支付所需要的的sign
func GetAppPaySign(appId, nonceStr, partnerId, prepayId, signType, timeStamp, apiKey string) (paySign string) {
// 原始字符串
raw := fmt.Sprintf("appId=%s&nonceStr=%s&package==Sign=WXPay&partnerid=%s&prepayid=%s&timeStamp=%s&key=%s",
appId, nonceStr, partnerId, prepayId, timeStamp, apiKey)
buffer := new(bytes.Buffer)
buffer.WriteString(raw)
// 加密签名
signStr := buffer.String()
var hashSign []byte
if signType == SignTypeHmacSHA256 {
hash := hmac.New(sha256.New, []byte(apiKey))
hash.Write([]byte(signStr))
hashSign = hash.Sum(nil)
} else {
hash := md5.New()
hash.Write([]byte(signStr))
hashSign = hash.Sum(nil)
}
paySign = strings.ToUpper(hex.EncodeToString(hashSign))
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。