This commit is contained in:
Mrx
2026-05-23 16:13:30 +08:00
parent effe82ce65
commit e2aab6af71
11 changed files with 695 additions and 9 deletions

View File

@@ -6,13 +6,13 @@ import (
"encoding/json"
"fmt"
"os"
"regexp"
"strings"
"qnc-server/app/main/api/internal/svc"
"qnc-server/app/main/api/internal/types"
"qnc-server/app/main/model"
"qnc-server/pkg/lzkit/crypto"
"qnc-server/pkg/lzkit/lzUtils"
"regexp"
"strings"
"github.com/google/uuid"
"github.com/hibiken/asynq"
@@ -186,6 +186,9 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
return l.handleError(ctx, updateQueryErr, order, query)
}
// 记录动态查询记录 (真实案例展示)
go l.recordInquiryRecord(context.Background(), decryptData, product, encryptData)
// 报告生成成功后,发送代理处理异步任务(不阻塞报告流程)
if asyncErr := l.svcCtx.AsynqService.SendAgentProcessTask(order.Id); asyncErr != nil {
// 代理处理任务发送失败,只记录日志,不影响报告流程
@@ -377,6 +380,84 @@ func maskPhone(phone string) string {
return phone[:3] + strings.Repeat("*", length-7) + phone[length-4:]
}
// recordInquiryRecord 记录成功的查询到动态展示表
func (l *PaySuccessNotifyUserHandler) recordInquiryRecord(ctx context.Context, decryptParams []byte, product *model.Product, encryptedResp string) {
defer func() {
if r := recover(); r != nil {
logx.Errorf("记录查询记录异常: %v", r)
}
}()
secretKey := l.svcCtx.Config.Encrypt.SecretKey
key, _ := hex.DecodeString(secretKey)
// 1. 解析参数获取手机号和VIN
var params map[string]interface{}
_ = json.Unmarshal(decryptParams, &params)
mobile, _ := params["mobile"].(string)
vin, _ := params["vin_code"].(string)
if vin == "" {
vin, _ = params["vin"].(string)
}
if mobile == "" || vin == "" {
return
}
// 2. 解密响应数据获取车型
decryptResp, err := crypto.AesDecrypt(encryptedResp, key)
if err != nil {
return
}
// 尝试从响应中寻找车型信息 (这里根据实际响应结构寻找)
// 通常在车辆信息接口的 data 字段中
carModel := "未知车型"
respStr := string(decryptResp)
// 简单的规则寻找车型字段
if strings.Contains(respStr, "model_name") {
re := regexp.MustCompile(`"model_name"\s*:\s*"([^"]+)"`)
match := re.FindStringSubmatch(respStr)
if len(match) > 1 {
carModel = match[1]
}
} else if strings.Contains(respStr, "brand_name") {
re := regexp.MustCompile(`"brand_name"\s*:\s*"([^"]+)"`)
match := re.FindStringSubmatch(respStr)
if len(match) > 1 {
carModel = match[1]
}
}
// 3. 脱敏处理
phoneTail := ""
if len(mobile) >= 4 {
phoneTail = mobile[len(mobile)-4:]
}
displayName := "用户*" + phoneTail
maskedVin := ""
if len(vin) >= 8 {
maskedVin = vin[:4] + "********" + vin[len(vin)-4:]
} else {
maskedVin = vin
}
// 4. 保存记录
record := &model.InquiryRecord{
UserPhoneTail: phoneTail,
DisplayName: displayName,
VinMasked: maskedVin,
CarModel: carModel,
InquiryTag: product.ProductName,
Status: 1,
}
_, _ = l.svcCtx.InquiryRecordModel.Insert(ctx, nil, record)
}
// 通用敏感信息脱敏 - 根据字符串长度比例进行脱敏
func maskGeneral(value string) string {
length := len(value)