2024-10-02 00:57:17 +08:00
|
|
|
package FLXG
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-10-13 01:37:10 +08:00
|
|
|
"fmt"
|
2024-10-12 20:41:55 +08:00
|
|
|
"tianyuan-api/pkg/errs"
|
2024-10-02 00:57:17 +08:00
|
|
|
|
|
|
|
"tianyuan-api/apps/api/internal/svc"
|
|
|
|
"tianyuan-api/apps/api/internal/types"
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FLXG3D56Logic struct {
|
|
|
|
logx.Logger
|
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFLXG3D56Logic(ctx context.Context, svcCtx *svc.ServiceContext) *FLXG3D56Logic {
|
|
|
|
return &FLXG3D56Logic{
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-12 20:41:55 +08:00
|
|
|
// FLXG3D56 特殊名单
|
2024-10-12 21:35:35 +08:00
|
|
|
func (l *FLXG3D56Logic) FLXG3D56(req *types.Request) (resp *types.Response, err *errs.AppError) {
|
2024-10-13 01:21:13 +08:00
|
|
|
var status string
|
|
|
|
var charges bool
|
|
|
|
var remark = ""
|
2024-10-02 00:57:17 +08:00
|
|
|
secretKey, ok := l.ctx.Value("secretKey").(string)
|
|
|
|
if !ok {
|
2024-10-12 20:41:55 +08:00
|
|
|
return &types.Response{}, errs.ErrSystem
|
|
|
|
}
|
|
|
|
transactionID, ok := l.ctx.Value("transactionID").(string)
|
|
|
|
if !ok {
|
|
|
|
return &types.Response{}, errs.ErrSystem
|
2024-10-02 00:57:17 +08:00
|
|
|
}
|
2024-10-13 01:21:13 +08:00
|
|
|
userId, userIdOk := l.ctx.Value("userId").(int64)
|
|
|
|
if !userIdOk {
|
|
|
|
return &types.Response{}, errs.ErrSystem
|
|
|
|
}
|
|
|
|
productCode, productCodeOk := l.ctx.Value("productCode").(string)
|
|
|
|
if !productCodeOk || productCode == "" {
|
|
|
|
return &types.Response{}, errs.ErrSystem
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
2024-10-13 01:37:10 +08:00
|
|
|
fmt.Println(secretKey)
|
2024-10-13 01:21:13 +08:00
|
|
|
if err != nil {
|
|
|
|
status = "failed"
|
|
|
|
charges = false
|
|
|
|
} else {
|
|
|
|
status = "success"
|
|
|
|
charges = true
|
|
|
|
}
|
|
|
|
sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark)
|
|
|
|
if sendApiRequestMessageErr != nil {
|
|
|
|
logx.Errorf("发送 API 请求消息失败: %v", err)
|
|
|
|
}
|
|
|
|
}()
|
2024-10-02 00:57:17 +08:00
|
|
|
return &types.Response{
|
2024-10-13 01:37:10 +08:00
|
|
|
Data: "asdasdasdasd",
|
2024-10-02 00:57:17 +08:00
|
|
|
}, nil
|
2024-10-13 01:37:10 +08:00
|
|
|
//// 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
|
2024-10-02 00:57:17 +08:00
|
|
|
}
|