f
This commit is contained in:
@@ -2,6 +2,7 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -106,6 +107,7 @@ func (l *QueryServiceLogic) ProcessMarriageLogic(req *types.QueryServiceReq) (*t
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
l.recordQueryUserRecord(params, "marriage", userID, cacheNo)
|
||||
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)
|
||||
@@ -166,7 +168,7 @@ func (l *QueryServiceLogic) ProcessHomeServiceLogic(req *types.QueryServiceReq)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
l.recordQueryUserRecord(params, "homeservice", userID, cacheNo)
|
||||
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)
|
||||
@@ -227,7 +229,7 @@ func (l *QueryServiceLogic) ProcessRiskAssessmentLogic(req *types.QueryServiceRe
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
l.recordQueryUserRecord(params, "riskassessment", userID, cacheNo)
|
||||
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)
|
||||
@@ -287,7 +289,7 @@ func (l *QueryServiceLogic) ProcessCompanyInfoLogic(req *types.QueryServiceReq)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
l.recordQueryUserRecord(params, "companyinfo", userID, cacheNo)
|
||||
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)
|
||||
@@ -348,7 +350,7 @@ func (l *QueryServiceLogic) ProcessRentalInfoLogic(req *types.QueryServiceReq) (
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
l.recordQueryUserRecord(params, "rentalinfo", userID, cacheNo)
|
||||
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)
|
||||
@@ -409,7 +411,7 @@ func (l *QueryServiceLogic) ProcessPreLoanBackgroundCheckLogic(req *types.QueryS
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
l.recordQueryUserRecord(params, "preloanbackgroundcheck", userID, cacheNo)
|
||||
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)
|
||||
@@ -469,7 +471,7 @@ func (l *QueryServiceLogic) ProcessBackgroundCheckLogic(req *types.QueryServiceR
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
l.recordQueryUserRecord(params, "backgroundcheck", userID, cacheNo)
|
||||
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)
|
||||
@@ -527,7 +529,7 @@ func (l *QueryServiceLogic) ProcessPersonalDataLogic(req *types.QueryServiceReq)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
l.recordQueryUserRecord(params, "personalData", userID, cacheNo)
|
||||
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)
|
||||
@@ -558,6 +560,10 @@ func (l *QueryServiceLogic) DecryptData(data string) ([]byte, error) {
|
||||
|
||||
// 校验验证码
|
||||
func (l *QueryServiceLogic) VerifyCode(mobile string, code string) error {
|
||||
// 开发环境下跳过验证码验证
|
||||
if l.svcCtx.Config.SystemConfig.SkipVerifyCode {
|
||||
return nil
|
||||
}
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
encryptedMobile, err := crypto.EncryptMobile(mobile, secretKey)
|
||||
if err != nil {
|
||||
@@ -579,6 +585,10 @@ func (l *QueryServiceLogic) VerifyCode(mobile string, code string) error {
|
||||
|
||||
// 二、三要素验证
|
||||
func (l *QueryServiceLogic) Verify(Name string, IDCard string, Mobile string) error {
|
||||
// 空报告模式:开发环境下跳过二/三要素验证
|
||||
if l.svcCtx.Config.SystemConfig.SkipVerify {
|
||||
return nil
|
||||
}
|
||||
if !l.svcCtx.Config.SystemConfig.ThreeVerify {
|
||||
twoVerification := service.TwoFactorVerificationRequest{
|
||||
Name: Name,
|
||||
@@ -643,6 +653,76 @@ func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product str
|
||||
return outTradeNo, nil
|
||||
}
|
||||
|
||||
// recordQueryUserRecord 写入查询用户记录表,用于通过姓名/身份证/手机号追溯订单
|
||||
// 重要:name、id_card、mobile 必须以 AES-ECB+Base64 密文入库,禁止写入明文
|
||||
func (l *QueryServiceLogic) recordQueryUserRecord(params map[string]interface{}, product string, userID int64, queryNo string) {
|
||||
getStr := func(k string) string {
|
||||
if v, ok := params[k]; ok {
|
||||
if s, ok := v.(string); ok {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
if secretKey == "" {
|
||||
l.Errorf("查询用户记录表加密失败, Encrypt.SecretKey 未配置,拒绝写入明文 queryNo=%s", queryNo)
|
||||
return
|
||||
}
|
||||
key, keyErr := hex.DecodeString(secretKey)
|
||||
if keyErr != nil {
|
||||
l.Errorf("查询用户记录表加密失败, 密钥解析错误 queryNo=%s err=%v", queryNo, keyErr)
|
||||
return
|
||||
}
|
||||
// 以下三字段仅使用加密后的值赋值,不得使用 getStr 的明文
|
||||
encName := ""
|
||||
if name := getStr("name"); name != "" {
|
||||
if s, err := crypto.AesEcbEncrypt([]byte(name), key); err != nil {
|
||||
l.Errorf("查询用户记录表姓名加密失败 queryNo=%s err=%v", queryNo, err)
|
||||
return
|
||||
} else {
|
||||
encName = s
|
||||
}
|
||||
}
|
||||
encIdCard := ""
|
||||
if idCard := getStr("id_card"); idCard != "" {
|
||||
if s, err := crypto.EncryptIDCard(idCard, key); err != nil {
|
||||
l.Errorf("查询用户记录表身份证加密失败 queryNo=%s err=%v", queryNo, err)
|
||||
return
|
||||
} else {
|
||||
encIdCard = s
|
||||
}
|
||||
}
|
||||
encMobile := ""
|
||||
if mobile := getStr("mobile"); mobile != "" {
|
||||
if s, err := crypto.EncryptMobile(mobile, secretKey); err != nil {
|
||||
l.Errorf("查询用户记录表手机号加密失败 queryNo=%s err=%v", queryNo, err)
|
||||
return
|
||||
} else {
|
||||
encMobile = s
|
||||
}
|
||||
}
|
||||
agentIdentifier := sql.NullString{}
|
||||
if v, ok := l.ctx.Value("agentIdentifier").(string); ok && v != "" {
|
||||
agentIdentifier = sql.NullString{String: v, Valid: true}
|
||||
}
|
||||
// rec 的 Name、IdCard、Mobile 仅使用密文 encName、encIdCard、encMobile
|
||||
rec := &model.QueryUserRecord{
|
||||
UserId: userID,
|
||||
Name: encName,
|
||||
IdCard: encIdCard,
|
||||
Mobile: encMobile,
|
||||
Product: product,
|
||||
QueryNo: queryNo,
|
||||
OrderId: 0,
|
||||
PlatformOrderId: sql.NullString{},
|
||||
AgentIdentifier: agentIdentifier,
|
||||
}
|
||||
if _, err := l.svcCtx.QueryUserRecordModel.Insert(l.ctx, nil, rec); err != nil {
|
||||
l.Errorf("查询用户记录表写入失败 queryNo=%s err=%v", queryNo, err)
|
||||
}
|
||||
}
|
||||
|
||||
// GetOrCreateUser 获取或创建用户
|
||||
// 1. 如果上下文中已有用户ID,直接返回
|
||||
// 2. 如果是代理查询或APP请求,创建新用户
|
||||
|
||||
Reference in New Issue
Block a user