This commit is contained in:
Mrx
2026-01-30 11:39:28 +08:00
parent c64b22ab05
commit 76784c3c1b
19 changed files with 717 additions and 46 deletions

View File

@@ -2,13 +2,16 @@ package query
import (
"context"
"database/sql"
"encoding/hex"
"encoding/json"
"fmt"
"os"
"time"
"tyc-server/app/main/api/internal/service"
"tyc-server/app/main/model"
"tyc-server/common/ctxdata"
"tyc-server/common/globalkey"
"tyc-server/common/xerr"
"tyc-server/pkg/lzkit/crypto"
"tyc-server/pkg/lzkit/validator"
@@ -739,8 +742,11 @@ func (l *QueryServiceLogic) DecryptData(data string) ([]byte, error) {
return decryptData, nil
}
// 校验验证码
// 校验验证码(开发环境 ENV=development 可跳过)
func (l *QueryServiceLogic) VerifyCode(mobile string, code string) error {
if os.Getenv("ENV") == "development" {
return nil
}
secretKey := l.svcCtx.Config.Encrypt.SecretKey
encryptedMobile, err := crypto.EncryptMobile(mobile, secretKey)
if err != nil {
@@ -765,8 +771,11 @@ func (l *QueryServiceLogic) IsAgentQuery() bool {
return agentID != ""
}
// 二要素验证(仅姓名+身份证号)
// 二要素验证(仅姓名+身份证号)(开发环境不调用验证 API
func (l *QueryServiceLogic) VerifyTwo(Name string, IDCard string) error {
if os.Getenv("ENV") == "development" {
return nil
}
twoVerification := service.TwoFactorVerificationRequest{
Name: Name,
IDCard: IDCard,
@@ -781,8 +790,11 @@ func (l *QueryServiceLogic) VerifyTwo(Name string, IDCard string) error {
return nil
}
// 按代理/非代理切换要素验证:代理走三要素;非代理走二要素
// 按代理/非代理切换要素验证:代理走三要素;非代理走二要素(开发环境不调用验证 API
func (l *QueryServiceLogic) Verify(Name string, IDCard string, Mobile string) error {
if os.Getenv("ENV") == "development" {
return nil
}
if !l.IsAgentQuery() {
twoVerification := service.TwoFactorVerificationRequest{
Name: Name,
@@ -847,6 +859,46 @@ func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product str
if cacheErr != nil {
return "", cacheErr
}
// 写入 query_user_record用于后台按被查询人姓名/身份证/手机号追溯订单(见 query_user_record.sql 说明 1
nameStr, _ := params["name"].(string)
idCardStr, _ := params["id_card"].(string)
mobileStr, _ := params["mobile"].(string)
if nameStr != "" || idCardStr != "" || mobileStr != "" {
var encName, encIdCard, encMobile string
if nameStr != "" {
encName, _ = crypto.AesEcbEncrypt([]byte(nameStr), key)
}
if idCardStr != "" {
encIdCard, _ = crypto.EncryptIDCard(idCardStr, key)
}
if mobileStr != "" {
encMobile, _ = crypto.EncryptMobile(mobileStr, secretKey)
}
agentIdent := sql.NullString{}
if agentIdentifier != "" {
agentIdent = sql.NullString{String: agentIdentifier, Valid: true}
}
rec := &model.QueryUserRecord{
DeleteTime: sql.NullTime{},
DelState: globalkey.DelStateNo,
Version: 0,
UserId: userID,
Name: encName,
IdCard: encIdCard,
Mobile: encMobile,
Product: Product,
QueryNo: outTradeNo,
OrderId: 0,
PlatformOrderId: sql.NullString{},
AgentIdentifier: agentIdent,
}
_, insertErr := l.svcCtx.QueryUserRecordModel.Insert(l.ctx, nil, rec)
if insertErr != nil {
logx.WithContext(l.ctx).Errorf("CacheData 写入 query_user_record 失败: %v", insertErr)
}
}
return outTradeNo, nil
}