From d047cded6ba9ba07326929eb3fa5076826d062d1 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Wed, 17 May 2023 15:28:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/local_wechat/api.go | 32 ++++++++++++++++++++++++++++++++ pay/pay_by_own.go | 5 +++++ 2 files changed, 37 insertions(+) diff --git a/lib/local_wechat/api.go b/lib/local_wechat/api.go index b89835a..a37486f 100644 --- a/lib/local_wechat/api.go +++ b/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) { diff --git a/pay/pay_by_own.go b/pay/pay_by_own.go index 7e9af1b..7d7b391 100644 --- a/pay/pay_by_own.go +++ b/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) {