mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-11 00:02:27 +08:00
fix payment bug
This commit is contained in:
@@ -87,10 +87,10 @@ func NewPay(ctx *context.Context) *Pay {
|
|||||||
// PrePayId will request wechat merchant api and request for a pre payment order id
|
// PrePayId will request wechat merchant api and request for a pre payment order id
|
||||||
func (pcf *Pay) PrePayId(p *PayParams) (prePayID string, err error) {
|
func (pcf *Pay) PrePayId(p *PayParams) (prePayID string, err error) {
|
||||||
nonceStr := util.RandomStr(32)
|
nonceStr := util.RandomStr(32)
|
||||||
pType := "JSAPI"
|
tradeType := "JSAPI"
|
||||||
template := "appid=%s&body=%s&mch_id=%s&nonce_str=%s¬ify_url=%s&out_trade_no=%s&spbill_create_ip=%s&total_fee=%s&trade_type=%s"
|
template := "appid=%s&body=%s&mch_id=%s&nonce_str=%s¬ify_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 := fmt.Sprintf(template, pcf.AppID, p.Body, pcf.PayMchID, nonceStr, pcf.PayNotifyURL, p.OutTradeNo, p.CreateIP, p.TotalFee, tradeType)
|
||||||
str += pcf.PayKey
|
str += "&key="pcf.PayKey
|
||||||
sum := md5.Sum([]byte(str))
|
sum := md5.Sum([]byte(str))
|
||||||
signature := string(sum[:])
|
signature := string(sum[:])
|
||||||
sign := strings.ToUpper(signature)
|
sign := strings.ToUpper(signature)
|
||||||
@@ -98,13 +98,14 @@ func (pcf *Pay) PrePayId(p *PayParams) (prePayID string, err error) {
|
|||||||
AppID: pcf.AppID,
|
AppID: pcf.AppID,
|
||||||
MchID: pcf.PayMchID,
|
MchID: pcf.PayMchID,
|
||||||
NotifyUrl: pcf.PayNotifyURL,
|
NotifyUrl: pcf.PayNotifyURL,
|
||||||
NonceStr: util.RandomStr(32),
|
NonceStr: nonceStr,
|
||||||
Sign: sign,
|
Sign: sign,
|
||||||
Body: p.Body,
|
Body: p.Body,
|
||||||
OutTradeNo: p.OutTradeNo,
|
OutTradeNo: p.OutTradeNo,
|
||||||
TotalFee: p.TotalFee,
|
TotalFee: p.TotalFee,
|
||||||
SpbillCreateIp: p.CreateIP,
|
SpbillCreateIp: p.CreateIP,
|
||||||
OpenID: p.OpenID,
|
OpenID: p.OpenID,
|
||||||
|
TradeType: tradeType,
|
||||||
}
|
}
|
||||||
rawRet, err := util.PostXML(payGateway, request)
|
rawRet, err := util.PostXML(payGateway, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user