区分环境

This commit is contained in:
2024-10-02 11:27:51 +08:00
parent ab842d8694
commit b8d9a72dac
30 changed files with 626 additions and 181 deletions

View File

@@ -2,6 +2,10 @@ package IVYZ
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"
@@ -24,7 +28,59 @@ func NewIVYZ5733Logic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZ5733
}
func (l *IVYZ5733Logic) IVYZ5733(req *types.Request) (resp *types.Response, err error) {
// todo: add your logic here and delete this line
//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("系统错误,请联系管理员")
}
return
// 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.IVYZ5733Request
if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil {
return nil, validatorErr
}
// 3、西部加密
westConfig := l.svcCtx.Config.WestConfig
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("业务异常")
}
// 4、发送请求到西部
westdexRequest := map[string]interface{}{
"id": idCard,
"name": name,
}
westResp, err := l.svcCtx.WestDexService.CallAPI("G09GX01", 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
}