add 3 new api
This commit is contained in:
parent
42ea1bd929
commit
ece4b5d1b1
@ -1330,16 +1330,16 @@ func (l *QueryServiceLogic) VerifyCode(mobile string, code string) error {
|
||||
|
||||
// 二、三要素验证
|
||||
func (l *QueryServiceLogic) Verify(Name string, IDCard string, Mobile string) error {
|
||||
agent, ok := l.ctx.Value("agent").(bool)
|
||||
if !ok {
|
||||
agent = false
|
||||
}
|
||||
if !l.svcCtx.Config.SystemConfig.ThreeVerify || agent {
|
||||
//agent, ok := l.ctx.Value("agent").(bool)
|
||||
//if !ok {
|
||||
// agent = false
|
||||
//}
|
||||
if !l.svcCtx.Config.SystemConfig.ThreeVerify {
|
||||
twoVerification := service.TwoFactorVerificationRequest{
|
||||
Name: Name,
|
||||
IDCard: IDCard,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification)
|
||||
verification, err := l.svcCtx.VerificationService.TwoFactorVerificationWest(twoVerification)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "二要素验证失败: %v", err)
|
||||
}
|
||||
|
@ -27,10 +27,10 @@ func NewQuerySingleTestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Q
|
||||
}
|
||||
|
||||
func (l *QuerySingleTestLogic) QuerySingleTest(req *types.QuerySingleTestReq) (resp *types.QuerySingleTestResp, err error) {
|
||||
featrueModel, err := l.svcCtx.FeatureModel.FindOneByApiId(l.ctx, req.Api)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "单查测试, 获取接口失败 : %d", err)
|
||||
}
|
||||
//featrueModel, err := l.svcCtx.FeatureModel.FindOneByApiId(l.ctx, req.Api)
|
||||
//if err != nil {
|
||||
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "单查测试, 获取接口失败 : %d", err)
|
||||
//}
|
||||
marshalParams, err := json.Marshal(req.Params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "单查测试, 序列化参数失败 : %d", err)
|
||||
@ -46,6 +46,6 @@ func (l *QuerySingleTestLogic) QuerySingleTest(req *types.QuerySingleTestReq) (r
|
||||
}
|
||||
return &types.QuerySingleTestResp{
|
||||
Data: respData,
|
||||
Api: featrueModel.Name,
|
||||
Api: req.Api,
|
||||
}, nil
|
||||
}
|
||||
|
@ -5,10 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -20,6 +16,11 @@ import (
|
||||
"tydata-server/app/user/model"
|
||||
"tydata-server/pkg/lzkit/crypto"
|
||||
"tydata-server/pkg/lzkit/lzUtils"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ApiRequestService struct {
|
||||
@ -194,6 +195,7 @@ var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, err
|
||||
"Q03SC01": (*ApiRequestService).ProcessQ03SC01Request,
|
||||
"G39SC02": (*ApiRequestService).ProcessG39SC02Request,
|
||||
"G38SC02": (*ApiRequestService).ProcessG38SC02Request,
|
||||
"layoutIdcard": (*ApiRequestService).ProcessLayoutIdcardRequest,
|
||||
}
|
||||
|
||||
// PreprocessRequestApi 调用指定的请求处理函数
|
||||
@ -693,7 +695,6 @@ func (a *ApiRequestService) ProcessKZEYSRequest(params []byte) ([]byte, error) {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("KZEYS 请求失败, 状态码: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("KZEYS 响应体读取失败:%v", err)
|
||||
@ -1151,3 +1152,43 @@ func (a *ApiRequestService) ProcessG38SC02Request(params []byte) ([]byte, error)
|
||||
return resp, nil
|
||||
|
||||
}
|
||||
|
||||
// layoutIdcard 西部二要素
|
||||
func (a *ApiRequestService) ProcessLayoutIdcardRequest(params []byte) ([]byte, 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 []byte(firstChar), nil
|
||||
}
|
||||
|
@ -3,24 +3,27 @@ package service
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/tidwall/gjson"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"tydata-server/app/user/cmd/api/internal/config"
|
||||
"tydata-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,6 +129,33 @@ func (r *VerificationService) TwoFactorVerification(request TwoFactorVerificatio
|
||||
|
||||
return &VerificationResult{Passed: true, Err: nil}, nil
|
||||
}
|
||||
|
||||
func (r *VerificationService) TwoFactorVerificationWest(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(marshal)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求失败: %v", err)
|
||||
}
|
||||
|
||||
respStr := string(resp)
|
||||
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 {
|
||||
|
@ -89,7 +89,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)
|
||||
}
|
||||
|
@ -104,8 +104,8 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
alipayService := service.NewAliPayService(c)
|
||||
wechatPayService := service.NewWechatPayService(c, userAuthModel)
|
||||
applePayService := service.NewApplePayService(c)
|
||||
verificationService := service.NewVerificationService(c, westDexService)
|
||||
apiRequestService := service.NewApiRequestService(c, westDexService, yushanService, featureModel, productFeatureModel)
|
||||
verificationService := service.NewVerificationService(c, westDexService, apiRequestService)
|
||||
asynqService := service.NewAsynqService(c)
|
||||
agentService := service.NewAgentService(c, agentModel, agentAuditModel, agentClosureModel, agentCommissionModel,
|
||||
agentCommissionDeductionModel, agentWalletModel, agentLinkModel, agentOrderModel, agentRewardsModel,
|
||||
|
Loading…
Reference in New Issue
Block a user