瀏覽代碼

更新

tags/v1.6.1^2
huangjiajun 1 年之前
父節點
當前提交
d047cded6b
共有 2 個文件被更改,包括 37 次插入0 次删除
  1. +32
    -0
      lib/local_wechat/api.go
  2. +5
    -0
      pay/pay_by_own.go

+ 32
- 0
lib/local_wechat/api.go 查看文件

@@ -124,6 +124,38 @@ func TradeH5Pay(client *wechat.Client, subject, orderID, amount, notifyUrl strin
}
return r, nil
}
func TradePcPay(client *wechat.Client, subject, orderID, amount, notifyUrl, productId string) (map[string]string, error) {
// 初始化 BodyMap
bm := make(gopay.BodyMap)
bm.Set("nonce_str", util.GetRandomString(32)).
Set("body", subject).
Set("out_trade_no", orderID).
Set("total_fee", amount).
Set("spbill_create_ip", "121.196.29.49").
Set("notify_url", notifyUrl).
Set("product_id", productId).
Set("trade_type", wechat.TradeType_Native).
Set("sign_type", wechat.SignType_MD5)
// 预下单
wxRsp, err := client.UnifiedOrder(bm)
if err != nil {
_ = zhios_pay_logx.Warn(err)
return nil, err
}
_, err = wechat.VerifySign(client.ApiKey, wechat.SignType_MD5, wxRsp)
if err != nil {
_ = zhios_pay_logx.Warn(err)
return nil, err
}
timeStamp := strconv.FormatInt(time.Now().Unix(), 10)
packages := "prepay_id=" + wxRsp.PrepayId
paySign := wechat.GetH5PaySign(client.AppId, wxRsp.NonceStr, packages, wechat.SignType_MD5, timeStamp, client.ApiKey)
fmt.Println("paySign===", paySign)
r := map[string]string{
"redirect_url": wxRsp.MwebUrl,
}
return r, nil
}

// TradeMiniProgPay is 微信小程序支付 ☑️
func TradeMiniProgPay(client *wechat.Client, subject, orderID, amount, notifyUrl, openid string) (map[string]string, error) {


+ 5
- 0
pay/pay_by_own.go 查看文件

@@ -108,6 +108,11 @@ func WxH5Pay(params map[string]string) (map[string]string, error) {
r, err := local_wxpay.TradeH5Pay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"])
return r, err
}
func WxPcPay(params map[string]string) (map[string]string, error) {
client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true)
r, err := local_wxpay.TradePcPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["product_id"])
return r, err
}

// 微信小程序v2
func WxMiniProgPay(params map[string]string) (map[string]string, error) {


Loading…
取消
儲存