huangjiajun 1 anno fa
parent
commit
e88d5b6c2c
2 ha cambiato i file con 30 aggiunte e 0 eliminazioni
  1. +22
    -0
      lib/local_wechat/api.go
  2. +8
    -0
      pay/pay_by_own.go

+ 22
- 0
lib/local_wechat/api.go Vedi File

@@ -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) {


+ 8
- 0
pay/pay_by_own.go Vedi File

@@ -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
}

Caricamento…
Annulla
Salva