新增天聚数行平台,手机归属地查询,身份证归属地查询
This commit is contained in:
@@ -38,6 +38,85 @@ func NewQueryServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Quer
|
||||
func (l *QueryServiceLogic) QueryService(req *types.QueryServiceReq) (resp *types.QueryServiceResp, err error) {
|
||||
return l.PreprocessLogic(req, req.Product)
|
||||
}
|
||||
func (l *QueryServiceLogic) DecryptData(data string) ([]byte, error) {
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
if decodeErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "密钥获取失败: %+v", decodeErr)
|
||||
}
|
||||
decryptData, aesDecryptErr := crypto.AesDecrypt(data, key)
|
||||
if aesDecryptErr != nil || len(decryptData) == 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "解密失败: %+v", aesDecryptErr)
|
||||
}
|
||||
return decryptData, nil
|
||||
}
|
||||
|
||||
// 校验验证码
|
||||
func (l *QueryServiceLogic) VerifyCode(mobile string, code string) error {
|
||||
codeRedisKey := fmt.Sprintf("%s:%s", "query", mobile)
|
||||
cacheCode, err := l.svcCtx.Redis.Get(codeRedisKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return errors.Wrapf(xerr.NewErrMsg("验证码已过期"), "验证码过期: %s", mobile)
|
||||
}
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "读取验证码redis缓存失败, mobile: %s, err: %+v", mobile, err)
|
||||
}
|
||||
if cacheCode != code {
|
||||
return errors.Wrapf(xerr.NewErrMsg("验证码不正确"), "验证码不正确: %s", mobile)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 二、三要素验证
|
||||
func (l *QueryServiceLogic) Verify(Name string, IDCard string, Mobile string) error {
|
||||
if l.svcCtx.Config.SystemConfig.ThreeVerify {
|
||||
// 三要素验证
|
||||
threeVerification := service.ThreeFactorVerificationRequest{
|
||||
Name: Name,
|
||||
IDCard: IDCard,
|
||||
Mobile: Mobile,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "三要素验证失败: %+v", err)
|
||||
}
|
||||
if !verification.Passed {
|
||||
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "三要素验证不通过: %+v", err)
|
||||
}
|
||||
} else {
|
||||
twoVerification := service.TwoFactorVerificationRequest{
|
||||
Name: Name,
|
||||
IDCard: IDCard,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "二要素验证失败: %+v", err)
|
||||
}
|
||||
if !verification.Passed {
|
||||
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "二要素验证不通过: %+v", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 缓存
|
||||
func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product string, userID int64) (string, error) {
|
||||
queryCache := types.QueryCacheLoad{
|
||||
Params: params,
|
||||
Product: Product,
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 序列化参数失败: %+v", marshalErr)
|
||||
}
|
||||
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
||||
redisKey := fmt.Sprintf("%d:%s", userID, outTradeNo)
|
||||
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), int(2*time.Hour))
|
||||
if cacheErr != nil {
|
||||
return "", cacheErr
|
||||
}
|
||||
return outTradeNo, nil
|
||||
}
|
||||
|
||||
var productProcessors = map[string]func(*QueryServiceLogic, *types.QueryServiceReq) (*types.QueryServiceResp, error){
|
||||
"marriage": (*QueryServiceLogic).ProcessMarriageLogic,
|
||||
@@ -64,26 +143,30 @@ var productProcessors = map[string]func(*QueryServiceLogic, *types.QueryServiceR
|
||||
"toc_BankCardFourElements": (*QueryServiceLogic).ProcessTocBankCardFourElementsLogic,
|
||||
"toc_PersonalConsumptionRestriction": (*QueryServiceLogic).ProcessTocPersonalConsumptionRestrictionLogic,
|
||||
"toc_PersonalDiscredit": (*QueryServiceLogic).ProcessTocPersonalDiscreditLogic,
|
||||
"toc_BankCardBlacklist": (*QueryServiceLogic).ProcessTocBankCardBlacklistLogic,
|
||||
|
||||
// 查车部分
|
||||
"toc_vehicleInsuranceSummary": (*QueryServiceLogic).ProcessTocVehicleInsuranceSummaryLogic, // 车辆出险信息
|
||||
"toc_vehicleMaintenanceRecord": (*QueryServiceLogic).ProcessTocVehicleMaintenanceRecordLogic, // 车辆维修记录
|
||||
"toc_VehiclesUnderName": (*QueryServiceLogic).ProcessTocVehiclesUnderNameLogic, // 名下车辆
|
||||
"toc_vehicleValuation": (*QueryServiceLogic).ProcessTocVehicleValuationLogic, // 车辆估值
|
||||
"toc_chassisNumberCheck": (*QueryServiceLogic).ProcessTocChassisNumberCheckLogic, // 车辆识别代码
|
||||
"toc_vehicleTransferCount": (*QueryServiceLogic).ProcessTocVehicleTransferCountLogic, // 车辆过户次数
|
||||
|
||||
"toc_ExitRestriction": (*QueryServiceLogic).ProcessTocExitRestrictionLogic, // 限制出境
|
||||
"toc_MonthlyMobileConsumptionLevel": (*QueryServiceLogic).ProcessTocMonthlyMobileConsumptionLevelLogic, // 月消费水平
|
||||
"toc_EducationVerification": (*QueryServiceLogic).ProcessTocEducationVerificationLogic, // 学历认证
|
||||
"toc_FraudGamblingCheck": (*QueryServiceLogic).ProcessTocFraudGamblingCheckLogic, // 反赌反诈
|
||||
"toc_MobileNumberValidation": (*QueryServiceLogic).ProcessTocMobileNumberValidationLogic, // 手机号验证
|
||||
"toc_BankCardLocation": (*QueryServiceLogic).ProcessTocBankCardLocationLogic, // 银行卡归属地
|
||||
"toc_BankCardNameElementVerification": (*QueryServiceLogic).ProcessTocBankCardNameElementVerificationLogic, // 银行卡姓名认证
|
||||
"toc_BankCardIDElementVerification": (*QueryServiceLogic).ProcessTocBankCardIDElementVerificationLogic, // 银行卡身份证认证
|
||||
"toc_BankCardThreeElementsVerification": (*QueryServiceLogic).ProcessTocBankCardThreeElementsVerificationLogic, // 银行卡三要素认证
|
||||
"toc_MobileRiskAssessment": (*QueryServiceLogic).ProcessTocMobileRiskAssessmentLogic, // 手机号风险评估
|
||||
"toc_MobileDrugFraudRiskCheck": (*QueryServiceLogic).ProcessTocMobileDrugFraudRiskCheckLogic, // 手机号反赌反诈
|
||||
"toc_MobileLocation": (*QueryServiceLogic).ProcessTocMobileLocationLogic, // 手机归属地
|
||||
"toc_IDCardLocation": (*QueryServiceLogic).ProcessTocIDCardLocationLogic, // 身份证归属地
|
||||
|
||||
// 车辆部分
|
||||
"toc_BankCardBlacklist": (*QueryServiceLogic).ProcessTocBankCardBlacklistLogic,
|
||||
"toc_VehiclesUnderName": (*QueryServiceLogic).ProcessTocVehiclesUnderNameLogic,
|
||||
"toc_vehicleInsuranceSummary": (*QueryServiceLogic).ProcessTocVehicleInsuranceSummaryLogic,
|
||||
"toc_vehicleMaintenanceRecord": (*QueryServiceLogic).ProcessTocVehicleMaintenanceRecordLogic,
|
||||
"toc_vehicleValuation": (*QueryServiceLogic).ProcessTocVehicleValuationLogic,
|
||||
"toc_chassisNumberCheck": (*QueryServiceLogic).ProcessTocChassisNumberCheckLogic,
|
||||
"toc_vehicleTransferCount": (*QueryServiceLogic).ProcessTocVehicleTransferCountLogic,
|
||||
"toc_ExitRestriction": (*QueryServiceLogic).ProcessTocExitRestrictionLogic,
|
||||
"toc_MonthlyMobileConsumptionLevel": (*QueryServiceLogic).ProcessTocMonthlyMobileConsumptionLevelLogic,
|
||||
"toc_EducationVerification": (*QueryServiceLogic).ProcessTocEducationVerificationLogic,
|
||||
"toc_FraudGamblingCheck": (*QueryServiceLogic).ProcessTocFraudGamblingCheckLogic,
|
||||
"toc_MobileNumberValidation": (*QueryServiceLogic).ProcessTocMobileNumberValidationLogic,
|
||||
"toc_BankCardLocation": (*QueryServiceLogic).ProcessTocBankCardLocationLogic,
|
||||
"toc_BankCardNameElementVerification": (*QueryServiceLogic).ProcessTocBankCardNameElementVerificationLogic,
|
||||
"toc_BankCardIDElementVerification": (*QueryServiceLogic).ProcessTocBankCardIDElementVerificationLogic,
|
||||
"toc_BankCardThreeElementsVerification": (*QueryServiceLogic).ProcessTocBankCardThreeElementsVerificationLogic,
|
||||
"toc_MobileRiskAssessment": (*QueryServiceLogic).ProcessTocMobileRiskAssessmentLogic,
|
||||
"toc_MobileDrugFraudRiskCheck": (*QueryServiceLogic).ProcessTocMobileDrugFraudRiskCheckLogic,
|
||||
}
|
||||
|
||||
func (l *QueryServiceLogic) PreprocessLogic(req *types.QueryServiceReq, product string) (*types.QueryServiceResp, error) {
|
||||
@@ -1750,82 +1833,71 @@ func (l *QueryServiceLogic) ProcessTocFraudGamblingCheckLogic(req *types.QuerySe
|
||||
|
||||
return &types.QueryServiceResp{Id: cacheNo}, nil
|
||||
}
|
||||
func (l *QueryServiceLogic) DecryptData(data string) ([]byte, error) {
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
if decodeErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "密钥获取失败: %+v", decodeErr)
|
||||
|
||||
// ProcessTocMobileLocationLogic 手机归属地
|
||||
func (l *QueryServiceLogic) ProcessTocMobileLocationLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 获取用户信息失败, %+v", getUidErr)
|
||||
}
|
||||
decryptData, aesDecryptErr := crypto.AesDecrypt(data, key)
|
||||
if aesDecryptErr != nil || len(decryptData) == 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "解密失败: %+v", aesDecryptErr)
|
||||
|
||||
// AES解密
|
||||
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
||||
if DecryptDataErr != nil {
|
||||
return nil, DecryptDataErr
|
||||
}
|
||||
return decryptData, nil
|
||||
|
||||
// 校验参数
|
||||
var data types.TocMobileLocation
|
||||
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)
|
||||
}
|
||||
|
||||
params := map[string]interface{}{
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "toc_MobileLocation", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
return &types.QueryServiceResp{Id: cacheNo}, nil
|
||||
}
|
||||
|
||||
// 校验验证码
|
||||
func (l *QueryServiceLogic) VerifyCode(mobile string, code string) error {
|
||||
codeRedisKey := fmt.Sprintf("%s:%s", "query", mobile)
|
||||
cacheCode, err := l.svcCtx.Redis.Get(codeRedisKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return errors.Wrapf(xerr.NewErrMsg("验证码已过期"), "验证码过期: %s", mobile)
|
||||
}
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "读取验证码redis缓存失败, mobile: %s, err: %+v", mobile, err)
|
||||
// ProcessTocIDCardLocationLogic 身份证归属地
|
||||
func (l *QueryServiceLogic) ProcessTocIDCardLocationLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) {
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 获取用户信息失败, %+v", getUidErr)
|
||||
}
|
||||
if cacheCode != code {
|
||||
return errors.Wrapf(xerr.NewErrMsg("验证码不正确"), "验证码不正确: %s", mobile)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 二、三要素验证
|
||||
func (l *QueryServiceLogic) Verify(Name string, IDCard string, Mobile string) error {
|
||||
if l.svcCtx.Config.SystemConfig.ThreeVerify {
|
||||
// 三要素验证
|
||||
threeVerification := service.ThreeFactorVerificationRequest{
|
||||
Name: Name,
|
||||
IDCard: IDCard,
|
||||
Mobile: Mobile,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "三要素验证失败: %+v", err)
|
||||
}
|
||||
if !verification.Passed {
|
||||
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "三要素验证不通过: %+v", err)
|
||||
}
|
||||
} else {
|
||||
twoVerification := service.TwoFactorVerificationRequest{
|
||||
Name: Name,
|
||||
IDCard: IDCard,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "二要素验证失败: %+v", err)
|
||||
}
|
||||
if !verification.Passed {
|
||||
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "二要素验证不通过: %+v", err)
|
||||
}
|
||||
// AES解密
|
||||
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
||||
if DecryptDataErr != nil {
|
||||
return nil, DecryptDataErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 缓存
|
||||
func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product string, userID int64) (string, error) {
|
||||
queryCache := types.QueryCacheLoad{
|
||||
Params: params,
|
||||
Product: Product,
|
||||
// 校验参数
|
||||
var data types.TocIDCardLocation
|
||||
if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr)
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 序列化参数失败: %+v", marshalErr)
|
||||
|
||||
if validatorErr := validator.Validate(data); validatorErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr)
|
||||
}
|
||||
outTradeNo := l.svcCtx.WechatPayService.GenerateOutTradeNo()
|
||||
redisKey := fmt.Sprintf("%d:%s", userID, outTradeNo)
|
||||
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), int(2*time.Hour))
|
||||
if cacheErr != nil {
|
||||
return "", cacheErr
|
||||
|
||||
params := map[string]interface{}{
|
||||
"id_card": data.IDCard,
|
||||
}
|
||||
return outTradeNo, nil
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "toc_IDCardLocation", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
return &types.QueryServiceResp{Id: cacheNo}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user