diff --git a/app/main/api/internal/logic/query/queryservicelogic.go b/app/main/api/internal/logic/query/queryservicelogic.go index ed877b6..3098d1a 100644 --- a/app/main/api/internal/logic/query/queryservicelogic.go +++ b/app/main/api/internal/logic/query/queryservicelogic.go @@ -5,13 +5,13 @@ import ( "encoding/hex" "encoding/json" "fmt" - "time" "qnc-server/app/main/api/internal/service" "qnc-server/app/main/model" "qnc-server/common/ctxdata" "qnc-server/common/xerr" "qnc-server/pkg/lzkit/crypto" "qnc-server/pkg/lzkit/validator" + "time" "github.com/pkg/errors" "github.com/zeromicro/go-zero/core/stores/redis" @@ -54,6 +54,7 @@ var productProcessors = map[string]func(*QueryServiceLogic, *types.QueryServiceR "preloanbackgroundcheck": (*QueryServiceLogic).ProcessPreLoanBackgroundCheckLogic, "backgroundcheck": (*QueryServiceLogic).ProcessBackgroundCheckLogic, "personalData": (*QueryServiceLogic).ProcessPersonalDataLogic, + "consumerFinanceReport": (*QueryServiceLogic).ProcessConsumerFinanceReportLogic, } func (l *QueryServiceLogic) PreprocessLogic(req *types.QueryServiceReq, product string) (*types.QueryServiceResp, error) { @@ -542,7 +543,64 @@ func (l *QueryServiceLogic) ProcessPersonalDataLogic(req *types.QueryServiceReq) RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter, }, nil } +func (l *QueryServiceLogic) ProcessConsumerFinanceReportLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) { + // AES解密 + decryptData, DecryptDataErr := l.DecryptData(req.Data) + if DecryptDataErr != nil { + return nil, DecryptDataErr + } + // 校验参数 + var data types.ConsumerFinanceReportReq + if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr) + } + + if validatorErr := validator.Validate(data); validatorErr != nil { + return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr) + } + + // 校验验证码 + verifyCodeErr := l.VerifyCode(data.Mobile, data.Code) + if verifyCodeErr != nil { + return nil, verifyCodeErr + } + + // 校验三要素 + verifyErr := l.Verify(data.Name, data.IDCard, data.Mobile) + if verifyErr != nil { + return nil, verifyErr + } + + // 缓存 + params := map[string]interface{}{ + "name": data.Name, + "id_card": data.IDCard, + "mobile": data.Mobile, + } + userID, err := l.GetOrCreateUser() + if err != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err) + } + cacheNo, cacheDataErr := l.CacheData(params, "personalData", userID) + if cacheDataErr != nil { + return nil, cacheDataErr + } + + token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal) + if err != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID) + } + + // 获取当前时间戳 + now := time.Now().Unix() + return &types.QueryServiceResp{ + Id: cacheNo, + AccessToken: token, + AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire, + RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter, + }, nil +} func (l *QueryServiceLogic) DecryptData(data string) ([]byte, error) { secretKey := l.svcCtx.Config.Encrypt.SecretKey key, decodeErr := hex.DecodeString(secretKey) diff --git a/app/main/api/internal/types/query.go b/app/main/api/internal/types/query.go index c5e81bd..f12fbea 100644 --- a/app/main/api/internal/types/query.go +++ b/app/main/api/internal/types/query.go @@ -58,6 +58,12 @@ type PersonalDataReq struct { Mobile string `json:"mobile" validate:"required,mobile"` Code string `json:"code" validate:"required"` } +type ConsumerFinanceReportReq struct { + Name string `json:"name" validate:"required,name"` + IDCard string `json:"id_card" validate:"required,idCard"` + Mobile string `json:"mobile" validate:"required,mobile"` + Code string `json:"code" validate:"required"` +} type EntLawsuitReq struct { EntName string `json:"ent_name" validate:"required,name"` EntCode string `json:"ent_code" validate:"required,USCI"`