mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
统一下单接口修改tradeType:可以从param中指定使用什么tradeType;方便使用者根据不同使用场景调用
This commit is contained in:
@@ -24,6 +24,7 @@ type Params struct {
|
||||
Body string
|
||||
OutTradeNo string
|
||||
OpenID string
|
||||
TradeType string
|
||||
}
|
||||
|
||||
// Config 是传出用于 jsdk 用的参数
|
||||
@@ -86,9 +87,8 @@ func NewPay(ctx *context.Context) *Pay {
|
||||
// PrePayOrder return data for invoke wechat payment
|
||||
func (pcf *Pay) PrePayOrder(p *Params) (payOrder PreOrder, err error) {
|
||||
nonceStr := util.RandomStr(32)
|
||||
tradeType := "JSAPI"
|
||||
template := "appid=%s&body=%s&mch_id=%s&nonce_str=%s¬ify_url=%s&openid=%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.OpenID, p.OutTradeNo, p.CreateIP, p.TotalFee, tradeType, pcf.PayKey)
|
||||
str := fmt.Sprintf(template, pcf.AppID, p.Body, pcf.PayMchID, nonceStr, pcf.PayNotifyURL, p.OpenID, p.OutTradeNo, p.CreateIP, p.TotalFee, p.TradeType, pcf.PayKey)
|
||||
sign := util.MD5Sum(str)
|
||||
request := payRequest{
|
||||
AppID: pcf.AppID,
|
||||
@@ -100,7 +100,7 @@ func (pcf *Pay) PrePayOrder(p *Params) (payOrder PreOrder, err error) {
|
||||
TotalFee: p.TotalFee,
|
||||
SpbillCreateIP: p.CreateIP,
|
||||
NotifyURL: pcf.PayNotifyURL,
|
||||
TradeType: tradeType,
|
||||
TradeType: p.TradeType,
|
||||
OpenID: p.OpenID,
|
||||
}
|
||||
rawRet, err := util.PostXML(payGateway, request)
|
||||
|
||||
Reference in New Issue
Block a user