新版本,代理功能上线
This commit is contained in:
		| @@ -7,9 +7,12 @@ import ( | ||||
| 	"fmt" | ||||
| 	"github.com/pkg/errors" | ||||
| 	"github.com/zeromicro/go-zero/core/stores/redis" | ||||
| 	"github.com/zeromicro/go-zero/core/stores/sqlx" | ||||
| 	"time" | ||||
| 	"tydata-server/app/user/cmd/api/internal/service" | ||||
| 	"tydata-server/app/user/model" | ||||
| 	"tydata-server/common/ctxdata" | ||||
| 	jwtx "tydata-server/common/jwt" | ||||
| 	"tydata-server/common/xerr" | ||||
| 	"tydata-server/pkg/lzkit/crypto" | ||||
| 	"tydata-server/pkg/lzkit/validator" | ||||
| @@ -35,9 +38,32 @@ func NewQueryServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Quer | ||||
| } | ||||
|  | ||||
| func (l *QueryServiceLogic) QueryService(req *types.QueryServiceReq) (resp *types.QueryServiceResp, err error) { | ||||
| 	if req.AgentIdentifier != "" { | ||||
| 		l.ctx = context.WithValue(l.ctx, "agentIdentifier", req.AgentIdentifier) | ||||
| 		return l.PreprocessLogic(req, req.Product) | ||||
| 	} | ||||
| 	return l.PreprocessLogic(req, req.Product) | ||||
| } | ||||
|  | ||||
| //func (l *QueryServiceLogic) agentParsing(req *types.QueryServiceReq) (*types.AgentIdentifier, error) { | ||||
| //	key, decodeErr := hex.DecodeString("8e3e7a2f60edb49221e953b9c029ed10") | ||||
| //	if decodeErr != nil { | ||||
| //		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 获取AES密钥失败: %+v", decodeErr) | ||||
| //	} | ||||
| // | ||||
| //	encrypted, err := crypto.AesDecryptURL(req.Product, key) | ||||
| //	if err != nil { | ||||
| //		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, %v", err) | ||||
| //	} | ||||
| //	var agentIdentifier types.AgentIdentifier | ||||
| //	err = json.Unmarshal(encrypted, &agentIdentifier) | ||||
| //	if err != nil { | ||||
| //		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务,反序列化失败 %v", err) | ||||
| //	} | ||||
| //	l.ctx = context.WithValue(l.ctx, "agent", req.Agent) | ||||
| //	return &agentIdentifier, nil | ||||
| //} | ||||
|  | ||||
| var productProcessors = map[string]func(*QueryServiceLogic, *types.QueryServiceReq) (*types.QueryServiceResp, error){ | ||||
| 	"marriage":                        (*QueryServiceLogic).ProcessMarriageLogic, | ||||
| 	"homeservice":                     (*QueryServiceLogic).ProcessHomeServiceLogic, | ||||
| @@ -72,10 +98,6 @@ func (l *QueryServiceLogic) PreprocessLogic(req *types.QueryServiceReq, product | ||||
| 	return nil, errors.New("未找到相应的处理程序") | ||||
| } | ||||
| func (l *QueryServiceLogic) ProcessMarriageLogic(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) | ||||
| 	} | ||||
|  | ||||
| 	// AES解密 | ||||
| 	decryptData, DecryptDataErr := l.DecryptData(req.Data) | ||||
| @@ -111,21 +133,31 @@ func (l *QueryServiceLogic) ProcessMarriageLogic(req *types.QueryServiceReq) (*t | ||||
| 		"id_card": data.IDCard, | ||||
| 		"mobile":  data.Mobile, | ||||
| 	} | ||||
| 	userID, err := l.GetOrCreateUser(data.Mobile) | ||||
| 	if err != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %v", err) | ||||
| 	} | ||||
| 	cacheNo, cacheDataErr := l.CacheData(params, "marriage", userID) | ||||
| 	if cacheDataErr != nil { | ||||
| 		return nil, cacheDataErr | ||||
| 	} | ||||
| 	token, generaErr := jwtx.GenerateJwtToken(userID, l.svcCtx.Config.JwtAuth.AccessSecret, l.svcCtx.Config.JwtAuth.AccessExpire) | ||||
| 	if generaErr != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID) | ||||
| 	} | ||||
|  | ||||
| 	return &types.QueryServiceResp{Id: cacheNo}, nil | ||||
| 	// 获取当前时间戳 | ||||
| 	now := time.Now().Unix() | ||||
| 	return &types.QueryServiceResp{ | ||||
| 		Id:           cacheNo, | ||||
| 		AccessToken:  token, | ||||
| 		AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire, | ||||
| 		RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| // 处理家政服务相关逻辑 | ||||
|  | ||||
| func (l *QueryServiceLogic) ProcessHomeServiceLogic(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) | ||||
| 	} | ||||
|  | ||||
| 	// AES解密 | ||||
| 	decryptData, DecryptDataErr := l.DecryptData(req.Data) | ||||
| @@ -161,20 +193,32 @@ func (l *QueryServiceLogic) ProcessHomeServiceLogic(req *types.QueryServiceReq) | ||||
| 		"id_card": data.IDCard, | ||||
| 		"mobile":  data.Mobile, | ||||
| 	} | ||||
| 	userID, err := l.GetOrCreateUser(data.Mobile) | ||||
| 	if err != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %v", err) | ||||
| 	} | ||||
| 	cacheNo, cacheDataErr := l.CacheData(params, "homeservice", userID) | ||||
| 	if cacheDataErr != nil { | ||||
| 		return nil, cacheDataErr | ||||
| 	} | ||||
|  | ||||
| 	return &types.QueryServiceResp{Id: cacheNo}, nil | ||||
| 	token, generaErr := jwtx.GenerateJwtToken(userID, l.svcCtx.Config.JwtAuth.AccessSecret, l.svcCtx.Config.JwtAuth.AccessExpire) | ||||
| 	if generaErr != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID) | ||||
| 	} | ||||
|  | ||||
| 	// 获取当前时间戳 | ||||
| 	now := time.Now().Unix() | ||||
| 	return &types.QueryServiceResp{ | ||||
| 		Id:           cacheNo, | ||||
| 		AccessToken:  token, | ||||
| 		AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire, | ||||
| 		RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| // 处理风险评估相关逻辑 | ||||
| func (l *QueryServiceLogic) ProcessRiskAssessmentLogic(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) | ||||
| 	} | ||||
|  | ||||
| 	// AES解密 | ||||
| 	decryptData, DecryptDataErr := l.DecryptData(req.Data) | ||||
| @@ -210,21 +254,32 @@ func (l *QueryServiceLogic) ProcessRiskAssessmentLogic(req *types.QueryServiceRe | ||||
| 		"id_card": data.IDCard, | ||||
| 		"mobile":  data.Mobile, | ||||
| 	} | ||||
| 	userID, err := l.GetOrCreateUser(data.Mobile) | ||||
| 	if err != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %v", err) | ||||
| 	} | ||||
| 	cacheNo, cacheDataErr := l.CacheData(params, "riskassessment", userID) | ||||
| 	if cacheDataErr != nil { | ||||
| 		return nil, cacheDataErr | ||||
| 	} | ||||
|  | ||||
| 	return &types.QueryServiceResp{Id: cacheNo}, nil | ||||
| 	token, generaErr := jwtx.GenerateJwtToken(userID, l.svcCtx.Config.JwtAuth.AccessSecret, l.svcCtx.Config.JwtAuth.AccessExpire) | ||||
| 	if generaErr != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID) | ||||
| 	} | ||||
|  | ||||
| 	// 获取当前时间戳 | ||||
| 	now := time.Now().Unix() | ||||
| 	return &types.QueryServiceResp{ | ||||
| 		Id:           cacheNo, | ||||
| 		AccessToken:  token, | ||||
| 		AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire, | ||||
| 		RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| // 处理公司信息查询相关逻辑 | ||||
| func (l *QueryServiceLogic) ProcessCompanyInfoLogic(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) | ||||
| 	} | ||||
|  | ||||
| 	// AES解密 | ||||
| 	decryptData, DecryptDataErr := l.DecryptData(req.Data) | ||||
| 	if DecryptDataErr != nil { | ||||
| @@ -259,20 +314,32 @@ func (l *QueryServiceLogic) ProcessCompanyInfoLogic(req *types.QueryServiceReq) | ||||
| 		"id_card": data.IDCard, | ||||
| 		"mobile":  data.Mobile, | ||||
| 	} | ||||
| 	userID, err := l.GetOrCreateUser(data.Mobile) | ||||
| 	if err != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %v", err) | ||||
| 	} | ||||
| 	cacheNo, cacheDataErr := l.CacheData(params, "companyinfo", userID) | ||||
| 	if cacheDataErr != nil { | ||||
| 		return nil, cacheDataErr | ||||
| 	} | ||||
|  | ||||
| 	return &types.QueryServiceResp{Id: cacheNo}, nil | ||||
| 	token, generaErr := jwtx.GenerateJwtToken(userID, l.svcCtx.Config.JwtAuth.AccessSecret, l.svcCtx.Config.JwtAuth.AccessExpire) | ||||
| 	if generaErr != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID) | ||||
| 	} | ||||
|  | ||||
| 	// 获取当前时间戳 | ||||
| 	now := time.Now().Unix() | ||||
| 	return &types.QueryServiceResp{ | ||||
| 		Id:           cacheNo, | ||||
| 		AccessToken:  token, | ||||
| 		AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire, | ||||
| 		RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| // 处理租赁信息查询相关逻辑 | ||||
| func (l *QueryServiceLogic) ProcessRentalInfoLogic(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) | ||||
| 	} | ||||
|  | ||||
| 	// AES解密 | ||||
| 	decryptData, DecryptDataErr := l.DecryptData(req.Data) | ||||
| @@ -308,20 +375,32 @@ func (l *QueryServiceLogic) ProcessRentalInfoLogic(req *types.QueryServiceReq) ( | ||||
| 		"id_card": data.IDCard, | ||||
| 		"mobile":  data.Mobile, | ||||
| 	} | ||||
| 	userID, err := l.GetOrCreateUser(data.Mobile) | ||||
| 	if err != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %v", err) | ||||
| 	} | ||||
| 	cacheNo, cacheDataErr := l.CacheData(params, "rentalinfo", userID) | ||||
| 	if cacheDataErr != nil { | ||||
| 		return nil, cacheDataErr | ||||
| 	} | ||||
|  | ||||
| 	return &types.QueryServiceResp{Id: cacheNo}, nil | ||||
| 	token, generaErr := jwtx.GenerateJwtToken(userID, l.svcCtx.Config.JwtAuth.AccessSecret, l.svcCtx.Config.JwtAuth.AccessExpire) | ||||
| 	if generaErr != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID) | ||||
| 	} | ||||
|  | ||||
| 	// 获取当前时间戳 | ||||
| 	now := time.Now().Unix() | ||||
| 	return &types.QueryServiceResp{ | ||||
| 		Id:           cacheNo, | ||||
| 		AccessToken:  token, | ||||
| 		AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire, | ||||
| 		RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| // 处理贷前背景检查相关逻辑 | ||||
| func (l *QueryServiceLogic) ProcessPreLoanBackgroundCheckLogic(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) | ||||
| 	} | ||||
|  | ||||
| 	// AES解密 | ||||
| 	decryptData, DecryptDataErr := l.DecryptData(req.Data) | ||||
| @@ -357,21 +436,32 @@ func (l *QueryServiceLogic) ProcessPreLoanBackgroundCheckLogic(req *types.QueryS | ||||
| 		"id_card": data.IDCard, | ||||
| 		"mobile":  data.Mobile, | ||||
| 	} | ||||
| 	userID, err := l.GetOrCreateUser(data.Mobile) | ||||
| 	if err != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %v", err) | ||||
| 	} | ||||
| 	cacheNo, cacheDataErr := l.CacheData(params, "preloanbackgroundcheck", userID) | ||||
| 	if cacheDataErr != nil { | ||||
| 		return nil, cacheDataErr | ||||
| 	} | ||||
|  | ||||
| 	return &types.QueryServiceResp{Id: cacheNo}, nil | ||||
| 	token, generaErr := jwtx.GenerateJwtToken(userID, l.svcCtx.Config.JwtAuth.AccessSecret, l.svcCtx.Config.JwtAuth.AccessExpire) | ||||
| 	if generaErr != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID) | ||||
| 	} | ||||
|  | ||||
| 	// 获取当前时间戳 | ||||
| 	now := time.Now().Unix() | ||||
| 	return &types.QueryServiceResp{ | ||||
| 		Id:           cacheNo, | ||||
| 		AccessToken:  token, | ||||
| 		AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire, | ||||
| 		RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| // 处理人事背调相关逻辑 | ||||
| func (l *QueryServiceLogic) ProcessBackgroundCheckLogic(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) | ||||
| 	} | ||||
|  | ||||
| 	// AES解密 | ||||
| 	decryptData, DecryptDataErr := l.DecryptData(req.Data) | ||||
| 	if DecryptDataErr != nil { | ||||
| @@ -389,16 +479,16 @@ func (l *QueryServiceLogic) ProcessBackgroundCheckLogic(req *types.QueryServiceR | ||||
| 	} | ||||
|  | ||||
| 	// 校验验证码 | ||||
| 	verifyCodeErr := l.VerifyCode(data.Mobile, data.Code) | ||||
| 	if verifyCodeErr != nil { | ||||
| 		return nil, verifyCodeErr | ||||
| 	} | ||||
|  | ||||
| 	// 校验三要素 | ||||
| 	verifyErr := l.Verify(data.Name, data.IDCard, data.Mobile) | ||||
| 	if verifyErr != nil { | ||||
| 		return nil, verifyErr | ||||
| 	} | ||||
| 	//verifyCodeErr := l.VerifyCode(data.Mobile, data.Code) | ||||
| 	//if verifyCodeErr != nil { | ||||
| 	//	return nil, verifyCodeErr | ||||
| 	//} | ||||
| 	// | ||||
| 	//// 校验三要素 | ||||
| 	//verifyErr := l.Verify(data.Name, data.IDCard, data.Mobile) | ||||
| 	//if verifyErr != nil { | ||||
| 	//	return nil, verifyErr | ||||
| 	//} | ||||
|  | ||||
| 	// 缓存 | ||||
| 	params := map[string]interface{}{ | ||||
| @@ -406,12 +496,28 @@ func (l *QueryServiceLogic) ProcessBackgroundCheckLogic(req *types.QueryServiceR | ||||
| 		"id_card": data.IDCard, | ||||
| 		"mobile":  data.Mobile, | ||||
| 	} | ||||
| 	userID, err := l.GetOrCreateUser(data.Mobile) | ||||
| 	if err != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %v", err) | ||||
| 	} | ||||
| 	cacheNo, cacheDataErr := l.CacheData(params, "backgroundcheck", userID) | ||||
| 	if cacheDataErr != nil { | ||||
| 		return nil, cacheDataErr | ||||
| 	} | ||||
|  | ||||
| 	return &types.QueryServiceResp{Id: cacheNo}, nil | ||||
| 	token, generaErr := jwtx.GenerateJwtToken(userID, l.svcCtx.Config.JwtAuth.AccessSecret, l.svcCtx.Config.JwtAuth.AccessExpire) | ||||
| 	if generaErr != nil { | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID) | ||||
| 	} | ||||
|  | ||||
| 	// 获取当前时间戳 | ||||
| 	now := time.Now().Unix() | ||||
| 	return &types.QueryServiceResp{ | ||||
| 		Id:           cacheNo, | ||||
| 		AccessToken:  token, | ||||
| 		AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire, | ||||
| 		RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| func (l *QueryServiceLogic) ProcessTocMarriageLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) { | ||||
| @@ -652,7 +758,7 @@ func (l *QueryServiceLogic) ProcessTocPhoneThreeElementsLogic(req *types.QuerySe | ||||
| 	// AES解密 | ||||
| 	decryptData, DecryptDataErr := l.DecryptData(req.Data) | ||||
| 	if DecryptDataErr != nil { | ||||
| 		return nil, DecryptDataErr | ||||
| 		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后失败: %+v", DecryptDataErr) | ||||
| 	} | ||||
|  | ||||
| 	// 校验参数 | ||||
| @@ -1096,7 +1202,23 @@ 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.ThreeVerify { | ||||
| 	agent, ok := l.ctx.Value("agent").(bool) | ||||
| 	if !ok { | ||||
| 		agent = false | ||||
| 	} | ||||
| 	if !l.svcCtx.Config.SystemConfig.ThreeVerify || agent { | ||||
| 		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) | ||||
| 		} | ||||
| 	} else { | ||||
| 		// 三要素验证 | ||||
| 		threeVerification := service.ThreeFactorVerificationRequest{ | ||||
| 			Name:   Name, | ||||
| @@ -1105,22 +1227,10 @@ func (l *QueryServiceLogic) Verify(Name string, IDCard string, Mobile string) er | ||||
| 		} | ||||
| 		verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification) | ||||
| 		if err != nil { | ||||
| 			return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "三要素验证失败: %+v", err) | ||||
| 			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 errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "三要素验证不通过: %v", err) | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| @@ -1128,9 +1238,11 @@ func (l *QueryServiceLogic) Verify(Name string, IDCard string, Mobile string) er | ||||
|  | ||||
| // 缓存 | ||||
| func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product string, userID int64) (string, error) { | ||||
| 	agentIdentifier, _ := l.ctx.Value("agentIdentifier").(string) | ||||
| 	queryCache := types.QueryCacheLoad{ | ||||
| 		Params:  params, | ||||
| 		Product: Product, | ||||
| 		Params:          params, | ||||
| 		Product:         Product, | ||||
| 		AgentIdentifier: agentIdentifier, | ||||
| 	} | ||||
| 	jsonData, marshalErr := json.Marshal(queryCache) | ||||
| 	if marshalErr != nil { | ||||
| @@ -1144,3 +1256,51 @@ func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product str | ||||
| 	} | ||||
| 	return outTradeNo, nil | ||||
| } | ||||
|  | ||||
| func (l *QueryServiceLogic) GetOrCreateUser(mobile string) (int64, error) { | ||||
| 	agentIdentifier, ok := l.ctx.Value("agentIdentifier").(string) | ||||
| 	if !ok || agentIdentifier == "" { | ||||
| 		// 不是代理查询 | ||||
| 		userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx) | ||||
| 		if getUidErr != nil { | ||||
| 			return 0, getUidErr | ||||
| 		} | ||||
| 		return userID, nil | ||||
| 	} | ||||
|  | ||||
| 	userModel, err := l.svcCtx.UserModel.FindOneByMobile(l.ctx, mobile) | ||||
| 	if err != nil && !errors.Is(err, model.ErrNotFound) { | ||||
| 		return 0, err | ||||
| 	} | ||||
| 	// 没有则创建账号 | ||||
| 	if userModel == nil { | ||||
| 		userModel = &model.User{Mobile: mobile} | ||||
| 		if len(userModel.Nickname) == 0 { | ||||
| 			userModel.Nickname = mobile | ||||
| 		} | ||||
| 		if transErr := l.svcCtx.UserModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error { | ||||
| 			insertResult, userInsertErr := l.svcCtx.UserModel.Insert(ctx, session, userModel) | ||||
| 			if userInsertErr != nil { | ||||
| 				return userInsertErr | ||||
| 			} | ||||
| 			lastId, lastInsertIdErr := insertResult.LastInsertId() | ||||
| 			if lastInsertIdErr != nil { | ||||
| 				return lastInsertIdErr | ||||
| 			} | ||||
| 			userModel.Id = lastId | ||||
|  | ||||
| 			userAuth := new(model.UserAuth) | ||||
| 			userAuth.UserId = lastId | ||||
| 			userAuth.AuthKey = mobile | ||||
| 			userAuth.AuthType = model.UserAuthTypeAgentPromote | ||||
| 			if _, userAuthInsertErr := l.svcCtx.UserAuthModel.Insert(ctx, session, userAuth); userAuthInsertErr != nil { | ||||
| 				return userAuthInsertErr | ||||
| 			} | ||||
|  | ||||
| 			return nil | ||||
| 		}); transErr != nil { | ||||
| 			return 0, transErr | ||||
| 		} | ||||
| 	} | ||||
| 	return userModel.Id, nil | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user