|
@@ -0,0 +1,76 @@
|
|
|
+package cygx
|
|
|
+
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "github.com/wechatpay-apiv3/wechatpay-go/core"
|
|
|
+ "github.com/wechatpay-apiv3/wechatpay-go/core/option"
|
|
|
+ "github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
|
|
|
+ payUtils "github.com/wechatpay-apiv3/wechatpay-go/utils"
|
|
|
+ "log"
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ //MchPKFileName = "./utils/cert/apiclient_key.pem"
|
|
|
+ MchPKFileName = "../cert/cygx/apiclient_key.pem"
|
|
|
+ Mchid = "1624495680"
|
|
|
+ MchCertificateSerialNumber = "5ED2719CFAE5205763034AD80BF4B8A33533C418"
|
|
|
+ MchAPIv3Key = "W1tbnzQrzQ7yRRNuQCIHjis8dgdasKVX"
|
|
|
+)
|
|
|
+
|
|
|
+// 微信商户建立连接
|
|
|
+func getWechatClient() (context.Context, *core.Client, error) {
|
|
|
+ // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
|
|
+ mchPrivateKey, err := payUtils.LoadPrivateKeyWithPath(MchPKFileName)
|
|
|
+ if err != nil {
|
|
|
+ log.Print("load merchant private key error")
|
|
|
+ return nil, nil, err
|
|
|
+ }
|
|
|
+ ctx := context.Background()
|
|
|
+ // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
|
|
|
+ opts := []core.ClientOption{
|
|
|
+ option.WithWechatPayAutoAuthCipher(Mchid, MchCertificateSerialNumber, mchPrivateKey, MchAPIv3Key),
|
|
|
+ }
|
|
|
+ client, err := core.NewClient(ctx, opts...)
|
|
|
+ if err != nil {
|
|
|
+ log.Printf("new wechat pay client err:%s", err)
|
|
|
+ return nil, nil, err
|
|
|
+ }
|
|
|
+ return ctx, client, nil
|
|
|
+}
|
|
|
+
|
|
|
+func init1212() {
|
|
|
+ ctx, client, err := getWechatClient()
|
|
|
+ if err != nil {
|
|
|
+ log.Printf("getWechatClientt err:%s", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ svc := refunddomestic.RefundsApiService{Client: client}
|
|
|
+ resp, result, err := svc.Create(ctx,
|
|
|
+ refunddomestic.CreateRequest{
|
|
|
+ //SubMchid: core.String(Mchid),
|
|
|
+ TransactionId: core.String("4200002189202403252248752161"),
|
|
|
+ OutTradeNo: core.String("OD202403251018320707"),
|
|
|
+ OutRefundNo: core.String("RefundOD202403251018320707"),
|
|
|
+ Reason: core.String("嘿!延边!"),
|
|
|
+ NotifyUrl: core.String("https://testmfyx.hzinsights.com/api/wechat/wxpay/refunds/notify"),
|
|
|
+ FundsAccount: refunddomestic.REQFUNDSACCOUNT_AVAILABLE.Ptr(),
|
|
|
+ Amount: &refunddomestic.AmountReq{
|
|
|
+ Currency: core.String("CNY"),
|
|
|
+ //From: []refunddomestic.FundsFromItem{refunddomestic.FundsFromItem{
|
|
|
+ // Account: refunddomestic.ACCOUNT_AVAILABLE.Ptr(),
|
|
|
+ // Amount: core.Int64(444),
|
|
|
+ //}},
|
|
|
+ Refund: core.Int64(1),
|
|
|
+ Total: core.Int64(1),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ )
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ // 处理错误
|
|
|
+ log.Printf("call Create err:%s", err)
|
|
|
+ } else {
|
|
|
+ // 处理返回结果
|
|
|
+ log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
|
|
|
+ }
|
|
|
+}
|