From f13dcda37074ddbde81d4a3cd113484523a1395e Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Mon, 25 Nov 2024 00:25:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(user):=20=E6=96=B0=E5=A2=9E=E4=B8=89?= =?UTF-8?q?=E8=A6=81=E7=B4=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/query/backgroundchecklogic.go | 21 ++++-- .../internal/logic/query/companyinfologic.go | 20 ++++-- .../internal/logic/query/homeservicelogic.go | 21 ++++-- .../api/internal/logic/query/marriagelogic.go | 21 ++++-- .../query/preloanbackgroundchecklogic.go | 20 ++++-- .../internal/logic/query/rentalinfologic.go | 20 ++++-- .../logic/query/riskassessmentlogic.go | 20 ++++-- .../internal/service/verificationService.go | 65 ++++++++++++++++++- .../cmd/api/internal/svc/servicecontext.go | 5 +- 9 files changed, 178 insertions(+), 35 deletions(-) diff --git a/app/user/cmd/api/internal/logic/query/backgroundchecklogic.go b/app/user/cmd/api/internal/logic/query/backgroundchecklogic.go index 2f82fd4..7a2ce0d 100644 --- a/app/user/cmd/api/internal/logic/query/backgroundchecklogic.go +++ b/app/user/cmd/api/internal/logic/query/backgroundchecklogic.go @@ -74,18 +74,29 @@ func (l *BackgroundCheckLogic) BackgroundCheck(req *types.QueryReq) (resp *types } // 3、二要素三要素核验 - twoVerification := service.TwoFactorVerificationRequest{ + //twoVerification := service.TwoFactorVerificationRequest{ + // Name: data.Name, + // IDCard: data.IDCard, + //} + //verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + //if err != nil { + // return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "人事背调, 二要素验证失败: %+v", err) + //} + //if !verification.Passed { + // return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "人事背调, 二要素验证不通过: %+v", err) + //} + // 3、二要素三要素核验 + threeVerification := service.ThreeFactorVerificationRequest{ Name: data.Name, IDCard: data.IDCard, } - verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification) if err != nil { - return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "人事背调, 二要素验证失败: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "人事背调, 三要素验证失败: %+v", err) } if !verification.Passed { - return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "人事背调, 二要素验证不通过: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "人事背调, 三要素验证不通过: %+v", err) } - // 缓存 queryCache := types.QueryCache{ Name: data.Name, diff --git a/app/user/cmd/api/internal/logic/query/companyinfologic.go b/app/user/cmd/api/internal/logic/query/companyinfologic.go index a939d59..3497ee2 100644 --- a/app/user/cmd/api/internal/logic/query/companyinfologic.go +++ b/app/user/cmd/api/internal/logic/query/companyinfologic.go @@ -74,16 +74,28 @@ func (l *CompanyInfoLogic) CompanyInfo(req *types.QueryReq) (resp *types.QueryRe } // 3、二要素三要素核验 - twoVerification := service.TwoFactorVerificationRequest{ + //twoVerification := service.TwoFactorVerificationRequest{ + // Name: data.Name, + // IDCard: data.IDCard, + //} + //verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + //if err != nil { + // return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "企业报告, 二要素验证失败: %+v", err) + //} + //if !verification.Passed { + // return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "企业报告, 二要素验证不通过: %+v", err) + //} + // 3、二要素三要素核验 + threeVerification := service.ThreeFactorVerificationRequest{ Name: data.Name, IDCard: data.IDCard, } - verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification) if err != nil { - return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "企业报告, 二要素验证失败: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "企业报告, 三要素验证失败: %+v", err) } if !verification.Passed { - return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "企业报告, 二要素验证不通过: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "企业报告, 三要素验证不通过: %+v", err) } // 缓存 queryCache := types.QueryCache{ diff --git a/app/user/cmd/api/internal/logic/query/homeservicelogic.go b/app/user/cmd/api/internal/logic/query/homeservicelogic.go index 4986c3a..d967a97 100644 --- a/app/user/cmd/api/internal/logic/query/homeservicelogic.go +++ b/app/user/cmd/api/internal/logic/query/homeservicelogic.go @@ -74,17 +74,30 @@ func (l *HomeServiceLogic) HomeService(req *types.QueryReq) (resp *types.QueryRe } // 3、二要素三要素核验 - twoVerification := service.TwoFactorVerificationRequest{ + //twoVerification := service.TwoFactorVerificationRequest{ + // Name: data.Name, + // IDCard: data.IDCard, + //} + //verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + //if err != nil { + // return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "家政服务, 二要素验证失败: %+v", err) + //} + //if !verification.Passed { + // return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "家政服务, 二要素验证不通过: %+v", err) + //} + // 3、二要素三要素核验 + threeVerification := service.ThreeFactorVerificationRequest{ Name: data.Name, IDCard: data.IDCard, } - verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification) if err != nil { - return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "家政服务, 二要素验证失败: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "家政服务, 三要素验证失败: %+v", err) } if !verification.Passed { - return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "家政服务, 二要素验证不通过: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "家政服务, 三要素验证不通过: %+v", err) } + // 缓存 queryCache := types.QueryCache{ Name: data.Name, diff --git a/app/user/cmd/api/internal/logic/query/marriagelogic.go b/app/user/cmd/api/internal/logic/query/marriagelogic.go index ed2ca0f..76f1508 100644 --- a/app/user/cmd/api/internal/logic/query/marriagelogic.go +++ b/app/user/cmd/api/internal/logic/query/marriagelogic.go @@ -73,19 +73,30 @@ func (l *MarriageLogic) Marriage(req *types.QueryReq) (resp *types.QueryResp, er return nil, errors.Wrapf(xerr.NewErrMsg("验证码不正确"), "婚恋评估, 验证码不正确: %s", data.Mobile) } + //// 3、二要素三要素核验 + //twoVerification := service.TwoFactorVerificationRequest{ + // Name: data.Name, + // IDCard: data.IDCard, + //} + //verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + //if err != nil { + // return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "婚恋评估, 二要素验证失败: %+v", err) + //} + //if !verification.Passed { + // return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "婚恋评估, 二要素验证不通过: %+v", err) + //} // 3、二要素三要素核验 - twoVerification := service.TwoFactorVerificationRequest{ + threeVerification := service.ThreeFactorVerificationRequest{ Name: data.Name, IDCard: data.IDCard, } - verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification) if err != nil { - return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "婚恋评估, 二要素验证失败: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "婚恋评估, 三要素验证失败: %+v", err) } if !verification.Passed { - return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "婚恋评估, 二要素验证不通过: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "婚恋评估, 三要素验证不通过: %+v", err) } - // 缓存 queryCache := types.QueryCache{ Name: data.Name, diff --git a/app/user/cmd/api/internal/logic/query/preloanbackgroundchecklogic.go b/app/user/cmd/api/internal/logic/query/preloanbackgroundchecklogic.go index a60c4dd..1214d83 100644 --- a/app/user/cmd/api/internal/logic/query/preloanbackgroundchecklogic.go +++ b/app/user/cmd/api/internal/logic/query/preloanbackgroundchecklogic.go @@ -74,16 +74,28 @@ func (l *PreLoanBackgroundCheckLogic) PreLoanBackgroundCheck(req *types.QueryReq } // 3、二要素三要素核验 - twoVerification := service.TwoFactorVerificationRequest{ + //twoVerification := service.TwoFactorVerificationRequest{ + // Name: data.Name, + // IDCard: data.IDCard, + //} + //verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + //if err != nil { + // return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "贷前背调, 二要素验证失败: %+v", err) + //} + //if !verification.Passed { + // return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "贷前背调, 二要素验证不通过: %+v", err) + //} + // 3、二要素三要素核验 + threeVerification := service.ThreeFactorVerificationRequest{ Name: data.Name, IDCard: data.IDCard, } - verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification) if err != nil { - return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "贷前背调, 二要素验证失败: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "贷前背调, 三要素验证失败: %+v", err) } if !verification.Passed { - return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "贷前背调, 二要素验证不通过: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "贷前背调, 三要素验证不通过: %+v", err) } // 缓存 queryCache := types.QueryCache{ diff --git a/app/user/cmd/api/internal/logic/query/rentalinfologic.go b/app/user/cmd/api/internal/logic/query/rentalinfologic.go index 6c1260b..47426b8 100644 --- a/app/user/cmd/api/internal/logic/query/rentalinfologic.go +++ b/app/user/cmd/api/internal/logic/query/rentalinfologic.go @@ -74,16 +74,28 @@ func (l *RentalInfoLogic) RentalInfo(req *types.QueryReq) (resp *types.QueryResp } // 3、二要素三要素核验 - twoVerification := service.TwoFactorVerificationRequest{ + //twoVerification := service.TwoFactorVerificationRequest{ + // Name: data.Name, + // IDCard: data.IDCard, + //} + //verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + //if err != nil { + // return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "租赁服务, 二要素验证失败: %+v", err) + //} + //if !verification.Passed { + // return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "租赁服务, 二要素验证不通过: %+v", err) + //} + // 3、二要素三要素核验 + threeVerification := service.ThreeFactorVerificationRequest{ Name: data.Name, IDCard: data.IDCard, } - verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification) if err != nil { - return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "租赁服务, 二要素验证失败: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "租赁服务, 三要素验证失败: %+v", err) } if !verification.Passed { - return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "租赁服务, 二要素验证不通过: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "租赁服务, 三要素验证不通过: %+v", err) } // 缓存 queryCache := types.QueryCache{ diff --git a/app/user/cmd/api/internal/logic/query/riskassessmentlogic.go b/app/user/cmd/api/internal/logic/query/riskassessmentlogic.go index 28a043f..642a69d 100644 --- a/app/user/cmd/api/internal/logic/query/riskassessmentlogic.go +++ b/app/user/cmd/api/internal/logic/query/riskassessmentlogic.go @@ -74,16 +74,28 @@ func (l *RiskAssessmentLogic) RiskAssessment(req *types.QueryReq) (resp *types.Q } // 3、二要素三要素核验 - twoVerification := service.TwoFactorVerificationRequest{ + //twoVerification := service.TwoFactorVerificationRequest{ + // Name: data.Name, + // IDCard: data.IDCard, + //} + //verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + //if err != nil { + // return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "个人风险, 二要素验证失败: %+v", err) + //} + //if !verification.Passed { + // return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "个人风险, 二要素验证不通过: %+v", err) + //} + // 3、二要素三要素核验 + threeVerification := service.ThreeFactorVerificationRequest{ Name: data.Name, IDCard: data.IDCard, } - verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification) + verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification) if err != nil { - return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "个人风险, 二要素验证失败: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "个人风险, 三要素验证失败: %+v", err) } if !verification.Passed { - return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "个人风险, 二要素验证不通过: %+v", err) + return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "个人风险, 三要素验证不通过: %+v", err) } // 缓存 queryCache := types.QueryCache{ diff --git a/app/user/cmd/api/internal/service/verificationService.go b/app/user/cmd/api/internal/service/verificationService.go index bebeeb9..c79f5d4 100644 --- a/app/user/cmd/api/internal/service/verificationService.go +++ b/app/user/cmd/api/internal/service/verificationService.go @@ -3,6 +3,7 @@ package service import ( "encoding/json" "fmt" + "github.com/tidwall/gjson" "io" "net/http" "net/url" @@ -11,15 +12,18 @@ import ( ) type VerificationService struct { - c config.Config + c config.Config + westDexService *WestDexService } -func NewVerificationService(c config.Config) *VerificationService { +func NewVerificationService(c config.Config, westDexService *WestDexService) *VerificationService { return &VerificationService{ - c: c, + c: c, + westDexService: westDexService, } } +// 二要素 type TwoFactorVerificationRequest struct { Name string IDCard string @@ -39,6 +43,13 @@ type TwoFactorVerificationData struct { Desc string `json:"desc"` } +// 三要素 +type ThreeFactorVerificationRequest struct { + Name string + IDCard string + Mobile string +} + // VerificationResult 定义校验结果结构体 type VerificationResult struct { Passed bool @@ -114,3 +125,51 @@ func (r *VerificationService) TwoFactorVerification(request TwoFactorVerificatio return &VerificationResult{Passed: true, Err: nil}, nil } +func (r *VerificationService) ThreeFactorVerification(request ThreeFactorVerificationRequest) (*VerificationResult, error) { + threeElementsReq := map[string]interface{}{ + "name": request.Name, + "idNo": request.IDCard, + "phone": request.Mobile, + } + + resp, err := r.westDexService.CallAPI("G15BJ02", threeElementsReq) + if err != nil { + return nil, err + } + dataResult := gjson.GetBytes(resp, "data.code") + if !dataResult.Exists() { + return nil, fmt.Errorf("code 字段不存在") + } + code := dataResult.Int() + switch code { + case 1000: + case 1002: + return &VerificationResult{ + Passed: false, + Err: &ValidationError{Message: "姓名、证件号、手机号信息不一致"}, + }, nil + case 1003: + return &VerificationResult{ + Passed: false, + Err: &ValidationError{Message: "姓名、证件号、手机号信息不一致"}, + }, nil + case 1004: + return &VerificationResult{ + Passed: false, + Err: &ValidationError{Message: "姓名不正确"}, + }, nil + case 1005: + return &VerificationResult{ + Passed: false, + Err: &ValidationError{Message: "证件号码不正确"}, + }, nil + default: + dataResultMsg := gjson.GetBytes(resp, "data.msg") + if !dataResultMsg.Exists() { + return nil, fmt.Errorf("msg字段不存在") + } + return nil, fmt.Errorf("三要素核验错误状态响应: %s", dataResultMsg.String()) + } + + return &VerificationResult{Passed: true, Err: nil}, nil +} diff --git a/app/user/cmd/api/internal/svc/servicecontext.go b/app/user/cmd/api/internal/svc/servicecontext.go index 9d5d2cc..453fd6a 100644 --- a/app/user/cmd/api/internal/svc/servicecontext.go +++ b/app/user/cmd/api/internal/svc/servicecontext.go @@ -45,13 +45,14 @@ func NewServiceContext(c config.Config) *ServiceContext { Concurrency: 10, }, ) + westDexService := service.NewWestDexService(c) return &ServiceContext{ Config: c, Redis: redis.MustNewRedis(redisConf), AlipayService: service.NewAliPayService(c), WechatPayService: service.NewWechatPayService(c), - WestDexService: service.NewWestDexService(c), - VerificationService: service.NewVerificationService(c), + WestDexService: westDexService, + VerificationService: service.NewVerificationService(c, westDexService), AsynqServer: asynqServer, AsynqService: service.NewAsynqService(c), UserModel: model.NewUserModel(db, c.CacheRedis),