This commit is contained in:
2025-07-13 20:37:12 +08:00
parent 418b89c1ae
commit c81208e3c8
17 changed files with 6603 additions and 93 deletions

View File

@@ -2,10 +2,15 @@ package IVYZ
import (
"context"
"encoding/hex"
"tianyuan-api/pkg/crypto"
"tianyuan-api/pkg/errs"
"tianyuan-api/apps/api/internal/common"
"tianyuan-api/apps/api/internal/svc"
"tianyuan-api/apps/api/internal/types"
"tianyuan-api/apps/api/internal/validator"
"tianyuan-api/apps/api/internal/westmodel"
"github.com/zeromicro/go-zero/core/logx"
)
@@ -25,89 +30,81 @@ func NewIVYZ0B03Logic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZ0B03
}
func (l *IVYZ0B03Logic) IVYZ0B03(req *types.Request) (resp string, err *errs.AppError) {
return
//var status string
//var charges bool
//var remark = ""
//secretKey, ok := l.ctx.Value("secretKey").(string)
//if !ok {
// return "", errs.ErrSystem
//}
//transactionID, ok := l.ctx.Value("transactionID").(string)
//if !ok {
// return "", errs.ErrSystem
//}
//userId, userIdOk := l.ctx.Value("userId").(int64)
//if !userIdOk {
// return "", errs.ErrSystem
//}
//productCode, productCodeOk := l.ctx.Value("productCode").(string)
//if !productCodeOk || productCode == "" {
// return "", errs.ErrSystem
//}
//defer func() {
// 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)
// }
//}()
//// 1、解密
//key, decodeErr := hex.DecodeString(secretKey)
//if decodeErr != nil {
// return "", errs.ErrSystem
//}
//decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key)
//if aesDecryptErr != nil || len(decryptData) == 0 {
// return "", errs.ErrParamDecryption
//}
//
//// 2、校验
//var data validator.FLXGDEC7Request
//if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil {
// return "", errs.ErrParamValidation
//}
//
//// 3、西部加密
//westConfig := l.svcCtx.Config.WestConfig
//encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key)
//if encryptStructFieldsErr != nil {
// logx.Errorf("西部加密错误:%v", encryptStructFieldsErr)
// return "", errs.ErrSystem
//}
//
//// 4、发送请求到西部
//logx.Infof("交易号:%s", transactionID)
//apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.FLXGDEC7FieldMapping, "data")
//
//westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G23BJ03", apiRequest, l.svcCtx.Config.WestConfig.SecretId)
//if callAPIErr != nil {
// return "", errs.ErrSystem
//}
//
//// 5、响应解析
////var respData westmodel.G32BJ05Response
////unmarshalErr := json.Unmarshal(westResp, &respData)
////if unmarshalErr != nil {
//// return "", errs.ErrSystem
////}
////
////if respData.Data.Code == "00" || respData.Data.Code == "100002" {
//// l.ctx = context.WithValue(l.ctx, "Charges", true)
////} else {
//// return "", errs.ErrSystem
////}
////encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key)
////if aesEncrypt != nil {
//// return "", errs.ErrSystem
////}
//return &types.Response{
// Data: string(westResp),
//}, nil
}
var status string
var charges bool
var remark = ""
secretKey, ok := l.ctx.Value("secretKey").(string)
if !ok {
return "", errs.ErrSystem
}
transactionID, ok := l.ctx.Value("transactionID").(string)
if !ok {
return "", errs.ErrSystem
}
userId, userIdOk := l.ctx.Value("userId").(int64)
if !userIdOk {
return "", errs.ErrSystem
}
productCode, productCodeOk := l.ctx.Value("productCode").(string)
if !productCodeOk || productCode == "" {
return "", errs.ErrSystem
}
defer func() {
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)
}
}()
// 1、解密
key, decodeErr := hex.DecodeString(secretKey)
if decodeErr != nil {
return "", errs.ErrSystem
}
decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key)
if aesDecryptErr != nil || len(decryptData) == 0 {
return "", errs.ErrParamDecryption
}
// 2、校验
var data validator.IVYZ0b03Request
if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil {
return "", errs.ErrParamValidation
}
// 3、西部加密
westConfig := l.svcCtx.Config.WestConfig
encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key)
if encryptStructFieldsErr != nil {
logx.Errorf("西部加密错误:%v", encryptStructFieldsErr)
return "", errs.ErrSystem
}
// 4、发送请求到西部
logx.Infof("交易号:%s", transactionID)
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.IVYZ0b03FieldMapping, "data")
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G17BJ02", apiRequest, l.svcCtx.Config.WestConfig.SecretId)
if callAPIErr != nil {
if callAPIErr.Code == errs.ErrDataSource.Code {
encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key)
if aesEncrypt != nil {
return "", errs.ErrSystem
}
return encryptData, callAPIErr
}
return "", callAPIErr
}
encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key)
if aesEncrypt != nil {
return "", errs.ErrSystem
}
return encryptData, nil
}

View File

@@ -3,11 +3,13 @@ package YYSY
import (
"context"
"encoding/hex"
"fmt"
"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"
"time"
"tianyuan-api/apps/api/internal/svc"
"tianyuan-api/apps/api/internal/types"
@@ -88,9 +90,10 @@ func (l *YYSYBE08Logic) YYSYBE08(req *types.Request) (resp string, err *errs.App
// 4、发送请求到西部
logx.Infof("交易号:%s", transactionID)
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.YYSYBE08FieldMapping, "data")
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G17BJ02", apiRequest, l.svcCtx.Config.WestConfig.SecretId)
apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.YYSYBE08FieldMapping, "")
apiRequest["customerNumber"] = l.svcCtx.Config.WestConfig.SecretId
apiRequest["timeStamp"] = fmt.Sprintf("%d", time.Now().UnixNano()/int64(time.Millisecond))
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("layoutIdcard", apiRequest, l.svcCtx.Config.WestConfig.SecretId)
if callAPIErr != nil {
if callAPIErr.Code == errs.ErrDataSource.Code {
encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key)

View File

@@ -64,8 +64,6 @@ type FLXGDEC7Request struct {
Name string `json:"name" validate:"required,min=1,validName"`
}
type IVYZ0B03Request struct {
}
type IVYZ385ERequest struct {
IDCard string `json:"id_card" validate:"required,validIDCard"`
Name string `json:"name" validate:"required,min=1,validName"`
@@ -146,10 +144,14 @@ type YYSY09CDRequest struct {
IDCard string `json:"id_card" validate:"required,validIDCard"`
Name string `json:"name" validate:"required,min=1,validName"`
}
type YYSYBE08Request struct {
type IVYZ0b03Request struct {
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
Name string `json:"name" validate:"required,min=1,validName"`
}
type YYSYBE08Request struct{
Name string `json:"name" validate:"required,min=1,validName"`
IDCard string `json:"id_card" validate:"required,validIDCard"`
}
type YYSYD50FRequest struct {
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
IDCard string `json:"id_card" validate:"required,validIDCard"`

View File

@@ -135,10 +135,14 @@ var YYSY09CDFieldMapping = map[string]string{
"MobileNo": "phone",
"MobileType": "phoneType",
}
var YYSYBE08FieldMapping = map[string]string{
var IVYZ0b03FieldMapping = map[string]string{
"Name": "name",
"MobileNo": "phone",
}
var YYSYBE08FieldMapping = map[string]string{
"MobileNo": "xM",
"IDCard": "gMSFZHM",
}
var YYSYD50FFieldMapping = map[string]string{
"MobileNo": "phone",
"IDCard": "idNo",