From e88d5b6c2cb37d97a6a4fe705e07900f9c3d9de1 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Fri, 25 Aug 2023 16:33:04 +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 | 22 ++++++++++++++++++++++ pay/pay_by_own.go | 8 ++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/local_wechat/api.go b/lib/local_wechat/api.go index 54a95f1..3d34067 100644 --- a/lib/local_wechat/api.go +++ b/lib/local_wechat/api.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/iGoogle-ink/gopay" "github.com/iGoogle-ink/gopay/pkg/util" + "github.com/iGoogle-ink/gopay/pkg/xlog" "github.com/iGoogle-ink/gopay/wechat" v3 "github.com/iGoogle-ink/gopay/wechat/v3" "strconv" @@ -44,6 +45,27 @@ func NewClient(appId, mchId, apiKey string, isProd bool) *wechat.Client { //client.AddCertFileContent() return client } +func TradeAppRefund(client *wechat.Client, subject, transactionId, outRefundNo, totalFee, amount, p12Path, notifyUrl string) (*wechat.RefundResponse, gopay.BodyMap, error) { + // 初始化 BodyMap + bm := make(gopay.BodyMap) + bm.Set("transaction_id", transactionId). + Set("nonce_str", util.GetRandomString(32)). + Set("sign_type", wechat.SignType_MD5). + Set("out_refund_no", outRefundNo). + Set("total_fee", int(zhios_pay_utils.StrToFloat64(totalFee)*100)). + Set("refund_fee", int(zhios_pay_utils.StrToFloat64(amount)*100)). + Set("refund_desc", subject). + Set("notify_url", notifyUrl) + wxRsp, resBm, err := client.Refund(bm, nil, nil, p12Path) + fmt.Println(wxRsp) + fmt.Println(resBm) + if err != nil { + xlog.Error(err) + fmt.Println(err) + return wxRsp, resBm, err + } + return wxRsp, resBm, nil +} // TradeAppPay is 微信APP支付 func TradeAppPay(client *wechat.Client, subject, orderID, amount, notifyUrl string) (map[string]string, error) { diff --git a/pay/pay_by_own.go b/pay/pay_by_own.go index 7d7b391..4c871bb 100644 --- a/pay/pay_by_own.go +++ b/pay/pay_by_own.go @@ -6,6 +6,8 @@ import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/md" zhios_pay_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/utils" "fmt" + "github.com/iGoogle-ink/gopay" + "github.com/iGoogle-ink/gopay/wechat" "github.com/pkg/errors" ) @@ -133,3 +135,9 @@ func WxAppJSAPIPay(params map[string]string) (map[string]string, error) { r, err := local_wxpay.TradeJSAPIPay(client, params["subject"], params["ord_id"], params["amount"], params["notify_url"], params["third_party_wechat_openid"]) return r, err } + +func WxAppRefund(params map[string]string) (*wechat.RefundResponse, gopay.BodyMap, error) { + client := local_wxpay.NewClient(params["pay_wx_appid"], params["pay_wx_mch_id"], params["pay_wx_api_key"], true) + r, r1, err := local_wxpay.TradeAppRefund(client, params["subject"], params["transaction_id"], params["out_refund_no"], params["total_fee"], params["amount"], params["p12_str"], params["notify_url"]) + return r, r1, err +}