新增个人不良标准版FLXG0V3B

This commit is contained in:
liangzai 2024-11-06 17:10:34 +08:00
parent 2a2078eebe
commit b0d13d3642
7 changed files with 156 additions and 1 deletions

View File

@ -71,6 +71,9 @@ service api-api {
@handler FLXG3D56 @handler FLXG3D56
post /FLXG3D56 (request) returns (string) post /FLXG3D56 (request) returns (string)
@handler FLXG0V3B
post /FLXG0V3B (request) returns (string)
} }
@server ( @server (

View File

@ -0,0 +1,29 @@
package FLXG
import (
"net/http"
"tianyuan-api/pkg/errs"
"tianyuan-api/pkg/response"
"github.com/zeromicro/go-zero/rest/httpx"
"tianyuan-api/apps/api/internal/logic/FLXG"
"tianyuan-api/apps/api/internal/svc"
"tianyuan-api/apps/api/internal/types"
)
func FLXG0V3BHandler(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 {
response.Fail(r.Context(), w, errs.ErrParamValidation, nil)
return
}
l := FLXG.NewFLXG0V3BLogic(r.Context(), svcCtx)
resp, err := l.FLXG0V3B(&req)
if err != nil {
response.Fail(r.Context(), w, err, resp)
} else {
response.Success(r.Context(), w, resp)
}
}
}

View File

@ -18,7 +18,6 @@ func FLXG3D56Handler(svcCtx *svc.ServiceContext) http.HandlerFunc {
response.Fail(r.Context(), w, errs.ErrParamValidation, nil) response.Fail(r.Context(), w, errs.ErrParamValidation, nil)
return return
} }
l := FLXG.NewFLXG3D56Logic(r.Context(), svcCtx) l := FLXG.NewFLXG3D56Logic(r.Context(), svcCtx)
resp, err := l.FLXG3D56(&req) resp, err := l.FLXG3D56(&req)
if err != nil { if err != nil {

View File

@ -21,6 +21,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithMiddlewares( rest.WithMiddlewares(
[]rest.Middleware{serverCtx.ApiAuthInterceptor}, []rest.Middleware{serverCtx.ApiAuthInterceptor},
[]rest.Route{ []rest.Route{
{
Method: http.MethodPost,
Path: "/FLXG0V3B",
Handler: FLXG.FLXG0V3BHandler(serverCtx),
},
{ {
Method: http.MethodPost, Method: http.MethodPost,
Path: "/FLXG162A", Path: "/FLXG162A",

View File

@ -0,0 +1,111 @@
package FLXG
import (
"context"
"encoding/hex"
"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"
"tianyuan-api/apps/api/internal/svc"
"tianyuan-api/apps/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type FLXG0V3BLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewFLXG0V3BLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FLXG0V3BLogic {
return &FLXG0V3BLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FLXG0V3BLogic) FLXG0V3B(req *types.Request) (resp string, err *errs.AppError) {
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.FLXG0V3BRequest
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.FLXG0V3BFieldMapping, "data")
westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G34BJ03", 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

@ -16,6 +16,10 @@ type Name struct {
} }
type FLXG3D56Request struct { type FLXG3D56Request struct {
IDCard string `json:"id_card" validate:"required,validIDCard"`
Name string `json:"name" validate:"required,min=1,validName"`
}
type FLXG0V3BRequest struct {
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"` MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
IDCard string `json:"id_card" validate:"required,validIDCard"` IDCard string `json:"id_card" validate:"required,validIDCard"`
Name string `json:"name" validate:"required,min=1,validName"` Name string `json:"name" validate:"required,min=1,validName"`

View File

@ -6,6 +6,10 @@ var FLXG3D56FieldMapping = map[string]string{
"MobileNo": "cell", "MobileNo": "cell",
"TimeRange": "time_range", "TimeRange": "time_range",
} }
var FLXG0V3BFieldMapping = map[string]string{
"IDCard": "id_card",
"Name": "name",
}
var FLXG54F5FieldMapping = map[string]string{ var FLXG54F5FieldMapping = map[string]string{
"MobileNo": "mobile", "MobileNo": "mobile",
} }