94 lines
2.4 KiB
Go
94 lines
2.4 KiB
Go
package FLXG
|
|
|
|
import (
|
|
"context"
|
|
"encoding/hex"
|
|
"tianyuan-api/apps/api/internal/common"
|
|
"tianyuan-api/apps/api/internal/validator"
|
|
"tianyuan-api/apps/api/internal/westmodel"
|
|
"tianyuan-api/pkg/crypto"
|
|
"tianyuan-api/pkg/errs"
|
|
|
|
"tianyuan-api/apps/api/internal/svc"
|
|
"tianyuan-api/apps/api/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type FLXG970FLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewFLXG970FLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FLXG970FLogic {
|
|
return &FLXG970FLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *FLXG970FLogic) FLXG970F(req *types.Request) (resp *types.Response, err error) {
|
|
secretKey, ok := l.ctx.Value("secretKey").(string)
|
|
if !ok {
|
|
return &types.Response{}, errs.ErrSystem
|
|
}
|
|
transactionID, ok := l.ctx.Value("transactionID").(string)
|
|
if !ok {
|
|
return &types.Response{}, errs.ErrSystem
|
|
}
|
|
// 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.FLXG970FRequest
|
|
if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil {
|
|
return nil, errs.ErrParamValidation
|
|
}
|
|
|
|
// 3、西部加密
|
|
westConfig := l.svcCtx.Config.WestConfig
|
|
encryptedFields, err := common.EncryptStructFields(data, westConfig.Key)
|
|
if err != nil {
|
|
logx.Errorf("西部加密错误:%v", err)
|
|
return nil, errs.ErrSystem
|
|
}
|
|
|
|
// 4、发送请求到西部
|
|
logx.Infof("交易号:%s", transactionID)
|
|
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.FLXG970FFieldMapping, "")
|
|
|
|
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("WEST00028", apiRequest)
|
|
if callAPIErr != nil {
|
|
return nil, errs.ErrSystem
|
|
}
|
|
|
|
// 5、响应解析
|
|
//var respData westmodel.G32BJ05Response
|
|
//unmarshalErr := json.Unmarshal(westResp, &respData)
|
|
//if unmarshalErr != nil {
|
|
// return nil, errs.ErrSystem
|
|
//}
|
|
//
|
|
//if respData.Data.Code == "00" || respData.Data.Code == "100002" {
|
|
// l.ctx = context.WithValue(l.ctx, "Charges", true)
|
|
//} else {
|
|
// return nil, errs.ErrSystem
|
|
//}
|
|
//encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key)
|
|
//if aesEncrypt != nil {
|
|
// return nil, errs.ErrSystem
|
|
//}
|
|
return &types.Response{
|
|
Data: string(westResp),
|
|
}, nil
|
|
}
|