feat(main): add mp-weixin
This commit is contained in:
@@ -68,7 +68,7 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
if aesEncryptErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 加密参数失败: %+v", aesEncryptErr)
|
||||
}
|
||||
var prepayID string
|
||||
var prepayData interface{}
|
||||
var outTradeNo string
|
||||
var amount float64
|
||||
user, err := l.svcCtx.UserModel.FindOne(l.ctx, userID)
|
||||
@@ -81,16 +81,17 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
} else {
|
||||
amount = product.SellPrice
|
||||
}
|
||||
|
||||
var createOrderErr error
|
||||
if req.PayMethod == "wechatpay" {
|
||||
if req.PayMethod == "wechat" {
|
||||
outTradeNo = l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
||||
prepayID, createOrderErr = l.svcCtx.WechatPayService.CreateWechatOrder(l.ctx, amount, product.ProductName, outTradeNo)
|
||||
prepayData, createOrderErr = l.svcCtx.WechatPayService.CreateWechatOrder(l.ctx, amount, product.ProductName, outTradeNo)
|
||||
} else if req.PayMethod == "alipay" {
|
||||
outTradeNo = l.svcCtx.AlipayService.GenerateOutTradeNo()
|
||||
prepayID, createOrderErr = l.svcCtx.AlipayService.CreateAlipayOrder(l.ctx, amount, product.ProductName, outTradeNo, brand)
|
||||
prepayData, createOrderErr = l.svcCtx.AlipayService.CreateAlipayOrder(l.ctx, amount, product.ProductName, outTradeNo, brand)
|
||||
} else if req.PayMethod == "appleiap" {
|
||||
outTradeNo = l.svcCtx.ApplePayService.GenerateOutTradeNo()
|
||||
prepayID = l.svcCtx.ApplePayService.GetIappayAppID(product.ProductEn)
|
||||
prepayData = l.svcCtx.ApplePayService.GetIappayAppID(product.ProductEn)
|
||||
}
|
||||
if createOrderErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 创建支付订单失败: %+v", createOrderErr)
|
||||
@@ -132,5 +133,5 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
return nil, transErr
|
||||
}
|
||||
|
||||
return &types.PaymentResp{PrepayID: prepayID, OrderID: orderID}, nil
|
||||
return &types.PaymentResp{PrepayData: prepayData, OrderID: orderID}, nil
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (l *WechatPayCallbackLogic) WechatPayCallback(w http.ResponseWriter, r *htt
|
||||
}
|
||||
|
||||
amount := lzUtils.ToWechatAmount(order.Amount)
|
||||
if &amount != notification.Amount.Total {
|
||||
if amount != *notification.Amount.Total {
|
||||
logx.Errorf("微信支付回调,金额不一致")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user