|
@@ -2,16 +2,20 @@ package cygx
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "fmt"
|
|
|
"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"
|
|
|
+ "hongze/hz_crm_api/models/cygx"
|
|
|
+ "hongze/hz_crm_api/services/alarm_msg"
|
|
|
"log"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
//MchPKFileName = "./utils/cert/apiclient_key.pem"
|
|
|
- MchPKFileName = "../cert/cygx/apiclient_key.pem"
|
|
|
+ //MchPKFileName = "../cert/cygx/apiclient_key.pem"
|
|
|
+ MchPKFileName = "../hongze_mfyx/utils/cert/apiclient_key.pem"
|
|
|
Mchid = "1624495680"
|
|
|
MchCertificateSerialNumber = "5ED2719CFAE5205763034AD80BF4B8A33533C418"
|
|
|
MchAPIv3Key = "W1tbnzQrzQ7yRRNuQCIHjis8dgdasKVX"
|
|
@@ -19,6 +23,13 @@ const (
|
|
|
|
|
|
// 微信商户建立连接
|
|
|
func getWechatClient() (context.Context, *core.Client, error) {
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go alarm_msg.SendAlarmMsg(fmt.Sprint("微信商户建立连接失败 getWechatClient, err:", err.Error()), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
|
|
mchPrivateKey, err := payUtils.LoadPrivateKeyWithPath(MchPKFileName)
|
|
|
if err != nil {
|
|
@@ -38,20 +49,28 @@ func getWechatClient() (context.Context, *core.Client, error) {
|
|
|
return ctx, client, nil
|
|
|
}
|
|
|
|
|
|
-func init1212() {
|
|
|
+// 微信商户退款
|
|
|
+func RefundsApiService(orderDetail *cygx.CygxOrderResp) (statusCode int, err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go alarm_msg.SendAlarmMsg(fmt.Sprint("生成预支付交易单失败 ExampleJsapiApiServicePrepay, err:", err.Error()), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
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("嘿!延边!"),
|
|
|
+ TransactionId: core.String(orderDetail.OutTradeCode),
|
|
|
+ OutTradeNo: core.String(orderDetail.OrderCode),
|
|
|
+ OutRefundNo: core.String("RE" + orderDetail.OrderCode),
|
|
|
+ Reason: core.String("退款"),
|
|
|
NotifyUrl: core.String("https://testmfyx.hzinsights.com/api/wechat/wxpay/refunds/notify"),
|
|
|
FundsAccount: refunddomestic.REQFUNDSACCOUNT_AVAILABLE.Ptr(),
|
|
|
Amount: &refunddomestic.AmountReq{
|
|
@@ -60,12 +79,12 @@ func init1212() {
|
|
|
// Account: refunddomestic.ACCOUNT_AVAILABLE.Ptr(),
|
|
|
// Amount: core.Int64(444),
|
|
|
//}},
|
|
|
- Refund: core.Int64(1),
|
|
|
- Total: core.Int64(1),
|
|
|
+ Refund: core.Int64(int64(orderDetail.PayMoney * 100)),
|
|
|
+ Total: core.Int64(int64(orderDetail.PayMoney * 100)),
|
|
|
},
|
|
|
},
|
|
|
)
|
|
|
-
|
|
|
+ statusCode = result.Response.StatusCode
|
|
|
if err != nil {
|
|
|
// 处理错误
|
|
|
log.Printf("call Create err:%s", err)
|
|
@@ -73,4 +92,5 @@ func init1212() {
|
|
|
// 处理返回结果
|
|
|
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
|
|
|
}
|
|
|
+ return
|
|
|
}
|