新增天聚数行平台,手机归属地查询,身份证归属地查询
This commit is contained in:
parent
9eb13590fc
commit
b8377d8887
@ -28,6 +28,9 @@ YushanConfig:
|
||||
ApiKey: "4c566c4a4b543164535455685655316c"
|
||||
AcctID: "YSSJ843926726"
|
||||
Url: "http://proxy.tianyuanapi.com/credit-gw/service"
|
||||
TianjuConfig:
|
||||
ApiKey: "479bcac2a77b56e976d044ff2bd996f4"
|
||||
Url: "https://apis.tianapi.com"
|
||||
Alipay:
|
||||
AppID: "2021004165608254"
|
||||
PrivateKey: "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCvo8TmTNnVguKwMYrX0z01PfUlSS+AqwwCH1+/P39q6No+09yO1bjhy4LowtDfwKX8F+IZLl5Cx06f1M8KzPvjQliBAfMJ1FuTEOOXPmtE1YLAYIUMLbltR6Crnp16T28eF41Uo0PUo2ple/oSjWhYgsTJjyBMXY04f6HM2uZlHOhG2aOUz2CDNbvkEhNddazuPMgo8Xl7vwENGDFTPa85HmSSoDppFowLdYfAw2Jl1ilKNg4sOPc6d507nXdgpMlUguwZxol6OQ2hBS6v9OjII5cJ1tyR/klJRapnIPmFaPvhDozYwjU6Z3jMvcbrByl0qNpLrbEFS4pn9hfRo4YrAgMBAAECggEAZAi0Ri6TCqXnEk7FMzMec0p8auYJ5hCFYFgaIkS5/1vroUjtH3TePcu5HXSHnkiMwM2hepIMIaB+SU3dNduVwtOwsJk5oOmP1m0SErv8QFISjBrs7AjGyVS4T8ahDl5bfRoQ5pmuMld4a6B2x0Y+ndqs1ddsn9HQctNOhexOuFsSjX1N3PZxFzfRTmGzxf7kwZGlXMN7G1r3Rp4koylYHVpqjXIK34Anc8SVljxFVkFOk62QvBdYcCucepymHNl0pYwPDCCylPH8OpIXOErmPldTflmoLRc+ywu9rw4I8UvkoPgTe+16he+jdi/N7cwbMTfixq+/Aeadjv2AgMuwkQKBgQDgLS3dRFAc6FMSJIA0FKgv5D/R3NZgWilbOAF11PtnE4AX4i0yZryGtLq+3NWCWYQF8iI60lIy3rEf9zWncwfadhWTEDUBjjrqqU46N2ddTzHsDw09I56TT2vrEwCdmJ2vh1hxPfgE3fSDnKbP4Wkl77JCTH7v0rA1jb65Plt8TwKBgQDIkrXqe/pVHDdxswoPL6em32TnKiaJ/R/UDDio20mgGG7FWEJAY5yYtu0y9Ug7W8PjJE7/cJ2/dwDSvHZm8R0iq8d6XkzN03Z+uvzGnMdUraXJZHSPZ5L/2ofysXjt/OtpA1Sox5++1+obiq6CZ6IYORLSxSf+it1JUbKXsNcVZQKBgQCTPzm7984DXtqJtS38h4D9jBgbWcn6Gd7GSuAyrIXBa76ccXSsgWzdskJjcZxQdUnRufyf1Fwni7yeOXullFoZNazwHxoh/nFWh4SZmqCrWoR5AF36xbW4HtfM3XtvCLqye90s7L5HPB8Kf8/WBcJSJ8JX5/UMw7/4PTWEaaAf4wKBgQCEXu7YVgIccYbV7wdQhm7q3rxFI7hTkU6UL4ylRDQPCJDyhREUValf0DozS1XkdueM3MWWJ8i0N+G/MsohnjdQTnZT+DBQFqM5eEai/Y1AAWpMw5N5oS2O1barIR1iU2053QzeZwCyfuTuUFRjk+mSevhFSgDfKN5qKRTor7kDUQKBgB3fC6jO8XCwimPvpsiGnuddNAq/w8iqSjSwuSvbI0Q7Lq6rvAIw2AmkC5t4kW4JcZLUgDvAs4GFoPDYhoL73vc1e2c35VTNck6IxZSQzzQ9pfXFiLtTe6eqggN4EOPGHKLd92CMAgoeySsp3NydpGSx2N/NUqp8BkoFLQ/k2W9o"
|
||||
|
@ -30,6 +30,9 @@ YushanConfig:
|
||||
ApiKey: "4c566c4a4b543164535455685655316c"
|
||||
AcctID: "YSSJ843926726"
|
||||
Url: "https://api.yushanshuju.com/credit-gw/service"
|
||||
TianjuConfig:
|
||||
ApiKey: "479bcac2a77b56e976d044ff2bd996f4"
|
||||
Url: "https://apis.tianapi.com"
|
||||
Alipay:
|
||||
AppID: "2021004165608254"
|
||||
PrivateKey: "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCvo8TmTNnVguKwMYrX0z01PfUlSS+AqwwCH1+/P39q6No+09yO1bjhy4LowtDfwKX8F+IZLl5Cx06f1M8KzPvjQliBAfMJ1FuTEOOXPmtE1YLAYIUMLbltR6Crnp16T28eF41Uo0PUo2ple/oSjWhYgsTJjyBMXY04f6HM2uZlHOhG2aOUz2CDNbvkEhNddazuPMgo8Xl7vwENGDFTPa85HmSSoDppFowLdYfAw2Jl1ilKNg4sOPc6d507nXdgpMlUguwZxol6OQ2hBS6v9OjII5cJ1tyR/klJRapnIPmFaPvhDozYwjU6Z3jMvcbrByl0qNpLrbEFS4pn9hfRo4YrAgMBAAECggEAZAi0Ri6TCqXnEk7FMzMec0p8auYJ5hCFYFgaIkS5/1vroUjtH3TePcu5HXSHnkiMwM2hepIMIaB+SU3dNduVwtOwsJk5oOmP1m0SErv8QFISjBrs7AjGyVS4T8ahDl5bfRoQ5pmuMld4a6B2x0Y+ndqs1ddsn9HQctNOhexOuFsSjX1N3PZxFzfRTmGzxf7kwZGlXMN7G1r3Rp4koylYHVpqjXIK34Anc8SVljxFVkFOk62QvBdYcCucepymHNl0pYwPDCCylPH8OpIXOErmPldTflmoLRc+ywu9rw4I8UvkoPgTe+16he+jdi/N7cwbMTfixq+/Aeadjv2AgMuwkQKBgQDgLS3dRFAc6FMSJIA0FKgv5D/R3NZgWilbOAF11PtnE4AX4i0yZryGtLq+3NWCWYQF8iI60lIy3rEf9zWncwfadhWTEDUBjjrqqU46N2ddTzHsDw09I56TT2vrEwCdmJ2vh1hxPfgE3fSDnKbP4Wkl77JCTH7v0rA1jb65Plt8TwKBgQDIkrXqe/pVHDdxswoPL6em32TnKiaJ/R/UDDio20mgGG7FWEJAY5yYtu0y9Ug7W8PjJE7/cJ2/dwDSvHZm8R0iq8d6XkzN03Z+uvzGnMdUraXJZHSPZ5L/2ofysXjt/OtpA1Sox5++1+obiq6CZ6IYORLSxSf+it1JUbKXsNcVZQKBgQCTPzm7984DXtqJtS38h4D9jBgbWcn6Gd7GSuAyrIXBa76ccXSsgWzdskJjcZxQdUnRufyf1Fwni7yeOXullFoZNazwHxoh/nFWh4SZmqCrWoR5AF36xbW4HtfM3XtvCLqye90s7L5HPB8Kf8/WBcJSJ8JX5/UMw7/4PTWEaaAf4wKBgQCEXu7YVgIccYbV7wdQhm7q3rxFI7hTkU6UL4ylRDQPCJDyhREUValf0DozS1XkdueM3MWWJ8i0N+G/MsohnjdQTnZT+DBQFqM5eEai/Y1AAWpMw5N5oS2O1barIR1iU2053QzeZwCyfuTuUFRjk+mSevhFSgDfKN5qKRTor7kDUQKBgB3fC6jO8XCwimPvpsiGnuddNAq/w8iqSjSwuSvbI0Q7Lq6rvAIw2AmkC5t4kW4JcZLUgDvAs4GFoPDYhoL73vc1e2c35VTNck6IxZSQzzQ9pfXFiLtTe6eqggN4EOPGHKLd92CMAgoeySsp3NydpGSx2N/NUqp8BkoFLQ/k2W9o"
|
||||
|
@ -18,6 +18,7 @@ type Config struct {
|
||||
Ali AliConfig
|
||||
WestConfig WestConfig
|
||||
YushanConfig YushanConfig
|
||||
TianjuConfig TianjuConfig
|
||||
SystemConfig SystemConfig
|
||||
}
|
||||
|
||||
@ -80,6 +81,10 @@ type YushanConfig struct {
|
||||
AcctID string
|
||||
Url string
|
||||
}
|
||||
type TianjuConfig struct {
|
||||
ApiKey string
|
||||
BaseURL string
|
||||
}
|
||||
type SystemConfig struct {
|
||||
ThreeVerify bool
|
||||
}
|
||||
|
@ -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_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,
|
||||
|
||||
// 查车部分
|
||||
"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, // 身份证归属地
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
// 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)
|
||||
}
|
||||
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,
|
||||
// AES解密
|
||||
decryptData, DecryptDataErr := l.DecryptData(req.Data)
|
||||
if DecryptDataErr != nil {
|
||||
return nil, DecryptDataErr
|
||||
}
|
||||
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,
|
||||
// 校验参数
|
||||
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
|
||||
}
|
||||
|
@ -27,18 +27,20 @@ type ApiRequestService struct {
|
||||
config config.Config
|
||||
westDexService *WestDexService
|
||||
yushanService *YushanService
|
||||
tianjuService *TianjuService
|
||||
featureModel model.FeatureModel
|
||||
productFeatureModel model.ProductFeatureModel
|
||||
}
|
||||
|
||||
// NewApiRequestService 是一个构造函数,用于初始化 ApiRequestService
|
||||
func NewApiRequestService(c config.Config, westDexService *WestDexService, yushanService *YushanService, featureModel model.FeatureModel, productFeatureModel model.ProductFeatureModel) *ApiRequestService {
|
||||
func NewApiRequestService(c config.Config, westDexService *WestDexService, yushanService *YushanService, tianjuService *TianjuService, featureModel model.FeatureModel, productFeatureModel model.ProductFeatureModel) *ApiRequestService {
|
||||
return &ApiRequestService{
|
||||
config: c,
|
||||
featureModel: featureModel,
|
||||
productFeatureModel: productFeatureModel,
|
||||
westDexService: westDexService,
|
||||
yushanService: yushanService,
|
||||
tianjuService: tianjuService,
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,17 +189,17 @@ var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, err
|
||||
"KZEYS": (*ApiRequestService).ProcessKZEYSRequest,
|
||||
"P_C_B332": (*ApiRequestService).ProcessP_C_B332Request,
|
||||
"FIN019": (*ApiRequestService).ProcessFIN019Request,
|
||||
"CAR061": (*ApiRequestService).ProcessCAR061Request,
|
||||
"G10SC02": (*ApiRequestService).ProcessG10SC02Request,
|
||||
"G03HZ01": (*ApiRequestService).ProcessG03HZ01Request,
|
||||
"G02BJ02": (*ApiRequestService).ProcessG02BJ02Request,
|
||||
"G19BJ02": (*ApiRequestService).ProcessG19BJ02Request,
|
||||
"G20GZ01": (*ApiRequestService).ProcessG20GZ01Request,
|
||||
"CAR074": (*ApiRequestService).ProcessCAR074Request,
|
||||
"CAR058": (*ApiRequestService).ProcessCAR058Request,
|
||||
"CAR079": (*ApiRequestService).ProcessCAR079Request,
|
||||
"CAR066": (*ApiRequestService).ProcessCAR066Request,
|
||||
"CAR100": (*ApiRequestService).ProcessCAR100Request,
|
||||
"CAR061": (*ApiRequestService).ProcessCAR061Request, // 名下车辆
|
||||
"CAR074": (*ApiRequestService).ProcessCAR074Request, // 车辆出险信息
|
||||
"CAR058": (*ApiRequestService).ProcessCAR058Request, // 车辆维保记录
|
||||
"CAR079": (*ApiRequestService).ProcessCAR079Request, // 车架号查车
|
||||
"CAR066": (*ApiRequestService).ProcessCAR066Request, // 车辆过户次数
|
||||
"CAR100": (*ApiRequestService).ProcessCAR100Request, // 车辆估值
|
||||
"G37SC01": (*ApiRequestService).ProcessG37SC01Request,
|
||||
"G36SC01": (*ApiRequestService).ProcessG36SC01Request,
|
||||
"G22SC01": (*ApiRequestService).ProcessG22SC01Request,
|
||||
@ -214,6 +216,8 @@ var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, err
|
||||
"MOB032": (*ApiRequestService).ProcessMOB032Request,
|
||||
"FIN032": (*ApiRequestService).ProcessFIN032Request,
|
||||
"HRD004": (*ApiRequestService).ProcessHRD004Request,
|
||||
"mobilelocal": (*ApiRequestService).ProcessMobilelocalRequest, // 手机归属地
|
||||
"sfz": (*ApiRequestService).ProcessSfzRequest, // 身份证归属地
|
||||
}
|
||||
|
||||
// PreprocessRequestApi 调用指定的请求处理函数
|
||||
@ -1446,3 +1450,39 @@ func (a *ApiRequestService) ProcessHRD004Request(params []byte) ([]byte, error)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// 手机归属地查询
|
||||
func (a *ApiRequestService) ProcessMobilelocalRequest(params []byte) ([]byte, error) {
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
if !mobile.Exists() {
|
||||
return nil, errors.New("api请求, mobilelocal, 获取相关参数失败")
|
||||
}
|
||||
|
||||
request := map[string]interface{}{
|
||||
"phone": mobile.String(),
|
||||
}
|
||||
|
||||
resp, err := a.tianjuService.Request("mobilelocal", request)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("手机归属地查询失败: %+v", err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// 身份证归属地查询
|
||||
func (a *ApiRequestService) ProcessSfzRequest(params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
if !idCard.Exists() {
|
||||
return nil, errors.New("api请求, sfz, 获取相关参数失败")
|
||||
}
|
||||
|
||||
request := map[string]interface{}{
|
||||
"idcard": idCard.String(),
|
||||
}
|
||||
|
||||
resp, err := a.tianjuService.Request("sfz", request)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("身份证归属地查询失败: %+v", err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
74
app/user/cmd/api/internal/service/tianjuService.go
Normal file
74
app/user/cmd/api/internal/service/tianjuService.go
Normal file
@ -0,0 +1,74 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"qnc-server/app/user/cmd/api/internal/config"
|
||||
"strings"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
type TianjuService struct {
|
||||
config config.TianjuConfig
|
||||
}
|
||||
|
||||
func NewTianjuService(c config.Config) *TianjuService {
|
||||
return &TianjuService{
|
||||
config: c.TianjuConfig,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TianjuService) Request(apiPath string, params map[string]interface{}) ([]byte, error) {
|
||||
// 确保params中包含key参数
|
||||
reqParams := make(map[string]interface{})
|
||||
|
||||
// 复制用户参数
|
||||
for k, v := range params {
|
||||
reqParams[k] = v
|
||||
}
|
||||
|
||||
// 如果未提供key,则使用配置中的ApiKey
|
||||
if _, ok := reqParams["key"]; !ok {
|
||||
reqParams["key"] = t.config.ApiKey
|
||||
}
|
||||
|
||||
// 构建完整的URL,假设BaseURL已包含https://前缀
|
||||
fullURL := fmt.Sprintf("%s/%s/index", strings.TrimRight(t.config.BaseURL, "/"), apiPath)
|
||||
|
||||
// 将请求数据转换为JSON
|
||||
messageBytes, err := json.Marshal(reqParams)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("参数序列化失败: %w", err)
|
||||
}
|
||||
|
||||
// 发起HTTP请求
|
||||
resp, err := http.Post(fullURL, "application/json", strings.NewReader(string(messageBytes)))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("发送请求失败: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// 读取响应体
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("读取响应失败: %w", err)
|
||||
}
|
||||
|
||||
// 检查响应状态码
|
||||
code := gjson.GetBytes(body, "code").Int()
|
||||
if code != 200 {
|
||||
msg := gjson.GetBytes(body, "msg").String()
|
||||
return nil, fmt.Errorf("天聚请求失败: 状态码 %d, 信息: %s", code, msg)
|
||||
}
|
||||
|
||||
// 获取结果数据
|
||||
result := gjson.GetBytes(body, "result")
|
||||
if !result.Exists() {
|
||||
return nil, fmt.Errorf("天聚请求result为空: %s", string(body))
|
||||
}
|
||||
|
||||
return []byte(result.Raw), nil
|
||||
}
|
@ -37,6 +37,7 @@ type ServiceContext struct {
|
||||
ApplePayService *service.ApplePayService
|
||||
WestDexService *service.WestDexService
|
||||
YushanService *service.YushanService
|
||||
TianjuService *service.TianjuService
|
||||
ApiRequestService *service.ApiRequestService
|
||||
AsynqServer *asynq.Server // 服务端
|
||||
AsynqService *service.AsynqService // 客户端
|
||||
@ -62,6 +63,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
)
|
||||
westDexService := service.NewWestDexService(c)
|
||||
yushanService := service.NewYushanService(c)
|
||||
tianjuService := service.NewTianjuService(c)
|
||||
productFeatureModel := model.NewProductFeatureModel(db, c.CacheRedis)
|
||||
featureModel := model.NewFeatureModel(db, c.CacheRedis)
|
||||
userAuthModel := model.NewUserAuthModel(db, c.CacheRedis)
|
||||
@ -74,9 +76,10 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
ApplePayService: service.NewApplePayService(c),
|
||||
WestDexService: westDexService,
|
||||
YushanService: yushanService,
|
||||
TianjuService: tianjuService,
|
||||
VerificationService: service.NewVerificationService(c, westDexService),
|
||||
AsynqServer: asynqServer,
|
||||
ApiRequestService: service.NewApiRequestService(c, westDexService, yushanService, featureModel, productFeatureModel),
|
||||
ApiRequestService: service.NewApiRequestService(c, westDexService, yushanService, tianjuService, featureModel, productFeatureModel),
|
||||
AsynqService: service.NewAsynqService(c),
|
||||
UserModel: model.NewUserModel(db, c.CacheRedis),
|
||||
UserAuthModel: userAuthModel,
|
||||
|
@ -177,3 +177,13 @@ type TocBankCardThreeElementsVerification struct {
|
||||
type TocMobileRiskAssessment struct {
|
||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||
}
|
||||
|
||||
// 手机归属地
|
||||
type TocMobileLocation struct {
|
||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||
}
|
||||
|
||||
// 身份证归属地
|
||||
type TocIDCardLocation struct {
|
||||
IDCard string `json:"id_card" validate:"required,idCard"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user