fix wx payment
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) | ||||
| @@ -84,13 +84,13 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp, | ||||
| 	var createOrderErr error | ||||
| 	if req.PayMethod == "wechatpay" { | ||||
| 		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 +132,11 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp, | ||||
| 		return nil, transErr | ||||
| 	} | ||||
|  | ||||
| 	return &types.PaymentResp{PrepayID: prepayID, OrderID: orderID}, nil | ||||
| 	switch v := prepayData.(type) { | ||||
| 	case string: | ||||
| 		// 如果 prepayData 是字符串类型,直接返回 | ||||
| 		return &types.PaymentResp{PrepayId: v, OrderID: orderID}, nil | ||||
| 	default: | ||||
| 		return &types.PaymentResp{PrepayData: prepayData, OrderID: orderID}, nil | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user