first commit
This commit is contained in:
98
apps/api/internal/logic/FLXG/flxg3d56logic.go
Normal file
98
apps/api/internal/logic/FLXG/flxg3d56logic.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package FLXG
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"tianyuan-api/apps/api/internal/validator"
|
||||
"tianyuan-api/pkg/crypto"
|
||||
|
||||
"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,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *FLXG3D56Logic) FLXG3D56(req *types.Request) (resp *types.Response, err error) {
|
||||
//userId, ok := l.ctx.Value("userId").(int64)
|
||||
//if !ok {
|
||||
// return &types.Response{}, errors.New("系统错误,请联系管理员")
|
||||
//}
|
||||
secretKey, ok := l.ctx.Value("secretKey").(string)
|
||||
if !ok {
|
||||
return &types.Response{}, errors.New("系统错误,请联系管理员")
|
||||
}
|
||||
|
||||
// 1、解密
|
||||
key, err := hex.DecodeString(secretKey)
|
||||
decryptData, err := crypto.AesDecrypt(req.Data, key)
|
||||
if err != nil || len(decryptData) == 0 {
|
||||
return nil, errors.New("参数解密失败")
|
||||
}
|
||||
|
||||
// 2、校验
|
||||
var data validator.FLXG3D56Request
|
||||
|
||||
if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil {
|
||||
return nil, validatorErr
|
||||
}
|
||||
|
||||
// 3、西部加密
|
||||
westConfig := l.svcCtx.Config.WestConfig
|
||||
mobileNo, err := crypto.WestDexEncrypt(data.MobileNo, westConfig.Key)
|
||||
if err != nil {
|
||||
logx.Errorf("西部加密错误:%v", err)
|
||||
return nil, errors.New("业务异常")
|
||||
}
|
||||
name, err := crypto.WestDexEncrypt(data.Name, westConfig.Key)
|
||||
if err != nil {
|
||||
logx.Errorf("西部加密错误:%v", err)
|
||||
return nil, errors.New("业务异常")
|
||||
}
|
||||
idCard, err := crypto.WestDexEncrypt(data.IDCard, westConfig.Key)
|
||||
if err != nil {
|
||||
logx.Errorf("西部加密错误:%v", err)
|
||||
return nil, errors.New("业务异常")
|
||||
}
|
||||
timeRange, err := crypto.WestDexEncrypt(data.TimeRange, westConfig.Key)
|
||||
if err != nil {
|
||||
logx.Errorf("西部加密错误:%v", err)
|
||||
return nil, errors.New("业务异常")
|
||||
}
|
||||
// 4、发送请求到西部
|
||||
westdexRequest := map[string]interface{}{
|
||||
"id": idCard,
|
||||
"cell": mobileNo,
|
||||
"name": name,
|
||||
"time_range": timeRange,
|
||||
}
|
||||
westResp, err := l.svcCtx.WestDexService.CallAPI("G26BJ05", westdexRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 5、响应解析
|
||||
//var respData westmodel.G09GX01Response
|
||||
//unmarshalErr := json.Unmarshal(westResp, &respData)
|
||||
//if unmarshalErr != nil {
|
||||
// return nil, unmarshalErr
|
||||
//}
|
||||
//crypto.AesEncrypt()
|
||||
return &types.Response{
|
||||
Data: string(westResp),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user