fix comb86pm
add flxg0687
This commit is contained in:
100
apps/api/internal/logic/FLXG/flxg0687logic.go
Normal file
100
apps/api/internal/logic/FLXG/flxg0687logic.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package FLXG
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
|
||||
"tianyuan-api/apps/api/internal/svc"
|
||||
"tianyuan-api/apps/api/internal/types"
|
||||
"tianyuan-api/apps/api/internal/validator"
|
||||
"tianyuan-api/pkg/crypto"
|
||||
"tianyuan-api/pkg/errs"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type FLXG0687Logic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewFLXG0687Logic(ctx context.Context, svcCtx *svc.ServiceContext) *FLXG0687Logic {
|
||||
return &FLXG0687Logic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *FLXG0687Logic) FLXG0687(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.FLXG0687Request
|
||||
if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil {
|
||||
return "", errs.ErrParamValidation
|
||||
}
|
||||
// 3、组装羽山请求参数
|
||||
yushanReq := map[string]interface{}{
|
||||
"keyWord": data.IDCard,
|
||||
"type": 3,
|
||||
}
|
||||
respData, reqErr := l.svcCtx.YushanService.Request("RIS031", yushanReq)
|
||||
if reqErr != nil {
|
||||
logx.Errorf("羽山 RIS031 请求失败:err:%v", reqErr)
|
||||
if appErr, ok := reqErr.(*errs.AppError); ok {
|
||||
return "", appErr
|
||||
}
|
||||
return "", errs.ErrSystem
|
||||
}
|
||||
if len(respData) == 0 {
|
||||
return "", errs.ErrNotFound
|
||||
}
|
||||
|
||||
encryptData, aesEncrypt := crypto.AesEncrypt(respData, key)
|
||||
if aesEncrypt != nil {
|
||||
return "", errs.ErrSystem
|
||||
}
|
||||
return encryptData, nil
|
||||
}
|
||||
Reference in New Issue
Block a user