|
|
@@ -2,10 +2,8 @@ package pay
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
- "crypto/md5"
|
|
|
"encoding/xml"
|
|
|
"fmt"
|
|
|
- "strings"
|
|
|
"github.com/silenceper/wechat/context"
|
|
|
"github.com/silenceper/wechat/util"
|
|
|
)
|
|
|
@@ -88,12 +86,9 @@ func NewPay(ctx *context.Context) *Pay {
|
|
|
func (pcf *Pay) PrePayId(p *PayParams) (prePayID string, err error) {
|
|
|
nonceStr := util.RandomStr(32)
|
|
|
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"
|
|
|
- str := fmt.Sprintf(template, pcf.AppID, p.Body, pcf.PayMchID, nonceStr, pcf.PayNotifyURL, p.OutTradeNo, p.CreateIP, p.TotalFee, tradeType)
|
|
|
- str = str + "&key=" + pcf.PayKey
|
|
|
- sum := md5.Sum([]byte(str))
|
|
|
- signature := string(sum[:])
|
|
|
- sign := strings.ToUpper(signature)
|
|
|
+ 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&key=%s"
|
|
|
+ str := fmt.Sprintf(template, pcf.AppID, p.Body, pcf.PayMchID, nonceStr, pcf.PayNotifyURL, p.OutTradeNo, p.CreateIP, p.TotalFee, tradeType, pcf.PayKey)
|
|
|
+ sign := util.Md5Sum(str)
|
|
|
request := payRequest{
|
|
|
AppID: pcf.AppID,
|
|
|
MchID: pcf.PayMchID,
|
|
|
@@ -123,6 +118,6 @@ func (pcf *Pay) PrePayId(p *PayParams) (prePayID string, err error) {
|
|
|
}
|
|
|
return "", errors.New(payRet.ErrCode + payRet.ErrCodeDes)
|
|
|
} else {
|
|
|
- return "", errors.New("xml unmarshal err : raw - " + string(rawRet))
|
|
|
+ return "", errors.New("[msg : xmlUnmarshalError] [rawReturn : " + string(rawRet) + "] [params : " + str + "] [sign : " + sign + "]")
|
|
|
}
|
|
|
}
|