f
This commit is contained in:
65
app/main/api/internal/logic/pay/xpayclienteventlogic.go
Normal file
65
app/main/api/internal/logic/pay/xpayclienteventlogic.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package pay
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"qnc-server/app/main/api/internal/svc"
|
||||
"qnc-server/app/main/api/internal/types"
|
||||
"qnc-server/common/ctxdata"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type XpayClientEventLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewXpayClientEventLogic(ctx context.Context, svcCtx *svc.ServiceContext) *XpayClientEventLogic {
|
||||
return &XpayClientEventLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// XpayClientEvent 记录小程序虚拟支付各步骤及微信/Apple 客户端提示(非 HTTP 异常)
|
||||
func (l *XpayClientEventLogic) XpayClientEvent(req *types.XpayClientEventReq) (*types.XpayClientEventResp, error) {
|
||||
userID, _ := ctxdata.GetUidFromCtx(l.ctx)
|
||||
|
||||
l.Infof("[xpay:client-event] user=%s order_no=%s stage=%s event=%s message=%q err_msg=%q err_code=%d errno=%d sign_data=%s device=%s extra=%s",
|
||||
userID, req.OrderNo, req.Stage, req.EventType, req.Message, req.ErrMsg, req.ErrCode, req.Errno,
|
||||
req.SignData, req.Device, req.Extra)
|
||||
|
||||
resp := &types.XpayClientEventResp{}
|
||||
|
||||
if req.OrderNo == "" || l.svcCtx.XpayService == nil || !l.svcCtx.XpayService.Enabled() {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// 客户端 fail/tip 时主动 query_order,把微信服务端侧状态一并记入日志
|
||||
if req.EventType == "fail" || req.EventType == "tip" {
|
||||
openid, err := l.svcCtx.XpayService.GetWxMiniOpenID(l.ctx, l.svcCtx.UserAuthModel, userID)
|
||||
if err != nil {
|
||||
resp.WxSyncError = "获取 openid 失败: " + err.Error()
|
||||
l.Errorf("[xpay:client-event] query_order skip order_no=%s reason=%v", req.OrderNo, err)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
status, qErr := l.svcCtx.XpayService.QueryOrder(l.ctx, openid, req.OrderNo, "")
|
||||
if qErr != nil {
|
||||
resp.WxSyncError = qErr.Error()
|
||||
l.Errorf("[xpay:client-event] query_order FAIL order_no=%s client_msg=%q wx_err=%v",
|
||||
req.OrderNo, req.Message, qErr)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
resp.WxOrderStatus = status.Status
|
||||
resp.WxOrderDetail = status.RawOrder
|
||||
l.Infof("[xpay:client-event] query_order SNAPSHOT order_no=%s client_msg=%q wx_status=%d wx_order_id=%s paid_fee=%d err_msg=%s raw=%s",
|
||||
req.OrderNo, req.Message, status.Status, status.WxOrderID, status.PaidFee, status.ErrMsg, status.RawOrder)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user