change tow verifucation
This commit is contained in:
parent
7c590a206a
commit
b60f6ffb3e
@ -89,7 +89,7 @@ func (l *QueryServiceLogic) VerifyTwoFactors(Name string, IDCard string) error {
|
||||
Name: Name,
|
||||
IDCard: IDCard,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification)
|
||||
verification, err := l.svcCtx.VerificationService.TwoFactorVerificationWest(l.ctx, twoVerification)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "二要素验证失败: %+v", err)
|
||||
}
|
||||
|
@ -233,6 +233,7 @@ var requestProcessors = map[string]func(*ApiRequestService, context.Context, []b
|
||||
"mobilelocal": (*ApiRequestService).ProcessMobilelocalRequest, // 手机归属地
|
||||
"sfz": (*ApiRequestService).ProcessSfzRequest, // 身份证归属地
|
||||
"IDV044": (*ApiRequestService).ProcessIDV044Request,
|
||||
"layoutIdcard": (*ApiRequestService).ProcessLayoutIdcardRequest,
|
||||
|
||||
// New Feature
|
||||
"PersonEnterprisePro": (*ApiRequestService).ProcessPersonEnterpriseProRequest,
|
||||
@ -1779,6 +1780,48 @@ func (a *ApiRequestService) ProcessIDV044Request(ctx context.Context, params []b
|
||||
}, nil
|
||||
}
|
||||
|
||||
// layoutIdcard 西部二要素
|
||||
func (a *ApiRequestService) ProcessLayoutIdcardRequest(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
|
||||
if !name.Exists() || !idCard.Exists() {
|
||||
return nil, errors.New("api请求, layoutIdcard, 获取相关参数失败")
|
||||
}
|
||||
|
||||
request := map[string]interface{}{
|
||||
"data": map[string]interface{}{
|
||||
"xM": a.westDexService.Encrypt(name.String()),
|
||||
"gMSFZHM": a.westDexService.Encrypt(idCard.String()),
|
||||
"customerNumber": a.config.WestConfig.SecretId,
|
||||
"timeStamp": fmt.Sprintf("%d", time.Now().UnixNano()/int64(time.Millisecond)),
|
||||
},
|
||||
}
|
||||
resp, callApiErr := a.westDexService.CallAPI("layoutIdcard", request)
|
||||
if callApiErr != nil {
|
||||
return nil, callApiErr
|
||||
}
|
||||
// 使用gjson获取resultCode
|
||||
resultCode := gjson.GetBytes(resp, "ctidRequest.ctidAuth.resultCode")
|
||||
if !resultCode.Exists() {
|
||||
return nil, errors.New("获取resultCode失败")
|
||||
}
|
||||
|
||||
// 获取resultCode的第一个字符
|
||||
resultCodeStr := resultCode.String()
|
||||
if len(resultCodeStr) == 0 {
|
||||
return nil, errors.New("resultCode为空")
|
||||
}
|
||||
|
||||
firstChar := string(resultCodeStr[0])
|
||||
if firstChar != "0" && firstChar != "5" {
|
||||
return nil, errors.New("resultCode的第一个字符既不是0也不是5")
|
||||
}
|
||||
return &APIInternalResult{
|
||||
Data: []byte(firstChar),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// PersonEnterprisePro 人企业关系加强版
|
||||
func (a *ApiRequestService) ProcessPersonEnterpriseProRequest(ctx context.Context, params []byte) (*APIInternalResult, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
|
@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -16,12 +17,14 @@ import (
|
||||
type VerificationService struct {
|
||||
c config.Config
|
||||
westDexService *WestDexService
|
||||
apiRequestService *ApiRequestService
|
||||
}
|
||||
|
||||
func NewVerificationService(c config.Config, westDexService *WestDexService) *VerificationService {
|
||||
func NewVerificationService(c config.Config, westDexService *WestDexService, apiRequestService *ApiRequestService) *VerificationService {
|
||||
return &VerificationService{
|
||||
c: c,
|
||||
westDexService: westDexService,
|
||||
apiRequestService: apiRequestService,
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,6 +130,31 @@ func (r *VerificationService) TwoFactorVerification(request TwoFactorVerificatio
|
||||
|
||||
return &VerificationResult{Passed: true, Err: nil}, nil
|
||||
}
|
||||
func (r *VerificationService) TwoFactorVerificationWest(ctx context.Context, request TwoFactorVerificationRequest) (*VerificationResult, error) {
|
||||
|
||||
params := map[string]interface{}{
|
||||
"name": request.Name,
|
||||
"id_card": request.IDCard,
|
||||
}
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("二要素参数创建错误: %v", err)
|
||||
}
|
||||
resp, err := r.apiRequestService.ProcessLayoutIdcardRequest(ctx, marshal)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求失败: %v", err)
|
||||
}
|
||||
|
||||
respStr := string(resp.Data)
|
||||
if respStr != "0" {
|
||||
return &VerificationResult{
|
||||
Passed: false,
|
||||
Err: &ValidationError{Message: "姓名与身份证不一致"},
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &VerificationResult{Passed: true, Err: nil}, nil
|
||||
}
|
||||
func (r *VerificationService) ThreeFactorVerification(request ThreeFactorVerificationRequest) (*VerificationResult, error) {
|
||||
westName, err := crypto.WestDexEncrypt(request.Name, r.c.WestConfig.Key)
|
||||
if err != nil {
|
||||
|
@ -91,7 +91,7 @@ func (w *WestDexService) CallAPI(code string, reqData map[string]interface{}) (r
|
||||
if UnmarshalErr != nil {
|
||||
return nil, UnmarshalErr
|
||||
}
|
||||
if westDexResp.Code != "00000" {
|
||||
if westDexResp.Code != "00000" && westDexResp.Code != "0" {
|
||||
if westDexResp.Data == "" {
|
||||
return nil, errors.New(westDexResp.Message)
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
productFeatureModel := model.NewProductFeatureModel(db, c.CacheRedis)
|
||||
featureModel := model.NewFeatureModel(db, c.CacheRedis)
|
||||
userAuthModel := model.NewUserAuthModel(db, c.CacheRedis)
|
||||
apiRequestService := service.NewApiRequestService(c, westDexService, yushanService, tianjuService, featureModel, productFeatureModel)
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
Redis: redis.MustNewRedis(redisConf),
|
||||
@ -73,9 +75,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
WestDexService: westDexService,
|
||||
YushanService: yushanService,
|
||||
TianjuService: tianjuService,
|
||||
VerificationService: service.NewVerificationService(c, westDexService),
|
||||
VerificationService: service.NewVerificationService(c, westDexService, apiRequestService),
|
||||
AsynqServer: asynqServer,
|
||||
ApiRequestService: service.NewApiRequestService(c, westDexService, yushanService, tianjuService, featureModel, productFeatureModel),
|
||||
ApiRequestService: apiRequestService,
|
||||
AsynqService: service.NewAsynqService(c),
|
||||
UserModel: model.NewUserModel(db, c.CacheRedis),
|
||||
UserAuthModel: userAuthModel,
|
||||
|
Loading…
Reference in New Issue
Block a user