必要位置添加日志

This commit is contained in:
陈俊宏 2024-08-02 16:53:48 +08:00
parent a79b18d279
commit 4842aa47a3
3 changed files with 13 additions and 5 deletions

View File

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

View File

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

View File

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