new
This commit is contained in:
@@ -2,14 +2,16 @@ package pay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/smartwalle/alipay/v3"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
"tydata-server/pkg/lzkit/lzUtils"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/smartwalle/alipay/v3"
|
||||
|
||||
"tydata-server/app/user/cmd/api/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AlipayCallbackLogic struct {
|
||||
@@ -72,7 +74,7 @@ func (l *AlipayCallbackLogic) AlipayCallback(w http.ResponseWriter, r *http.Requ
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
order.PlatformOrderId = lzUtils.StringToNullString(notification.OutTradeNo)
|
||||
order.PlatformOrderId = lzUtils.StringToNullString(notification.TradeNo)
|
||||
if updateErr := l.svcCtx.OrderModel.UpdateWithVersion(l.ctx, nil, order); updateErr != nil {
|
||||
logx.Errorf("支付宝支付回调,修改订单信息失败: %+v", updateErr)
|
||||
return nil
|
||||
|
||||
@@ -33,8 +33,6 @@ func NewPaymentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PaymentLo
|
||||
}
|
||||
|
||||
func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp, err error) {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "")
|
||||
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 获取用户信息失败, %+v", getUidErr)
|
||||
@@ -44,7 +42,8 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
if !ok {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 获取平台失败, %+v", getUidErr)
|
||||
}
|
||||
redisKey := fmt.Sprintf("%d:%s", userID, req.Id)
|
||||
outTradeNo := req.Id
|
||||
redisKey := fmt.Sprintf("%d:%s", userID, outTradeNo)
|
||||
cache, cacheErr := l.svcCtx.Redis.GetCtx(l.ctx, redisKey)
|
||||
if cacheErr != nil {
|
||||
return nil, cacheErr
|
||||
@@ -59,21 +58,8 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 查找产品错误: %v", err)
|
||||
}
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
if decodeErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 获取AES密钥失败: %+v", decodeErr)
|
||||
}
|
||||
params, marshalErr := json.Marshal(data.Params)
|
||||
if marshalErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 序列化参数失败: %+v", marshalErr)
|
||||
}
|
||||
encryptParams, aesEncryptErr := crypto.AesEncrypt(params, key)
|
||||
if aesEncryptErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 加密参数失败: %+v", aesEncryptErr)
|
||||
}
|
||||
|
||||
var prepayData interface{}
|
||||
var outTradeNo string
|
||||
var amount float64
|
||||
var orderAmount float64
|
||||
user, err := l.svcCtx.UserModel.FindOne(l.ctx, userID)
|
||||
@@ -99,13 +85,10 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
|
||||
var createOrderErr error
|
||||
if req.PayMethod == "wechat" {
|
||||
outTradeNo = l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
||||
prepayData, createOrderErr = l.svcCtx.WechatPayService.CreateWechatOrder(l.ctx, amount, product.ProductName, outTradeNo)
|
||||
} else if req.PayMethod == "alipay" {
|
||||
outTradeNo = l.svcCtx.AlipayService.GenerateOutTradeNo()
|
||||
prepayData, createOrderErr = l.svcCtx.AlipayService.CreateAlipayOrder(l.ctx, amount, product.ProductName, outTradeNo, brand)
|
||||
} else if req.PayMethod == "appleiap" {
|
||||
outTradeNo = l.svcCtx.ApplePayService.GenerateOutTradeNo()
|
||||
prepayData = l.svcCtx.ApplePayService.GetIappayAppID(product.ProductEn)
|
||||
}
|
||||
if createOrderErr != nil {
|
||||
@@ -131,17 +114,7 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "生成订单, 获取保存订单ID失败: %+v", lastInsertIdErr)
|
||||
}
|
||||
orderID = insertedOrderID
|
||||
query := model.Query{
|
||||
OrderId: orderID,
|
||||
UserId: userID,
|
||||
ProductId: product.Id,
|
||||
QueryParams: encryptParams,
|
||||
QueryState: "pending",
|
||||
}
|
||||
_, insertQueryErr := l.svcCtx.QueryModel.Insert(l.ctx, session, &query)
|
||||
if insertQueryErr != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "生成订单, 保存查询失败: %+v", lastInsertIdErr)
|
||||
}
|
||||
|
||||
if data.AgentIdentifier != "" {
|
||||
agent, parsingErr := l.agentParsing(data.AgentIdentifier)
|
||||
if parsingErr != nil {
|
||||
|
||||
Reference in New Issue
Block a user