From 4842aa47a31a46e45695e479dd1eb143900f1d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BF=8A=E5=AE=8F?= <389838709@qq.com> Date: Fri, 2 Aug 2024 16:53:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=85=E8=A6=81=E4=BD=8D=E7=BD=AE=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/third/paymentService/ali_service.go | 6 +++++- app/third/paymentService/payment_service.go | 4 ++++ app/third/paymentService/wechat_service.go | 8 ++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/third/paymentService/ali_service.go b/app/third/paymentService/ali_service.go index 0e85140..8fdf7f8 100644 --- a/app/third/paymentService/ali_service.go +++ b/app/third/paymentService/ali_service.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/go-pay/gopay" "github.com/go-pay/gopay/alipay" + "github.com/qit-team/snow-core/log/logger" "strconv" "sync" ) @@ -80,6 +81,7 @@ func ALiH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, e aliRsp, err := aliClient.TradeWapPay(c, bm) if err != nil { + logger.Error(c, "ALiH5PayInfo 发生错误", fmt.Sprintf("错误信息:%s", err.Error())) if bizErr, ok := alipay.IsBizError(err); ok { return "", bizErr } @@ -182,6 +184,7 @@ func AliRefundOrder(ctx context.Context, orderRefundRequest OrderRefundRequest) // 发起退款请求 aliRsp, err := aliClient.TradeRefund(ctx, bm) if err != nil { + logger.Error(ctx, "AliRefundOrder 发生错误", fmt.Sprintf("申请退款接口失败,错误信息:%s", err.Error())) if bizErr, ok := alipay.IsBizError(err); ok { return OrderRefundInfo{}, bizErr } @@ -253,9 +256,10 @@ func AliCloseOrder(ctx context.Context, orderCloseRequest OrderCloseRequest) (Or bm := make(gopay.BodyMap) bm.Set("out_trade_no", orderCloseRequest.OrderId) - // 条码支付 + // 关闭订单 aliRsp, err := aliClient.TradeClose(ctx, bm) if err != nil { + logger.Error(ctx, "AliCloseOrder 发生错误", fmt.Sprintf("申请退款接口失败,错误信息:%s", err.Error())) if bizErr, ok := alipay.IsBizError(err); ok { return OrderCloseInfo{}, bizErr } diff --git a/app/third/paymentService/payment_service.go b/app/third/paymentService/payment_service.go index 1c06d7a..cf9a369 100644 --- a/app/third/paymentService/payment_service.go +++ b/app/third/paymentService/payment_service.go @@ -3,6 +3,7 @@ package paymentService import ( "PaymentCenter/app/third/paymentService/payCommon" "context" + "github.com/qit-team/snow-core/log/logger" "strconv" ) @@ -40,6 +41,7 @@ type PayOrderResponse struct { // PaymentService 统一发起支付 func PaymentService(c context.Context, payOrderRequest PayOrderRequest) (payOrderResponse PayOrderResponse) { + logger.Info(c, "PaymentService 收到支付请求", payOrderRequest) var err error var info string switch payOrderRequest.ChannelType { @@ -147,6 +149,7 @@ type OrderRefundInfo struct { // OrderRefund 订单退款 func OrderRefund(c context.Context, orderRefundRequest OrderRefundRequest) OrderRefundResponse { + logger.Info(c, "PaymentService 收到退款请求", orderRefundRequest) var err error var info OrderRefundInfo switch orderRefundRequest.PayChannel { @@ -233,6 +236,7 @@ type OrderCloseInfo struct { // OrderClose 关闭订单 func OrderClose(c context.Context, orderCloseRequest OrderCloseRequest) OrderCloseResponse { + logger.Info(c, "PaymentService 收到关闭订单请求", orderCloseRequest) var err error var info OrderCloseInfo switch orderCloseRequest.PayChannel { diff --git a/app/third/paymentService/wechat_service.go b/app/third/paymentService/wechat_service.go index e439381..24c629b 100644 --- a/app/third/paymentService/wechat_service.go +++ b/app/third/paymentService/wechat_service.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/go-pay/gopay" "github.com/go-pay/gopay/wechat/v3" + "github.com/qit-team/snow-core/log/logger" "strconv" "sync" "time" @@ -62,7 +63,6 @@ func WxH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, er // 获取微信客户端 wxClient, err := GetClient() if err != nil { - fmt.Println("Failed to get client:", err) return "", err } expire := time.Now().Add(10 * time.Minute).Format(time.RFC3339) @@ -91,6 +91,7 @@ func WxH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, er return "", err } if wxRsp.Code != wechat.Success || wxRsp.Response.H5Url == "" { + logger.Error(c, "WxH5PayInfo 发生错误", fmt.Sprintf("错误状态码:%d, 错误信息:%s", wxRsp.Code, wxRsp.Error)) return "", errors.New(fmt.Sprintf("发起支付失败,失败状态码:%d, 失败原因:%s", wxRsp.Code, wxRsp.Error)) } return wxRsp.Response.H5Url, nil @@ -104,7 +105,6 @@ func WxPayCallBack(notifyReq *wechat.V3NotifyReq, wxConfig WxPay) error { // 获取微信客户端 wxClient, err := GetClient() if err != nil { - fmt.Println("Failed to get client:", err) return err } @@ -147,7 +147,6 @@ func WxOrderQuery(ctx context.Context, wxConfig WxPay, orderNo string) (PayOrder // 获取微信客户端 wxClient, err := GetClient() if err != nil { - fmt.Println("Failed to get client:", err) return PayOrderQueryInfo{}, err } @@ -219,6 +218,7 @@ func WxOrderRefund(ctx context.Context, orderRefundRequest OrderRefundRequest) ( // 将非正常退款异常记录 if refund.Code != wechat.Success { + logger.Error(ctx, "WxOrderRefund 发生错误", fmt.Sprintf("申请退款接口失败,错误状态码:%d, 错误信息:%s", refund.Code, refund.Error)) // 这里时对非正常退款的一些处理message,我们将code统一使用自定义的,然后把message抛出去 return OrderRefundInfo{}, errors.New(fmt.Sprintf("申请退款接口失败,错误状态码:%d, 错误信息:%s", refund.Code, refund.Error)) } @@ -254,7 +254,6 @@ func WxOrderRefundQuery(ctx context.Context, orderRefundQueryRequest OrderRefund // 获取微信客户端 wxClient, err := GetClient() if err != nil { - fmt.Println("Failed to get client:", err) return OrderRefundInfo{}, err } @@ -303,6 +302,7 @@ func WxCloseOrder(ctx context.Context, orderCloseRequest OrderCloseRequest) (Ord return OrderCloseInfo{}, err } if wxRsp.Code != wechat.Success { + logger.Error(ctx, "WxCloseOrder 发生错误", fmt.Sprintf("查询订单接口错误,错误状态码:%d, 错误信息:%s", wxRsp.Code, wxRsp.Error)) return OrderCloseInfo{}, errors.New(fmt.Sprintf("查询订单接口错误,错误状态码:%d, 错误信息:%s", wxRsp.Code, wxRsp.Error)) } return OrderCloseInfo{