feat(user): 修正加密参数

This commit is contained in:
liangzai 2024-11-23 23:46:20 +08:00
parent 9df11a66a1
commit f80c0812f0

View File

@ -2,6 +2,7 @@ package pay
import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/pkg/errors"
@ -12,6 +13,7 @@ import (
"qnc-server/app/user/model"
"qnc-server/common/ctxdata"
"qnc-server/common/xerr"
"qnc-server/pkg/lzkit/crypto"
)
type PaymentLogic struct {
@ -48,7 +50,15 @@ 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)
}
encryptParams, aesEncryptErr := crypto.AesEncrypt([]byte(cache), key)
if aesEncryptErr != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 加密参数失败: %+v", aesEncryptErr)
}
var prepayID string
var outTradeNo string
@ -87,7 +97,7 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
OrderId: orderID,
UserId: userID,
ProductId: product.Id,
QueryParams: cache,
QueryParams: encryptParams,
QueryState: "pending",
}
_, insertQueryErr := l.svcCtx.QueryModel.Insert(l.ctx, session, &query)