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 {
|
func (l *QueryServiceLogic) Verify(Name string, IDCard string, Mobile string) error {
|
||||||
agent, ok := l.ctx.Value("agent").(bool)
|
//agent, ok := l.ctx.Value("agent").(bool)
|
||||||
if !ok {
|
//if !ok {
|
||||||
agent = false
|
// agent = false
|
||||||
}
|
//}
|
||||||
if !l.svcCtx.Config.SystemConfig.ThreeVerify || agent {
|
if !l.svcCtx.Config.SystemConfig.ThreeVerify {
|
||||||
twoVerification := service.TwoFactorVerificationRequest{
|
twoVerification := service.TwoFactorVerificationRequest{
|
||||||
Name: Name,
|
Name: Name,
|
||||||
IDCard: IDCard,
|
IDCard: IDCard,
|
||||||
}
|
}
|
||||||
verification, err := l.svcCtx.VerificationService.TwoFactorVerification(twoVerification)
|
verification, err := l.svcCtx.VerificationService.TwoFactorVerificationWest(twoVerification)
|
||||||
if err != nil {
|
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)
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
func (l *QuerySingleTestLogic) QuerySingleTest(req *types.QuerySingleTestReq) (resp *types.QuerySingleTestResp, err error) {
|
||||||
featrueModel, err := l.svcCtx.FeatureModel.FindOneByApiId(l.ctx, req.Api)
|
//featrueModel, err := l.svcCtx.FeatureModel.FindOneByApiId(l.ctx, req.Api)
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "单查测试, 获取接口失败 : %d", err)
|
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "单查测试, 获取接口失败 : %d", err)
|
||||||
}
|
//}
|
||||||
marshalParams, err := json.Marshal(req.Params)
|
marshalParams, err := json.Marshal(req.Params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "单查测试, 序列化参数失败 : %d", err)
|
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{
|
return &types.QuerySingleTestResp{
|
||||||
Data: respData,
|
Data: respData,
|
||||||
Api: featrueModel.Name,
|
Api: req.Api,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Masterminds/squirrel"
|
|
||||||
"github.com/bytedance/sonic"
|
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -20,6 +16,11 @@ import (
|
|||||||
"tydata-server/app/user/model"
|
"tydata-server/app/user/model"
|
||||||
"tydata-server/pkg/lzkit/crypto"
|
"tydata-server/pkg/lzkit/crypto"
|
||||||
"tydata-server/pkg/lzkit/lzUtils"
|
"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 {
|
type ApiRequestService struct {
|
||||||
@ -168,32 +169,33 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID int64) ([]b
|
|||||||
|
|
||||||
// ------------------------------------请求处理器--------------------------
|
// ------------------------------------请求处理器--------------------------
|
||||||
var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, error){
|
var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, error){
|
||||||
"G09SC02": (*ApiRequestService).ProcessG09SC02Request,
|
"G09SC02": (*ApiRequestService).ProcessG09SC02Request,
|
||||||
"G27BJ05": (*ApiRequestService).ProcessG27BJ05Request,
|
"G27BJ05": (*ApiRequestService).ProcessG27BJ05Request,
|
||||||
"G26BJ05": (*ApiRequestService).ProcessG26BJ05Request,
|
"G26BJ05": (*ApiRequestService).ProcessG26BJ05Request,
|
||||||
"G34BJ03": (*ApiRequestService).ProcessG34BJ03Request,
|
"G34BJ03": (*ApiRequestService).ProcessG34BJ03Request,
|
||||||
"G35SC01": (*ApiRequestService).ProcessG35SC01Request,
|
"G35SC01": (*ApiRequestService).ProcessG35SC01Request,
|
||||||
"G28BJ05": (*ApiRequestService).ProcessG28BJ05Request,
|
"G28BJ05": (*ApiRequestService).ProcessG28BJ05Request,
|
||||||
"G05HZ01": (*ApiRequestService).ProcessG05HZ01Request,
|
"G05HZ01": (*ApiRequestService).ProcessG05HZ01Request,
|
||||||
"Q23SC01": (*ApiRequestService).ProcessQ23SC01Request,
|
"Q23SC01": (*ApiRequestService).ProcessQ23SC01Request,
|
||||||
"G15BJ02": (*ApiRequestService).ProcessG15BJ02Request,
|
"G15BJ02": (*ApiRequestService).ProcessG15BJ02Request,
|
||||||
"G17BJ02": (*ApiRequestService).ProcessG17BJ02Request,
|
"G17BJ02": (*ApiRequestService).ProcessG17BJ02Request,
|
||||||
"G08SC02": (*ApiRequestService).ProcessG08SC02Request,
|
"G08SC02": (*ApiRequestService).ProcessG08SC02Request,
|
||||||
"KZEYS": (*ApiRequestService).ProcessKZEYSRequest,
|
"KZEYS": (*ApiRequestService).ProcessKZEYSRequest,
|
||||||
"P_C_B332": (*ApiRequestService).ProcessP_C_B332Request,
|
"P_C_B332": (*ApiRequestService).ProcessP_C_B332Request,
|
||||||
"FIN019": (*ApiRequestService).ProcessFIN019Request,
|
"FIN019": (*ApiRequestService).ProcessFIN019Request,
|
||||||
"CAR061": (*ApiRequestService).ProcessCAR061Request,
|
"CAR061": (*ApiRequestService).ProcessCAR061Request,
|
||||||
"G10SC02": (*ApiRequestService).ProcessG10SC02Request,
|
"G10SC02": (*ApiRequestService).ProcessG10SC02Request,
|
||||||
"G03HZ01": (*ApiRequestService).ProcessG03HZ01Request,
|
"G03HZ01": (*ApiRequestService).ProcessG03HZ01Request,
|
||||||
"G02BJ02": (*ApiRequestService).ProcessG02BJ02Request,
|
"G02BJ02": (*ApiRequestService).ProcessG02BJ02Request,
|
||||||
"G19BJ02": (*ApiRequestService).ProcessG19BJ02Request,
|
"G19BJ02": (*ApiRequestService).ProcessG19BJ02Request,
|
||||||
"G20GZ01": (*ApiRequestService).ProcessG20GZ01Request,
|
"G20GZ01": (*ApiRequestService).ProcessG20GZ01Request,
|
||||||
"G37SC01": (*ApiRequestService).ProcessG37SC01Request,
|
"G37SC01": (*ApiRequestService).ProcessG37SC01Request,
|
||||||
"G36SC01": (*ApiRequestService).ProcessG36SC01Request,
|
"G36SC01": (*ApiRequestService).ProcessG36SC01Request,
|
||||||
"G22SC01": (*ApiRequestService).ProcessG22SC01Request,
|
"G22SC01": (*ApiRequestService).ProcessG22SC01Request,
|
||||||
"Q03SC01": (*ApiRequestService).ProcessQ03SC01Request,
|
"Q03SC01": (*ApiRequestService).ProcessQ03SC01Request,
|
||||||
"G39SC02": (*ApiRequestService).ProcessG39SC02Request,
|
"G39SC02": (*ApiRequestService).ProcessG39SC02Request,
|
||||||
"G38SC02": (*ApiRequestService).ProcessG38SC02Request,
|
"G38SC02": (*ApiRequestService).ProcessG38SC02Request,
|
||||||
|
"layoutIdcard": (*ApiRequestService).ProcessLayoutIdcardRequest,
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreprocessRequestApi 调用指定的请求处理函数
|
// PreprocessRequestApi 调用指定的请求处理函数
|
||||||
@ -693,7 +695,6 @@ func (a *ApiRequestService) ProcessKZEYSRequest(params []byte) ([]byte, error) {
|
|||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return nil, fmt.Errorf("KZEYS 请求失败, 状态码: %d", resp.StatusCode)
|
return nil, fmt.Errorf("KZEYS 请求失败, 状态码: %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
respBody, err := io.ReadAll(resp.Body)
|
respBody, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("KZEYS 响应体读取失败:%v", err)
|
return nil, fmt.Errorf("KZEYS 响应体读取失败:%v", err)
|
||||||
@ -1151,3 +1152,43 @@ func (a *ApiRequestService) ProcessG38SC02Request(params []byte) ([]byte, error)
|
|||||||
return resp, nil
|
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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"tydata-server/app/user/cmd/api/internal/config"
|
"tydata-server/app/user/cmd/api/internal/config"
|
||||||
"tydata-server/pkg/lzkit/crypto"
|
"tydata-server/pkg/lzkit/crypto"
|
||||||
|
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VerificationService struct {
|
type VerificationService struct {
|
||||||
c config.Config
|
c config.Config
|
||||||
westDexService *WestDexService
|
westDexService *WestDexService
|
||||||
|
apiRequestService *ApiRequestService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVerificationService(c config.Config, westDexService *WestDexService) *VerificationService {
|
func NewVerificationService(c config.Config, westDexService *WestDexService, apiRequestService *ApiRequestService) *VerificationService {
|
||||||
return &VerificationService{
|
return &VerificationService{
|
||||||
c: c,
|
c: c,
|
||||||
westDexService: westDexService,
|
westDexService: westDexService,
|
||||||
|
apiRequestService: apiRequestService,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,6 +129,33 @@ func (r *VerificationService) TwoFactorVerification(request TwoFactorVerificatio
|
|||||||
|
|
||||||
return &VerificationResult{Passed: true, Err: nil}, nil
|
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) {
|
func (r *VerificationService) ThreeFactorVerification(request ThreeFactorVerificationRequest) (*VerificationResult, error) {
|
||||||
westName, err := crypto.WestDexEncrypt(request.Name, r.c.WestConfig.Key)
|
westName, err := crypto.WestDexEncrypt(request.Name, r.c.WestConfig.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -89,7 +89,7 @@ func (w *WestDexService) CallAPI(code string, reqData map[string]interface{}) (r
|
|||||||
if UnmarshalErr != nil {
|
if UnmarshalErr != nil {
|
||||||
return nil, UnmarshalErr
|
return nil, UnmarshalErr
|
||||||
}
|
}
|
||||||
if westDexResp.Code != "00000" {
|
if westDexResp.Code != "00000" && westDexResp.Code != "0" {
|
||||||
if westDexResp.Data == "" {
|
if westDexResp.Data == "" {
|
||||||
return nil, errors.New(westDexResp.Message)
|
return nil, errors.New(westDexResp.Message)
|
||||||
}
|
}
|
||||||
|
@ -104,8 +104,8 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
alipayService := service.NewAliPayService(c)
|
alipayService := service.NewAliPayService(c)
|
||||||
wechatPayService := service.NewWechatPayService(c, userAuthModel)
|
wechatPayService := service.NewWechatPayService(c, userAuthModel)
|
||||||
applePayService := service.NewApplePayService(c)
|
applePayService := service.NewApplePayService(c)
|
||||||
verificationService := service.NewVerificationService(c, westDexService)
|
|
||||||
apiRequestService := service.NewApiRequestService(c, westDexService, yushanService, featureModel, productFeatureModel)
|
apiRequestService := service.NewApiRequestService(c, westDexService, yushanService, featureModel, productFeatureModel)
|
||||||
|
verificationService := service.NewVerificationService(c, westDexService, apiRequestService)
|
||||||
asynqService := service.NewAsynqService(c)
|
asynqService := service.NewAsynqService(c)
|
||||||
agentService := service.NewAgentService(c, agentModel, agentAuditModel, agentClosureModel, agentCommissionModel,
|
agentService := service.NewAgentService(c, agentModel, agentAuditModel, agentClosureModel, agentCommissionModel,
|
||||||
agentCommissionDeductionModel, agentWalletModel, agentLinkModel, agentOrderModel, agentRewardsModel,
|
agentCommissionDeductionModel, agentWalletModel, agentLinkModel, agentOrderModel, agentRewardsModel,
|
||||||
|
Loading…
Reference in New Issue
Block a user