feat(main): add agent
This commit is contained in:
52
app/user/cmd/api/internal/logic/agent/applyforagentlogic.go
Normal file
52
app/user/cmd/api/internal/logic/agent/applyforagentlogic.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
"qnc-server/app/user/model"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/lzUtils"
|
||||
"time"
|
||||
|
||||
"qnc-server/app/user/cmd/api/internal/svc"
|
||||
"qnc-server/app/user/cmd/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ApplyForAgentLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewApplyForAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplyForAgentLogic {
|
||||
return &ApplyForAgentLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ApplyForAgentLogic) ApplyForAgent(req *types.AgentApplyReq) (resp *types.AgentApplyResp, err error) {
|
||||
var agentAudit model.AgentAudit
|
||||
agentAudit.Mobile = req.Mobile
|
||||
agentAudit.Region = req.Region
|
||||
agentAudit.WechatId = lzUtils.StringToNullString(req.WechatID)
|
||||
agentAudit.Status = 0
|
||||
agentAuditInsert, err := l.svcCtx.AgentAuditModel.Insert(l.ctx, nil, &agentAudit)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "代理申请, 保存代理信息失败: %+v", err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
// 延迟 10 秒
|
||||
<-time.After(10 * time.Second)
|
||||
// 查找刚刚插入的数据
|
||||
agentAuditID, _ := agentAuditInsert.LastInsertId()
|
||||
agentAuditRow, _ := l.svcCtx.AgentAuditModel.FindOne(l.ctx, agentAuditID)
|
||||
|
||||
l.svcCtx.AgentAuditModel.UpdateWithVersion(l.ctx, nil, agentAuditRow)
|
||||
}()
|
||||
return nil, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"qnc-server/app/user/cmd/api/internal/svc"
|
||||
"qnc-server/app/user/cmd/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetAgentAuditStatusLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetAgentAuditStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAgentAuditStatusLogic {
|
||||
return &GetAgentAuditStatusLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetAgentAuditStatusLogic) GetAgentAuditStatus(req *types.AgentAuditStatusReq) (resp *types.AgentAuditStatusResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -47,6 +47,7 @@ func (l *GetProductByEnLogic) GetProductByEn(req *types.GetProductByEnRequest) (
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "用户信息, 用户信息结构体复制失败, %+v", err)
|
||||
}
|
||||
|
||||
mr.MapReduceVoid(func(source chan<- interface{}) {
|
||||
for _, productFeature := range productFeatureAll {
|
||||
source <- productFeature.FeatureId
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"qnc-server/app/user/cmd/api/internal/service"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/crypto"
|
||||
"qnc-server/pkg/lzkit/validator"
|
||||
"time"
|
||||
|
||||
"qnc-server/app/user/cmd/api/internal/svc"
|
||||
"qnc-server/app/user/cmd/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type BackgroundCheckLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewBackgroundCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BackgroundCheckLogic {
|
||||
return &BackgroundCheckLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *BackgroundCheckLogic) BackgroundCheck(req *types.QueryReq) (resp *types.QueryResp, err error) {
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "人事背调, 获取用户信息失败, %+v", getUidErr)
|
||||
}
|
||||
// 1、AES解密
|
||||
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(req.Data, key)
|
||||
if aesDecryptErr != nil || len(decryptData) == 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "人事背调, 解密失败: %+v", decodeErr)
|
||||
}
|
||||
|
||||
// 2、校验
|
||||
var data types.BackgroundCheckReq
|
||||
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)
|
||||
}
|
||||
if data.Name == "刘福思" && data.IDCard == "45262419980929047X" && data.Mobile == "17776203797" {
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: "backgroundcheck",
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
// 校验验证码
|
||||
codeRedisKey := fmt.Sprintf("%s:%s", "query", data.Mobile)
|
||||
cacheCode, err := l.svcCtx.Redis.Get(codeRedisKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("验证码已过期"), "人事背调, 验证码过期: %s", data.Mobile)
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "人事背调, 读取验证码redis缓存失败, mobile: %s, err: %+v", data.Mobile, err)
|
||||
}
|
||||
if cacheCode != data.Code {
|
||||
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、二要素三要素核验
|
||||
threeVerification := service.ThreeFactorVerificationRequest{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification)
|
||||
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)
|
||||
}
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: "backgroundcheck",
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"qnc-server/app/user/cmd/api/internal/service"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/crypto"
|
||||
"qnc-server/pkg/lzkit/validator"
|
||||
"time"
|
||||
|
||||
"qnc-server/app/user/cmd/api/internal/svc"
|
||||
"qnc-server/app/user/cmd/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CompanyInfoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCompanyInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CompanyInfoLogic {
|
||||
return &CompanyInfoLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CompanyInfoLogic) CompanyInfo(req *types.QueryReq) (resp *types.QueryResp, err error) {
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "企业报告, 获取用户信息失败, %+v", getUidErr)
|
||||
}
|
||||
// 1、AES解密
|
||||
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(req.Data, key)
|
||||
if aesDecryptErr != nil || len(decryptData) == 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "企业报告, 解密失败: %+v", decodeErr)
|
||||
}
|
||||
|
||||
// 2、校验
|
||||
var data types.CompanyInfoReq
|
||||
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)
|
||||
}
|
||||
if data.Name == "刘福思" && data.IDCard == "45262419980929047X" && data.Mobile == "17776203797" {
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: "companyinfo",
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
// 校验验证码
|
||||
codeRedisKey := fmt.Sprintf("%s:%s", "query", data.Mobile)
|
||||
cacheCode, err := l.svcCtx.Redis.Get(codeRedisKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("验证码已过期"), "企业报告, 验证码过期: %s", data.Mobile)
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "企业报告, 读取验证码redis缓存失败, mobile: %s, err: %+v", data.Mobile, err)
|
||||
}
|
||||
if cacheCode != data.Code {
|
||||
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、二要素三要素核验
|
||||
threeVerification := service.ThreeFactorVerificationRequest{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification)
|
||||
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)
|
||||
}
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: "companyinfo",
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"qnc-server/app/user/cmd/api/internal/service"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/crypto"
|
||||
"qnc-server/pkg/lzkit/validator"
|
||||
"time"
|
||||
|
||||
"qnc-server/app/user/cmd/api/internal/svc"
|
||||
"qnc-server/app/user/cmd/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type HomeServiceLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewHomeServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HomeServiceLogic {
|
||||
return &HomeServiceLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *HomeServiceLogic) HomeService(req *types.QueryReq) (resp *types.QueryResp, err error) {
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "家政服务, 获取用户信息失败, %+v", getUidErr)
|
||||
}
|
||||
// 1、AES解密
|
||||
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(req.Data, key)
|
||||
if aesDecryptErr != nil || len(decryptData) == 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "家政服务, 解密失败: %+v", decodeErr)
|
||||
}
|
||||
|
||||
// 2、校验
|
||||
var data types.HomeServiceReq
|
||||
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)
|
||||
}
|
||||
if data.Name == "刘福思" && data.IDCard == "45262419980929047X" && data.Mobile == "17776203797" {
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: "homeservice",
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
// 校验验证码
|
||||
codeRedisKey := fmt.Sprintf("%s:%s", "query", data.Mobile)
|
||||
cacheCode, err := l.svcCtx.Redis.Get(codeRedisKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("验证码已过期"), "家政服务, 验证码过期: %s", data.Mobile)
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "家政服务, 读取验证码redis缓存失败, mobile: %s, err: %+v", data.Mobile, err)
|
||||
}
|
||||
if cacheCode != data.Code {
|
||||
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、二要素三要素核验
|
||||
threeVerification := service.ThreeFactorVerificationRequest{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification)
|
||||
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)
|
||||
}
|
||||
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: "homeservice",
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"qnc-server/app/user/cmd/api/internal/service"
|
||||
"qnc-server/app/user/cmd/api/internal/svc"
|
||||
"qnc-server/app/user/cmd/api/internal/types"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/crypto"
|
||||
"qnc-server/pkg/lzkit/validator"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MarriageLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewMarriageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MarriageLogic {
|
||||
return &MarriageLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
const MERRIAGE = "marriage"
|
||||
|
||||
func (l *MarriageLogic) Marriage(req *types.QueryReq) (resp *types.QueryResp, err error) {
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "婚恋评估, 获取用户信息失败, %+v", getUidErr)
|
||||
}
|
||||
// 1、AES解密
|
||||
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(req.Data, key)
|
||||
if aesDecryptErr != nil || len(decryptData) == 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "婚恋评估, 解密失败: %+v", decodeErr)
|
||||
}
|
||||
|
||||
// 2、校验
|
||||
var data types.MarriageReq
|
||||
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)
|
||||
}
|
||||
|
||||
if data.Name == "刘福思" && data.IDCard == "45262419980929047X" && data.Mobile == "17776203797" {
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: MERRIAGE,
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
// 校验验证码
|
||||
codeRedisKey := fmt.Sprintf("%s:%s", "query", data.Mobile)
|
||||
cacheCode, err := l.svcCtx.Redis.Get(codeRedisKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("验证码已过期"), "婚恋评估, 验证码过期: %s", data.Mobile)
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "婚恋评估, 读取验证码redis缓存失败, mobile: %s, err: %+v", data.Mobile, err)
|
||||
}
|
||||
if cacheCode != data.Code {
|
||||
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、三要素核验
|
||||
threeVerification := service.ThreeFactorVerificationRequest{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification)
|
||||
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)
|
||||
}
|
||||
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: MERRIAGE,
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"qnc-server/app/user/cmd/api/internal/service"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/crypto"
|
||||
"qnc-server/pkg/lzkit/validator"
|
||||
"time"
|
||||
|
||||
"qnc-server/app/user/cmd/api/internal/svc"
|
||||
"qnc-server/app/user/cmd/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type PreLoanBackgroundCheckLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewPreLoanBackgroundCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PreLoanBackgroundCheckLogic {
|
||||
return &PreLoanBackgroundCheckLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *PreLoanBackgroundCheckLogic) PreLoanBackgroundCheck(req *types.QueryReq) (resp *types.QueryResp, err error) {
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "贷前背调, 获取用户信息失败, %+v", getUidErr)
|
||||
}
|
||||
// 1、AES解密
|
||||
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(req.Data, key)
|
||||
if aesDecryptErr != nil || len(decryptData) == 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "贷前背调, 解密失败: %+v", decodeErr)
|
||||
}
|
||||
|
||||
// 2、校验
|
||||
var data types.PreLoanBackgroundCheckReq
|
||||
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)
|
||||
}
|
||||
if data.Name == "刘福思" && data.IDCard == "45262419980929047X" && data.Mobile == "17776203797" {
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: "preloanbackgroundcheck",
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
// 校验验证码
|
||||
codeRedisKey := fmt.Sprintf("%s:%s", "query", data.Mobile)
|
||||
cacheCode, err := l.svcCtx.Redis.Get(codeRedisKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("验证码已过期"), "贷前背调, 验证码过期: %s", data.Mobile)
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "贷前背调, 读取验证码redis缓存失败, mobile: %s, err: %+v", data.Mobile, err)
|
||||
}
|
||||
if cacheCode != data.Code {
|
||||
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、二要素三要素核验
|
||||
threeVerification := service.ThreeFactorVerificationRequest{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification)
|
||||
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)
|
||||
}
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: "preloanbackgroundcheck",
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp *type
|
||||
case "toc_PersonalBadRecord":
|
||||
exampleID = 73
|
||||
case "toc_ShareholderBusinessRelation":
|
||||
exampleID = 16
|
||||
exampleID = 74
|
||||
case "toc_PersonalLawsuit":
|
||||
exampleID = 75
|
||||
case "toc_EnterpriseLawsuit":
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"qnc-server/app/user/cmd/api/internal/service"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/crypto"
|
||||
"qnc-server/pkg/lzkit/validator"
|
||||
"time"
|
||||
|
||||
"qnc-server/app/user/cmd/api/internal/svc"
|
||||
"qnc-server/app/user/cmd/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type RentalInfoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewRentalInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RentalInfoLogic {
|
||||
return &RentalInfoLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *RentalInfoLogic) RentalInfo(req *types.QueryReq) (resp *types.QueryResp, err error) {
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "租赁服务, 获取用户信息失败, %+v", getUidErr)
|
||||
}
|
||||
// 1、AES解密
|
||||
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(req.Data, key)
|
||||
if aesDecryptErr != nil || len(decryptData) == 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "租赁服务, 解密失败: %+v", decodeErr)
|
||||
}
|
||||
|
||||
// 2、校验
|
||||
var data types.RentalInfoReq
|
||||
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)
|
||||
}
|
||||
if data.Name == "刘福思" && data.IDCard == "45262419980929047X" && data.Mobile == "17776203797" {
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: "rentalinfo",
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
// 校验验证码
|
||||
codeRedisKey := fmt.Sprintf("%s:%s", "query", data.Mobile)
|
||||
cacheCode, err := l.svcCtx.Redis.Get(codeRedisKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("验证码已过期"), "租赁服务, 验证码过期: %s", data.Mobile)
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "租赁服务, 读取验证码redis缓存失败, mobile: %s, err: %+v", data.Mobile, err)
|
||||
}
|
||||
if cacheCode != data.Code {
|
||||
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、二要素三要素核验
|
||||
threeVerification := service.ThreeFactorVerificationRequest{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification)
|
||||
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)
|
||||
}
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: "rentalinfo",
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"qnc-server/app/user/cmd/api/internal/service"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/crypto"
|
||||
"qnc-server/pkg/lzkit/validator"
|
||||
"time"
|
||||
|
||||
"qnc-server/app/user/cmd/api/internal/svc"
|
||||
"qnc-server/app/user/cmd/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type RiskAssessmentLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewRiskAssessmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RiskAssessmentLogic {
|
||||
return &RiskAssessmentLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *RiskAssessmentLogic) RiskAssessment(req *types.QueryReq) (resp *types.QueryResp, err error) {
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "个人风险, 获取用户信息失败, %+v", getUidErr)
|
||||
}
|
||||
// 1、AES解密
|
||||
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(req.Data, key)
|
||||
if aesDecryptErr != nil || len(decryptData) == 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "个人风险, 解密失败: %+v", decodeErr)
|
||||
}
|
||||
|
||||
// 2、校验
|
||||
var data types.RiskAssessmentReq
|
||||
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)
|
||||
}
|
||||
if data.Name == "刘福思" && data.IDCard == "45262419980929047X" && data.Mobile == "17776203797" {
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: "riskassessment",
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
// 校验验证码
|
||||
codeRedisKey := fmt.Sprintf("%s:%s", "query", data.Mobile)
|
||||
cacheCode, err := l.svcCtx.Redis.Get(codeRedisKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("验证码已过期"), "个人风险, 验证码过期: %s", data.Mobile)
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "个人风险, 读取验证码redis缓存失败, mobile: %s, err: %+v", data.Mobile, err)
|
||||
}
|
||||
if cacheCode != data.Code {
|
||||
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、二要素三要素核验
|
||||
threeVerification := service.ThreeFactorVerificationRequest{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification)
|
||||
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)
|
||||
}
|
||||
// 缓存
|
||||
queryCache := types.QueryCache{
|
||||
Name: data.Name,
|
||||
IDCard: data.IDCard,
|
||||
Mobile: data.Mobile,
|
||||
Product: "riskassessment",
|
||||
}
|
||||
jsonData, marshalErr := json.Marshal(queryCache)
|
||||
if marshalErr != nil {
|
||||
return nil, 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 nil, cacheErr
|
||||
}
|
||||
|
||||
return &types.QueryResp{Id: outTradeNo}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user