2024-10-02 00:57:17 +08:00
|
|
|
package IVYZ
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-10-02 11:27:51 +08:00
|
|
|
"encoding/hex"
|
|
|
|
"errors"
|
|
|
|
"tianyuan-api/apps/api/internal/validator"
|
|
|
|
"tianyuan-api/pkg/crypto"
|
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 IVYZ5733Logic struct {
|
|
|
|
logx.Logger
|
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIVYZ5733Logic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZ5733Logic {
|
|
|
|
return &IVYZ5733Logic{
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *IVYZ5733Logic) IVYZ5733(req *types.Request) (resp *types.Response, err error) {
|
2024-10-02 11:27:51 +08:00
|
|
|
//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.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
|
|
|
|
}
|
2024-10-02 00:57:17 +08:00
|
|
|
|
2024-10-02 11:27:51 +08:00
|
|
|
// 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
|
2024-10-02 00:57:17 +08:00
|
|
|
}
|