增加IVYZ9a2b
This commit is contained in:
@@ -34,6 +34,9 @@ service api-api {
|
||||
|
||||
@handler IVYZADEE
|
||||
post /IVYZADEE (request) returns (string)
|
||||
|
||||
@handler IVYZ9A2B
|
||||
post /IVYZ9A2B (request) returns (string)
|
||||
}
|
||||
|
||||
@server (
|
||||
|
||||
28
apps/api/internal/handler/IVYZ/ivyz9a2bhandler.go
Normal file
28
apps/api/internal/handler/IVYZ/ivyz9a2bhandler.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package IVYZ
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"tianyuan-api/apps/api/internal/logic/IVYZ"
|
||||
"tianyuan-api/apps/api/internal/svc"
|
||||
"tianyuan-api/apps/api/internal/types"
|
||||
)
|
||||
|
||||
func IVYZ9A2BHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.Request
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := IVYZ.NewIVYZ9A2BLogic(r.Context(), svcCtx)
|
||||
resp, err := l.IVYZ9A2B(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,6 +115,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/IVYZ9363",
|
||||
Handler: IVYZ.IVYZ9363Handler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/IVYZ9A2B",
|
||||
Handler: IVYZ.IVYZ9A2BHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/IVYZADEE",
|
||||
|
||||
110
apps/api/internal/logic/IVYZ/ivyz9a2blogic.go
Normal file
110
apps/api/internal/logic/IVYZ/ivyz9a2blogic.go
Normal file
@@ -0,0 +1,110 @@
|
||||
package IVYZ
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
|
||||
"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"
|
||||
"tianyuan-api/pkg/crypto"
|
||||
"tianyuan-api/pkg/errs"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type IVYZ9A2BLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewIVYZ9A2BLogic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZ9A2BLogic {
|
||||
return &IVYZ9A2BLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *IVYZ9A2BLogic) IVYZ9A2B(req *types.Request) (resp string, err error) {
|
||||
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.IVYZ9A2BRequest
|
||||
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.IVYZ9A2BFieldMapping, "data")
|
||||
|
||||
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G11BJ06", 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
|
||||
}
|
||||
@@ -158,3 +158,7 @@ type YYSYF7DBRequest struct {
|
||||
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
||||
StartDate string `json:"start_date" validate:"required,validDate" encrypt:"false"`
|
||||
}
|
||||
type IVYZ9A2BRequest struct {
|
||||
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
||||
Name string `json:"name" validate:"required,min=1,validName"`
|
||||
}
|
||||
|
||||
@@ -142,3 +142,7 @@ var YYSYF7DBFieldMapping = map[string]string{
|
||||
"MobileNo": "phone",
|
||||
"StartDate": "startDate",
|
||||
}
|
||||
var IVYZ9A2BFieldMapping = map[string]string{
|
||||
"IDCard": "id_card_value",
|
||||
"Name": "name_value",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user