temp
This commit is contained in:
parent
18e4a8080d
commit
534500eb32
@ -22,13 +22,10 @@ func FLXG3D56Handler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
||||
l := FLXG.NewFLXG3D56Logic(r.Context(), svcCtx)
|
||||
resp, err := l.FLXG3D56(&req)
|
||||
ctx := r.Context()
|
||||
if err != nil {
|
||||
r = r.WithContext(ctx)
|
||||
response.Fail(ctx, w, err)
|
||||
response.Fail(r.Context(), w, err)
|
||||
} else {
|
||||
r = r.WithContext(ctx)
|
||||
response.Success(ctx, w, resp)
|
||||
response.Success(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,7 @@ package FLXG
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"tianyuan-api/apps/api/internal/common"
|
||||
"tianyuan-api/apps/api/internal/validator"
|
||||
"tianyuan-api/apps/api/internal/westmodel"
|
||||
"tianyuan-api/pkg/crypto"
|
||||
"fmt"
|
||||
"tianyuan-api/pkg/errs"
|
||||
|
||||
"tianyuan-api/apps/api/internal/svc"
|
||||
@ -53,6 +48,7 @@ func (l *FLXG3D56Logic) FLXG3D56(req *types.Request) (resp *types.Response, err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
fmt.Println(secretKey)
|
||||
if err != nil {
|
||||
status = "failed"
|
||||
charges = false
|
||||
@ -65,56 +61,58 @@ func (l *FLXG3D56Logic) FLXG3D56(req *types.Request) (resp *types.Response, err
|
||||
logx.Errorf("发送 API 请求消息失败: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// 1、解密
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
if decodeErr != nil {
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key)
|
||||
if aesDecryptErr != nil || len(decryptData) == 0 {
|
||||
return nil, errs.ErrParamDecryption
|
||||
}
|
||||
|
||||
// 2、校验
|
||||
var data validator.FLXG3D56Request
|
||||
if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil {
|
||||
return nil, errs.ErrParamValidation
|
||||
}
|
||||
|
||||
// 3、西部加密
|
||||
westConfig := l.svcCtx.Config.WestConfig
|
||||
encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key)
|
||||
if encryptStructFieldsErr != nil {
|
||||
logx.Errorf("西部加密错误:%v", encryptStructFieldsErr)
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
|
||||
// 4、发送请求到西部
|
||||
logx.Infof("交易号:%s", transactionID)
|
||||
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.FLXG3D56FieldMapping, "data")
|
||||
|
||||
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G26BJ05", apiRequest)
|
||||
if callAPIErr != nil {
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
|
||||
// 5、响应解析
|
||||
var respData westmodel.G26BJ05Response
|
||||
unmarshalErr := json.Unmarshal(westResp, &respData)
|
||||
if unmarshalErr != nil {
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
|
||||
if respData.Data.Code != "00" && respData.Data.Code != "100002" {
|
||||
return nil, errs.ErrDataSource
|
||||
}
|
||||
encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key)
|
||||
if aesEncrypt != nil {
|
||||
return nil, errs.ErrSystem
|
||||
}
|
||||
|
||||
return &types.Response{
|
||||
Data: encryptData,
|
||||
Data: "asdasdasdasd",
|
||||
}, nil
|
||||
//// 1、解密
|
||||
//key, decodeErr := hex.DecodeString(secretKey)
|
||||
//if decodeErr != nil {
|
||||
// return nil, errs.ErrSystem
|
||||
//}
|
||||
//decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key)
|
||||
//if aesDecryptErr != nil || len(decryptData) == 0 {
|
||||
// return nil, errs.ErrParamDecryption
|
||||
//}
|
||||
//
|
||||
//// 2、校验
|
||||
//var data validator.FLXG3D56Request
|
||||
//if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil {
|
||||
// return nil, errs.ErrParamValidation
|
||||
//}
|
||||
//
|
||||
//// 3、西部加密
|
||||
//westConfig := l.svcCtx.Config.WestConfig
|
||||
//encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key)
|
||||
//if encryptStructFieldsErr != nil {
|
||||
// logx.Errorf("西部加密错误:%v", encryptStructFieldsErr)
|
||||
// return nil, errs.ErrSystem
|
||||
//}
|
||||
//
|
||||
//// 4、发送请求到西部
|
||||
//logx.Infof("交易号:%s", transactionID)
|
||||
//apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.FLXG3D56FieldMapping, "data")
|
||||
//
|
||||
//westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G26BJ05", apiRequest)
|
||||
//if callAPIErr != nil {
|
||||
// return nil, errs.ErrSystem
|
||||
//}
|
||||
//
|
||||
//// 5、响应解析
|
||||
//var respData westmodel.G26BJ05Response
|
||||
//unmarshalErr := json.Unmarshal(westResp, &respData)
|
||||
//if unmarshalErr != nil {
|
||||
// return nil, errs.ErrSystem
|
||||
//}
|
||||
//
|
||||
//if respData.Data.Code != "00" && respData.Data.Code != "100002" {
|
||||
// return nil, errs.ErrDataSource
|
||||
//}
|
||||
//encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key)
|
||||
//if aesEncrypt != nil {
|
||||
// return nil, errs.ErrSystem
|
||||
//}
|
||||
//
|
||||
//return &types.Response{
|
||||
// Data: encryptData,
|
||||
//}, nil
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ func (l *Charge) Consume(ctx context.Context, key, val string) error {
|
||||
if !apiRequestMessage.Charges {
|
||||
return nil
|
||||
}
|
||||
_, updateWalletErr := l.svcCtx.WalletRpc.UpdateWallet(ctx, &user.UpdateWalletRequest{UserId: apiRequestMessage.UserId, TransactionId: apiRequestMessage.TransactionID, ProductCode: apiRequestMessage.ProductCode, Remark: apiRequestMessage.Remark})
|
||||
_, updateWalletErr := l.svcCtx.WalletRpc.UpdateWallet(ctx, &user.UpdateWalletRequest{UserId: apiRequestMessage.UserId, TransactionId: apiRequestMessage.TransactionID, ProductCode: apiRequestMessage.ProductCode, Charge: apiRequestMessage.Charges, Remark: apiRequestMessage.Remark})
|
||||
if updateWalletErr != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package apirequestservicelogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"tianyuan-api/apps/user/internal/model"
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
@ -36,6 +38,16 @@ func (l *AddApiRequestLogic) AddApiRequest(in *user.AddApiRequestRequest) (*user
|
||||
// 错误处理,比如日志输出或返回错误
|
||||
parsedTime = time.Now()
|
||||
}
|
||||
apiRequests, findOneByTransactionIdErr := l.svcCtx.ApiRequestsModel.FindOneByTransactionId(l.ctx, in.TransactionId)
|
||||
if findOneByTransactionIdErr != nil {
|
||||
if errors.Is(findOneByTransactionIdErr, sql.ErrNoRows) {
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if apiRequests != nil {
|
||||
return nil, errors.New("该请求已经记录")
|
||||
}
|
||||
_, err = l.svcCtx.ApiRequestsModel.Insert(l.ctx, &model.ApiRequests{
|
||||
TransactionId: in.TransactionId,
|
||||
UserId: in.UserId,
|
||||
|
Loading…
Reference in New Issue
Block a user