1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-04 21:02:25 +08:00

fix payment bug

This commit is contained in:
Mongo
2017-10-31 16:45:59 +08:00
parent d199cc947b
commit 1d2f06365e

View File

@@ -87,10 +87,10 @@ func NewPay(ctx *context.Context) *Pay {
// PrePayId will request wechat merchant api and request for a pre payment order id
func (pcf *Pay) PrePayId(p *PayParams) (prePayID string, err error) {
nonceStr := util.RandomStr(32)
pType := "JSAPI"
tradeType := "JSAPI"
template := "appid=%s&body=%s&mch_id=%s&nonce_str=%s&notify_url=%s&out_trade_no=%s&spbill_create_ip=%s&total_fee=%s&trade_type=%s"
str := fmt.Sprintf(template, pcf.AppID, p.Body, pcf.PayMchID, nonceStr, pcf.PayNotifyURL, p.OutTradeNo, p.CreateIP, p.TotalFee, pType)
str += pcf.PayKey
str := fmt.Sprintf(template, pcf.AppID, p.Body, pcf.PayMchID, nonceStr, pcf.PayNotifyURL, p.OutTradeNo, p.CreateIP, p.TotalFee, tradeType)
str += "&key="pcf.PayKey
sum := md5.Sum([]byte(str))
signature := string(sum[:])
sign := strings.ToUpper(signature)
@@ -98,13 +98,14 @@ func (pcf *Pay) PrePayId(p *PayParams) (prePayID string, err error) {
AppID: pcf.AppID,
MchID: pcf.PayMchID,
NotifyUrl: pcf.PayNotifyURL,
NonceStr: util.RandomStr(32),
NonceStr: nonceStr,
Sign: sign,
Body: p.Body,
OutTradeNo: p.OutTradeNo,
TotalFee: p.TotalFee,
SpbillCreateIp: p.CreateIP,
OpenID: p.OpenID,
TradeType: tradeType,
}
rawRet, err := util.PostXML(payGateway, request)
if err != nil {