fix(订单中心):首页统计临时演示修复,二维码租户Id修改
This commit is contained in:
+85
@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import com.central.common.model.Result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 热数据同步控制器
|
* 热数据同步控制器
|
||||||
@@ -194,4 +195,88 @@ public class HotDataSyncController {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 诊断S3配置和URL生成
|
||||||
|
*/
|
||||||
|
@Operation(summary = "诊断S3配置和URL生成")
|
||||||
|
@GetMapping("/diagnose")
|
||||||
|
public Result<Map<String, Object>> diagnoseS3Config() {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 检查S3配置
|
||||||
|
result.put("s3Enabled", hotDataSyncService.isS3Enabled());
|
||||||
|
result.put("enhancedS3ServiceAvailable", hotDataSyncService.isEnhancedS3ServiceAvailable());
|
||||||
|
result.put("s3ServiceAvailable", hotDataSyncService.isS3ServiceAvailable());
|
||||||
|
|
||||||
|
// 检查S3配置信息
|
||||||
|
result.put("s3Config", hotDataSyncService.getS3ConfigInfo());
|
||||||
|
|
||||||
|
// 测试URL生成
|
||||||
|
result.put("urlTest", hotDataSyncService.testUrlGeneration());
|
||||||
|
|
||||||
|
// 检查热同步配置
|
||||||
|
result.put("hotSyncConfig", hotDataSyncService.getHotSyncConfig());
|
||||||
|
|
||||||
|
return Result.succeed(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("诊断S3配置失败", e);
|
||||||
|
result.put("error", e.getMessage());
|
||||||
|
return Result.failed("诊断失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试URL访问
|
||||||
|
*/
|
||||||
|
@Operation(summary = "测试URL访问")
|
||||||
|
@PostMapping("/test-url")
|
||||||
|
public Result<Map<String, Object>> testUrlAccess(@RequestParam String url) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
log.info("测试URL访问: {}", url);
|
||||||
|
|
||||||
|
// 创建HTTP连接
|
||||||
|
java.net.URL testUrl = new java.net.URL(url);
|
||||||
|
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) testUrl.openConnection();
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.setConnectTimeout(10000); // 10秒连接超时
|
||||||
|
connection.setReadTimeout(30000); // 30秒读取超时
|
||||||
|
|
||||||
|
// 设置User-Agent
|
||||||
|
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36");
|
||||||
|
|
||||||
|
int responseCode = connection.getResponseCode();
|
||||||
|
String responseMessage = connection.getResponseMessage();
|
||||||
|
|
||||||
|
result.put("url", url);
|
||||||
|
result.put("responseCode", responseCode);
|
||||||
|
result.put("responseMessage", responseMessage);
|
||||||
|
result.put("contentType", connection.getContentType());
|
||||||
|
result.put("contentLength", connection.getContentLengthLong());
|
||||||
|
result.put("accessible", responseCode == 200);
|
||||||
|
|
||||||
|
// 获取响应头信息
|
||||||
|
Map<String, String> headers = new HashMap<>();
|
||||||
|
connection.getHeaderFields().forEach((key, values) -> {
|
||||||
|
if (key != null && values != null && !values.isEmpty()) {
|
||||||
|
headers.put(key, String.join(", ", values));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
result.put("headers", headers);
|
||||||
|
|
||||||
|
log.info("URL访问测试结果: 状态码={}, 消息={}, 可访问={}", responseCode, responseMessage, responseCode == 200);
|
||||||
|
|
||||||
|
return Result.succeed(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("测试URL访问失败: {}", url, e);
|
||||||
|
result.put("url", url);
|
||||||
|
result.put("error", e.getMessage());
|
||||||
|
result.put("accessible", false);
|
||||||
|
return Result.failed("URL访问测试失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+167
-12
@@ -19,6 +19,8 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 热数据自动同步服务
|
* 热数据自动同步服务
|
||||||
@@ -203,10 +205,14 @@ public class HotDataSyncService {
|
|||||||
log.info("开始同步文件到S3,文件ID: {}, 文件名: {}, 重试次数: {}/{}",
|
log.info("开始同步文件到S3,文件ID: {}, 文件名: {}, 重试次数: {}/{}",
|
||||||
fileInfo.getId(), fileInfo.getName(), retryCount + 1, maxRetries);
|
fileInfo.getId(), fileInfo.getName(), retryCount + 1, maxRetries);
|
||||||
|
|
||||||
|
// 获取原始OSS路径(不包含hot-sync前缀)
|
||||||
|
String originalPath = getOriginalPath(fileInfo);
|
||||||
|
log.debug("原始OSS路径: {}", originalPath);
|
||||||
|
|
||||||
// 从OSS获取文件URL
|
// 从OSS获取文件URL
|
||||||
String ossUrl = ossService.getViewUrlByPath(fileInfo.getPath());
|
String ossUrl = ossService.getViewUrlByPath(originalPath);
|
||||||
if (ossUrl == null || ossUrl.isEmpty()) {
|
if (ossUrl == null || ossUrl.isEmpty()) {
|
||||||
log.error("从OSS获取文件URL失败,文件ID: {}", fileInfo.getId());
|
log.error("从OSS获取文件URL失败,文件ID: {}, 路径: {}", fileInfo.getId(), originalPath);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,16 +236,26 @@ public class HotDataSyncService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (uploadSuccess) {
|
if (uploadSuccess) {
|
||||||
|
// 验证文件是否真的上传成功
|
||||||
|
if (verifyFileUpload(s3Path)) {
|
||||||
// 更新文件存储信息
|
// 更新文件存储信息
|
||||||
updateFileStorageInfo(fileInfo, s3Path);
|
updateFileStorageInfo(fileInfo, s3Path);
|
||||||
log.info("文件同步成功,文件ID: {}, 新路径: {}", fileInfo.getId(), s3Path);
|
log.info("文件同步成功,文件ID: {}, 新路径: {}", fileInfo.getId(), s3Path);
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
log.error("文件上传验证失败,文件ID: {}", fileInfo.getId());
|
||||||
|
retryCount++;
|
||||||
|
if (retryCount < maxRetries) {
|
||||||
|
log.info("准备重试,等待2秒后重试...");
|
||||||
|
Thread.sleep(2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.error("文件上传到S3失败,文件ID: {}", fileInfo.getId());
|
log.error("文件上传到S3失败,文件ID: {}", fileInfo.getId());
|
||||||
retryCount++;
|
retryCount++;
|
||||||
if (retryCount < maxRetries) {
|
if (retryCount < maxRetries) {
|
||||||
log.info("准备重试,等待2秒后重试...");
|
log.info("准备重试,等待2秒后重试...");
|
||||||
Thread.sleep(2000); // 等待2秒后重试
|
Thread.sleep(2000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,7 +270,7 @@ public class HotDataSyncService {
|
|||||||
if (retryCount < maxRetries) {
|
if (retryCount < maxRetries) {
|
||||||
try {
|
try {
|
||||||
log.info("准备重试,等待2秒后重试...");
|
log.info("准备重试,等待2秒后重试...");
|
||||||
Thread.sleep(2000); // 等待2秒后重试
|
Thread.sleep(2000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
log.error("重试等待被中断", ie);
|
log.error("重试等待被中断", ie);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
@@ -371,14 +387,55 @@ public class HotDataSyncService {
|
|||||||
return "hot-sync/" + fileInfo.getId() + "/" + fileInfo.getName();
|
return "hot-sync/" + fileInfo.getId() + "/" + fileInfo.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果原路径包含OSS信息,替换为S3路径
|
// 提取文件名,避免路径过长
|
||||||
if (originalPath.contains("oss://") || originalPath.contains("aliyun")) {
|
String fileName = fileInfo.getName();
|
||||||
return originalPath.replace("oss://", "s3://")
|
if (fileName == null || fileName.isEmpty()) {
|
||||||
.replace("aliyun", "minio");
|
// 从路径中提取文件名
|
||||||
|
if (originalPath.contains("/")) {
|
||||||
|
fileName = originalPath.substring(originalPath.lastIndexOf("/") + 1);
|
||||||
|
} else {
|
||||||
|
fileName = originalPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 否则添加热同步前缀
|
// 生成简洁的S3路径
|
||||||
return "hot-sync/" + originalPath;
|
return "hot-sync/" + fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取原始OSS路径(去除hot-sync前缀)
|
||||||
|
*/
|
||||||
|
private String getOriginalPath(FileInfo fileInfo) {
|
||||||
|
String path = fileInfo.getPath();
|
||||||
|
if (path == null || path.isEmpty()) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果路径包含hot-sync前缀,去除它
|
||||||
|
if (path.startsWith("hot-sync/")) {
|
||||||
|
return path.substring("hot-sync/".length());
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证文件是否上传成功
|
||||||
|
*/
|
||||||
|
private boolean verifyFileUpload(String s3Path) {
|
||||||
|
try {
|
||||||
|
if (enhancedS3Service != null) {
|
||||||
|
return enhancedS3Service.fileExists(s3Path);
|
||||||
|
} else if (s3Service != null) {
|
||||||
|
// 基础S3服务验证
|
||||||
|
String url = s3Service.getViewUrlByPath(s3Path);
|
||||||
|
return url != null && !url.isEmpty();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("验证文件上传失败: {}", s3Path, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -482,7 +539,105 @@ public class HotDataSyncService {
|
|||||||
* 获取配置信息
|
* 获取配置信息
|
||||||
*/
|
*/
|
||||||
public String getConfigInfo() {
|
public String getConfigInfo() {
|
||||||
return String.format("批次大小: %d, 同步间隔: %d分钟, 访问阈值: %d, 热数据天数: %d, 最大线程: %d",
|
return String.format("热数据同步配置 - 启用: %s, 批次大小: %d, 同步间隔: %d分钟, 访问阈值: %d, 最大线程数: %d, 热数据天数: %d",
|
||||||
batchSize, syncIntervalMinutes, accessThreshold, hotDataDays, maxThreads);
|
syncEnabled, batchSize, syncIntervalMinutes, accessThreshold, maxThreads, hotDataDays);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查S3是否启用
|
||||||
|
*/
|
||||||
|
public boolean isS3Enabled() {
|
||||||
|
return syncEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查增强S3服务是否可用
|
||||||
|
*/
|
||||||
|
public boolean isEnhancedS3ServiceAvailable() {
|
||||||
|
return enhancedS3Service != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查基础S3服务是否可用
|
||||||
|
*/
|
||||||
|
public boolean isS3ServiceAvailable() {
|
||||||
|
return s3Service != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取S3配置信息
|
||||||
|
*/
|
||||||
|
public Map<String, Object> getS3ConfigInfo() {
|
||||||
|
Map<String, Object> config = new HashMap<>();
|
||||||
|
|
||||||
|
if (enhancedS3Service != null) {
|
||||||
|
config.put("enhancedS3Service", "可用");
|
||||||
|
// 尝试获取S3配置信息
|
||||||
|
try {
|
||||||
|
// 这里可以添加更多S3配置信息的获取逻辑
|
||||||
|
config.put("s3Template", enhancedS3Service != null ? "已配置" : "未配置");
|
||||||
|
} catch (Exception e) {
|
||||||
|
config.put("s3Template", "配置错误: " + e.getMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
config.put("enhancedS3Service", "不可用");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s3Service != null) {
|
||||||
|
config.put("s3Service", "可用");
|
||||||
|
} else {
|
||||||
|
config.put("s3Service", "不可用");
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试URL生成
|
||||||
|
*/
|
||||||
|
public Map<String, Object> testUrlGeneration() {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 测试一个示例路径
|
||||||
|
String testPath = "hot-sync/test-file.txt";
|
||||||
|
|
||||||
|
if (enhancedS3Service != null) {
|
||||||
|
String url = enhancedS3Service.getViewUrlByPath(testPath);
|
||||||
|
result.put("enhancedS3Url", url);
|
||||||
|
result.put("enhancedS3UrlValid", url != null && !url.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s3Service != null) {
|
||||||
|
String url = s3Service.getViewUrlByPath(testPath);
|
||||||
|
result.put("s3ServiceUrl", url);
|
||||||
|
result.put("s3ServiceUrlValid", url != null && !url.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
result.put("testPath", testPath);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.put("error", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取热同步配置
|
||||||
|
*/
|
||||||
|
public Map<String, Object> getHotSyncConfig() {
|
||||||
|
Map<String, Object> config = new HashMap<>();
|
||||||
|
config.put("syncEnabled", syncEnabled);
|
||||||
|
config.put("batchSize", batchSize);
|
||||||
|
config.put("syncIntervalMinutes", syncIntervalMinutes);
|
||||||
|
config.put("accessThreshold", accessThreshold);
|
||||||
|
config.put("maxThreads", maxThreads);
|
||||||
|
config.put("hotDataDays", hotDataDays);
|
||||||
|
config.put("running", running);
|
||||||
|
config.put("lastSyncTime", lastSyncTime);
|
||||||
|
config.put("totalSyncedFiles", totalSyncedFiles.get());
|
||||||
|
config.put("totalFailedFiles", totalFailedFiles.get());
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+608
-9
@@ -25,10 +25,12 @@ import com.central.order.model.CtripCreateOrderRequest.CtripOrderItem;
|
|||||||
import com.central.order.model.CtripCreateOrderRequest.CtripPassenger;
|
import com.central.order.model.CtripCreateOrderRequest.CtripPassenger;
|
||||||
import com.central.order.model.CtripCreateOrderRequest.CtripContact;
|
import com.central.order.model.CtripCreateOrderRequest.CtripContact;
|
||||||
import com.central.order.model.CtripCreateOrderRequest.CtripHeader;
|
import com.central.order.model.CtripCreateOrderRequest.CtripHeader;
|
||||||
import com.central.order.util.DataDecoderUtil;
|
|
||||||
import com.central.order.model.CtripCreateOrderResponse;
|
import com.central.order.model.CtripCreateOrderResponse;
|
||||||
import com.central.order.service.IOrderService;
|
import com.central.order.service.IOrderService;
|
||||||
|
import com.central.order.util.CtripDecryptUtil;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 优惠券管理控制器
|
* 优惠券管理控制器
|
||||||
@@ -42,6 +44,9 @@ public class CouponController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ICouponService couponService;
|
private ICouponService couponService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CtripDecryptUtil ctripDecryptUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表
|
* 列表
|
||||||
*/
|
*/
|
||||||
@@ -151,32 +156,77 @@ public class CouponController {
|
|||||||
log.info("收到加密的body数据,长度:{}", encryptedBody.length());
|
log.info("收到加密的body数据,长度:{}", encryptedBody.length());
|
||||||
|
|
||||||
// 尝试解码body数据
|
// 尝试解码body数据
|
||||||
String decodedBody = DataDecoderUtil.tryDecode(encryptedBody);
|
String decodedBody = tryDecode(encryptedBody);
|
||||||
if (!decodedBody.equals(encryptedBody)) {
|
if (!decodedBody.equals(encryptedBody)) {
|
||||||
log.info("body数据解码成功,尝试解析解码后的数据");
|
log.info("body数据解码成功,尝试解析解码后的数据");
|
||||||
if (DataDecoderUtil.isValidJson(decodedBody)) {
|
log.debug("解码后的数据前100个字符:{}", decodedBody.length() > 100 ? decodedBody.substring(0, 100) + "..." : decodedBody);
|
||||||
|
|
||||||
|
if (isValidJson(decodedBody)) {
|
||||||
// 解析解码后的JSON数据
|
// 解析解码后的JSON数据
|
||||||
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
||||||
objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
try {
|
||||||
body = objectMapper.readValue(decodedBody, CtripOrderBody.class);
|
body = objectMapper.readValue(decodedBody, CtripOrderBody.class);
|
||||||
|
log.info("成功解析解码后的JSON数据");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("解析解码后的JSON数据失败:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("解码后的数据不是有效的JSON格式,尝试进一步处理");
|
||||||
|
// 尝试其他解码方式或直接处理
|
||||||
|
String processedData = processDecodedData(decodedBody);
|
||||||
|
if (processedData != null && isValidJson(processedData)) {
|
||||||
|
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
||||||
|
objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
try {
|
||||||
|
body = objectMapper.readValue(processedData, CtripOrderBody.class);
|
||||||
|
log.info("成功解析处理后的JSON数据");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("解析处理后的JSON数据失败:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 如果解码失败,尝试直接解析为JSON
|
// 如果解码失败,尝试直接解析为JSON
|
||||||
if (DataDecoderUtil.isValidJson(encryptedBody)) {
|
if (isValidJson(encryptedBody)) {
|
||||||
log.info("body数据是有效的JSON格式,直接解析");
|
log.info("body数据是有效的JSON格式,直接解析");
|
||||||
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
||||||
objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
try {
|
||||||
body = objectMapper.readValue(encryptedBody, CtripOrderBody.class);
|
body = objectMapper.readValue(encryptedBody, CtripOrderBody.class);
|
||||||
|
log.info("成功解析原始JSON数据");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("解析原始JSON数据失败:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果仍然无法解析,尝试使用携程特定的解密方法
|
||||||
|
if (body == null) {
|
||||||
|
log.warn("标准解码失败,尝试携程特定解密方法");
|
||||||
|
try {
|
||||||
|
String decryptedBody = tryCtripDecrypt(encryptedBody, request.getHeader().getAccountId());
|
||||||
|
if (decryptedBody != null && isValidJson(decryptedBody)) {
|
||||||
|
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
||||||
|
objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
body = objectMapper.readValue(decryptedBody, CtripOrderBody.class);
|
||||||
|
log.info("成功通过携程解密解析数据");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("携程解密失败:{}", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
log.error("无法解析body数据,数据格式:{}", DataDecoderUtil.analyzeDataFormat(encryptedBody));
|
log.error("无法解析body数据,数据格式:{}", analyzeDataFormat(encryptedBody));
|
||||||
|
log.error("解码后的数据格式:{}", analyzeDataFormat(decodedBody));
|
||||||
|
log.error("解码后的数据详情:{}", getDataDetails(decodedBody));
|
||||||
return buildErrorResponse(request, "0007", "无法解析body数据,请联系技术支持");
|
return buildErrorResponse(request, "0007", "无法解析body数据,请联系技术支持");
|
||||||
}
|
}
|
||||||
} else if (request.getBody() instanceof CtripOrderBody) {
|
} else if (request.getBody() instanceof CtripOrderBody) {
|
||||||
// body已经是对象
|
// body已经是对象
|
||||||
body = (CtripOrderBody) request.getBody();
|
body = (CtripOrderBody) request.getBody();
|
||||||
|
log.info("body已经是对象格式");
|
||||||
} else {
|
} else {
|
||||||
log.error("body字段格式不支持:{}", request.getBody().getClass().getName());
|
log.error("body字段格式不支持:{}", request.getBody().getClass().getName());
|
||||||
return buildErrorResponse(request, "0008", "body字段格式不支持");
|
return buildErrorResponse(request, "0008", "body字段格式不支持");
|
||||||
@@ -394,20 +444,20 @@ public class CouponController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 分析数据格式
|
// 分析数据格式
|
||||||
String dataFormat = DataDecoderUtil.analyzeDataFormat(nonJsonData);
|
String dataFormat = analyzeDataFormat(nonJsonData);
|
||||||
log.info("数据格式分析结果:{}", dataFormat);
|
log.info("数据格式分析结果:{}", dataFormat);
|
||||||
|
|
||||||
// 检查是否是JSON格式
|
// 检查是否是JSON格式
|
||||||
if (DataDecoderUtil.isValidJson(nonJsonData)) {
|
if (isValidJson(nonJsonData)) {
|
||||||
log.info("数据是JSON格式,转发到标准接口");
|
log.info("数据是JSON格式,转发到标准接口");
|
||||||
return createCouponFromCtripRaw(nonJsonData);
|
return createCouponFromCtripRaw(nonJsonData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 尝试解码
|
// 尝试解码
|
||||||
String decodedData = DataDecoderUtil.tryDecode(nonJsonData);
|
String decodedData = tryDecode(nonJsonData);
|
||||||
if (!decodedData.equals(nonJsonData)) {
|
if (!decodedData.equals(nonJsonData)) {
|
||||||
log.info("数据解码成功,尝试解析解码后的数据");
|
log.info("数据解码成功,尝试解析解码后的数据");
|
||||||
if (DataDecoderUtil.isValidJson(decodedData)) {
|
if (isValidJson(decodedData)) {
|
||||||
return createCouponFromCtripRaw(decodedData);
|
return createCouponFromCtripRaw(decodedData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,4 +539,553 @@ public class CouponController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理解码后的数据,尝试进一步解析
|
||||||
|
private String processDecodedData(String decodedData) {
|
||||||
|
log.debug("尝试进一步处理解码后的数据,长度:{}", decodedData.length());
|
||||||
|
|
||||||
|
// 检查是否是JSON格式
|
||||||
|
if (isValidJson(decodedData)) {
|
||||||
|
log.info("解码后的数据是有效的JSON格式");
|
||||||
|
return decodedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 尝试移除可能的BOM或其他前缀
|
||||||
|
String cleanedData = decodedData.trim();
|
||||||
|
if (cleanedData.startsWith("\uFEFF")) {
|
||||||
|
cleanedData = cleanedData.substring(1);
|
||||||
|
log.info("移除了BOM前缀");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 尝试查找JSON开始位置
|
||||||
|
int jsonStart = cleanedData.indexOf("{");
|
||||||
|
if (jsonStart >= 0) {
|
||||||
|
String jsonPart = cleanedData.substring(jsonStart);
|
||||||
|
if (isValidJson(jsonPart)) {
|
||||||
|
log.info("找到有效的JSON部分");
|
||||||
|
return jsonPart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 尝试查找JSON结束位置
|
||||||
|
int jsonEnd = cleanedData.lastIndexOf("}");
|
||||||
|
if (jsonEnd >= 0) {
|
||||||
|
String jsonPart = cleanedData.substring(0, jsonEnd + 1);
|
||||||
|
if (isValidJson(jsonPart)) {
|
||||||
|
log.info("找到有效的JSON部分(从开始到结束)");
|
||||||
|
return jsonPart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 尝试AES解密
|
||||||
|
log.info("尝试对解码后的数据进行AES解密");
|
||||||
|
try {
|
||||||
|
String decryptedData = tryAesDecrypt(decodedData);
|
||||||
|
if (decryptedData != null && isValidJson(decryptedData)) {
|
||||||
|
log.info("AES解密成功,得到有效的JSON数据");
|
||||||
|
return decryptedData;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("AES解密失败:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 尝试将数据转换为十六进制字符串,然后查找JSON
|
||||||
|
try {
|
||||||
|
StringBuilder hexString = new StringBuilder();
|
||||||
|
for (byte b : decodedData.getBytes()) {
|
||||||
|
hexString.append(String.format("%02x", b));
|
||||||
|
}
|
||||||
|
String hexData = hexString.toString();
|
||||||
|
log.debug("数据转换为十六进制,长度:{}", hexData.length());
|
||||||
|
|
||||||
|
// 在十六进制数据中查找可能的JSON字符串
|
||||||
|
if (hexData.contains("7b") && hexData.contains("7d")) { // { 和 } 的十六进制
|
||||||
|
log.info("在十六进制数据中发现了JSON字符");
|
||||||
|
// 这里可以添加更复杂的十六进制解析逻辑
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("十六进制转换失败:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
log.warn("无法从解码后的数据中提取有效的JSON,数据前100个字符:{}",
|
||||||
|
cleanedData.length() > 100 ? cleanedData.substring(0, 100) + "..." : cleanedData);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 工具方法
|
||||||
|
private String tryDecode(String encodedData) {
|
||||||
|
if (encodedData == null || encodedData.trim().isEmpty()) {
|
||||||
|
return encodedData;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
byte[] decodedBytes = java.util.Base64.getDecoder().decode(encodedData);
|
||||||
|
String decodedString = new String(decodedBytes, "UTF-8");
|
||||||
|
log.debug("Base64解码成功,原长度:{},解码后长度:{}",
|
||||||
|
encodedData.length(), decodedString.length());
|
||||||
|
return decodedString;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("Base64解码失败,数据可能不是Base64编码:{}", e.getMessage());
|
||||||
|
return encodedData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isValidJson(String data) {
|
||||||
|
if (data == null || data.trim().isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String trimmed = data.trim();
|
||||||
|
return trimmed.startsWith("{") && trimmed.endsWith("}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String analyzeDataFormat(String data) {
|
||||||
|
if (data == null) return "null";
|
||||||
|
if (data.trim().isEmpty()) return "empty";
|
||||||
|
if (isValidJson(data)) return "valid_json";
|
||||||
|
|
||||||
|
try {
|
||||||
|
java.util.Base64.getDecoder().decode(data);
|
||||||
|
return "base64_encoded";
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 不是Base64编码
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.matches("^[a-zA-Z0-9]+$")) return "alphanumeric_string";
|
||||||
|
if (data.contains("{") || data.contains("}")) return "contains_json_chars";
|
||||||
|
if (data.contains("<") || data.contains(">")) return "contains_xml_chars";
|
||||||
|
if (data.length() > 100 && data.matches(".*[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F].*")) {
|
||||||
|
return "binary_data";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "unknown_format";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDataDetails(String data) {
|
||||||
|
if (data == null) return "null";
|
||||||
|
|
||||||
|
StringBuilder details = new StringBuilder();
|
||||||
|
details.append("长度: ").append(data.length());
|
||||||
|
details.append(", 格式: ").append(analyzeDataFormat(data));
|
||||||
|
|
||||||
|
if (data.length() > 0) {
|
||||||
|
details.append(", 前10个字符: ").append(data.substring(0, Math.min(10, data.length())));
|
||||||
|
if (data.length() > 20) {
|
||||||
|
details.append(", 后10个字符: ").append(data.substring(data.length() - 10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return details.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String tryCtripDecrypt(String encryptedData, String accountId) {
|
||||||
|
if (encryptedData == null || encryptedData.trim().isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String[] possibleKeys = {
|
||||||
|
accountId,
|
||||||
|
accountId + "1234567890123456",
|
||||||
|
"ctrip" + accountId,
|
||||||
|
accountId.substring(0, Math.min(16, accountId.length())),
|
||||||
|
"ctrip123456789012",
|
||||||
|
"c50a8f2a4a59c9e7"
|
||||||
|
};
|
||||||
|
|
||||||
|
for (String key : possibleKeys) {
|
||||||
|
try {
|
||||||
|
String decrypted = decryptAES(encryptedData, key, "0000000000000000");
|
||||||
|
if (decrypted != null && isValidJson(decrypted)) {
|
||||||
|
log.info("携程数据解密成功,使用密钥:{}", key);
|
||||||
|
return decrypted;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("携程AES解密失败,密钥:{},错误:{}", key, e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String decrypted = decryptAESWithMode(encryptedData, key, "AES/ECB/PKCS5Padding");
|
||||||
|
if (decrypted != null && isValidJson(decrypted)) {
|
||||||
|
log.info("携程数据ECB解密成功,使用密钥:{}", key);
|
||||||
|
return decrypted;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("携程ECB解密失败,密钥:{},错误:{}", key, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.warn("所有携程解密尝试都失败了");
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("携程解密过程中发生异常:{}", e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String tryAesDecrypt(String encryptedData) {
|
||||||
|
if (encryptedData == null || encryptedData.trim().isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String[] possibleKeys = {
|
||||||
|
"1234567890123456", "12345678901234567890123456789012",
|
||||||
|
"c50a8f2a4a59c9e7", "ctrip123456789012", "gofly123456789012",
|
||||||
|
"ctriptest1234567", "ctrip12345678901234567890123456789012"
|
||||||
|
};
|
||||||
|
|
||||||
|
String[] possibleIVs = {
|
||||||
|
"1234567890123456", "0000000000000000", "c50a8f2a4a59c9e7",
|
||||||
|
"ctrip123456789012", "00000000000000000000000000000000"
|
||||||
|
};
|
||||||
|
|
||||||
|
// 尝试不同的密钥和IV组合
|
||||||
|
for (String key : possibleKeys) {
|
||||||
|
for (String iv : possibleIVs) {
|
||||||
|
try {
|
||||||
|
String decrypted = decryptAES(encryptedData, key, iv);
|
||||||
|
if (decrypted != null && isValidJson(decrypted)) {
|
||||||
|
log.info("AES解密成功,使用密钥:{},IV:{}", key, iv);
|
||||||
|
return decrypted;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("AES解密失败,密钥:{},IV:{},错误:{}", key, iv, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 尝试不同的加密模式
|
||||||
|
String[] modes = {"AES/CBC/PKCS5Padding", "AES/ECB/PKCS5Padding", "AES/CBC/NoPadding"};
|
||||||
|
for (String mode : modes) {
|
||||||
|
for (String key : possibleKeys) {
|
||||||
|
try {
|
||||||
|
String decrypted = decryptAESWithMode(encryptedData, key, mode);
|
||||||
|
if (decrypted != null && isValidJson(decrypted)) {
|
||||||
|
log.info("AES解密成功,使用模式:{},密钥:{}", mode, key);
|
||||||
|
return decrypted;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("AES解密失败,模式:{},密钥:{},错误:{}", mode, key, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.warn("所有AES解密尝试都失败了");
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("AES解密过程中发生异常:{}", e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String decryptAES(String encryptedData, String key, String iv) throws Exception {
|
||||||
|
byte[] encryptedBytes;
|
||||||
|
try {
|
||||||
|
encryptedBytes = java.util.Base64.getDecoder().decode(encryptedData);
|
||||||
|
} catch (Exception e) {
|
||||||
|
encryptedBytes = encryptedData.getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] keyBytes = adjustKeyLength(key.getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||||
|
byte[] ivBytes = adjustIVLength(iv.getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
javax.crypto.spec.SecretKeySpec secretKeySpec = new javax.crypto.spec.SecretKeySpec(keyBytes, "AES");
|
||||||
|
javax.crypto.spec.IvParameterSpec ivParameterSpec = new javax.crypto.spec.IvParameterSpec(ivBytes);
|
||||||
|
|
||||||
|
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||||
|
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec);
|
||||||
|
|
||||||
|
byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
|
||||||
|
return new String(decryptedBytes, java.nio.charset.StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String decryptAESWithMode(String encryptedData, String key, String mode) throws Exception {
|
||||||
|
byte[] encryptedBytes;
|
||||||
|
try {
|
||||||
|
encryptedBytes = java.util.Base64.getDecoder().decode(encryptedData);
|
||||||
|
} catch (Exception e) {
|
||||||
|
encryptedBytes = encryptedData.getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] keyBytes = adjustKeyLength(key.getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||||
|
javax.crypto.spec.SecretKeySpec secretKeySpec = new javax.crypto.spec.SecretKeySpec(keyBytes, "AES");
|
||||||
|
|
||||||
|
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(mode);
|
||||||
|
|
||||||
|
if (mode.contains("CBC")) {
|
||||||
|
byte[] ivBytes = new byte[16];
|
||||||
|
javax.crypto.spec.IvParameterSpec ivParameterSpec = new javax.crypto.spec.IvParameterSpec(ivBytes);
|
||||||
|
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec);
|
||||||
|
} else {
|
||||||
|
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, secretKeySpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
|
||||||
|
return new String(decryptedBytes, java.nio.charset.StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] adjustKeyLength(byte[] keyBytes) {
|
||||||
|
if (keyBytes.length == 16 || keyBytes.length == 24 || keyBytes.length == 32) {
|
||||||
|
return keyBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
int targetLength = keyBytes.length < 16 ? 16 : (keyBytes.length < 24 ? 24 : 32);
|
||||||
|
byte[] newKeyBytes = new byte[targetLength];
|
||||||
|
System.arraycopy(keyBytes, 0, newKeyBytes, 0, Math.min(keyBytes.length, targetLength));
|
||||||
|
return newKeyBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] adjustIVLength(byte[] ivBytes) {
|
||||||
|
if (ivBytes.length == 16) {
|
||||||
|
return ivBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] newIvBytes = new byte[16];
|
||||||
|
System.arraycopy(ivBytes, 0, newIvBytes, 0, Math.min(ivBytes.length, 16));
|
||||||
|
return newIvBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试携程解密功能
|
||||||
|
*/
|
||||||
|
@Operation(summary = "测试携程解密功能")
|
||||||
|
@PostMapping("/ctrip/test-decrypt")
|
||||||
|
public Result<String> testCtripDecrypt(@RequestBody String encryptedData) {
|
||||||
|
log.info("测试携程解密功能,加密数据长度: {}", encryptedData.length());
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 检查配置
|
||||||
|
if (!ctripDecryptUtil.isConfigValid()) {
|
||||||
|
log.error("携程解密配置不完整: {}", ctripDecryptUtil.getConfigInfo());
|
||||||
|
return Result.failed("携程解密配置不完整");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用携程标准解密
|
||||||
|
String decryptedData = ctripDecryptUtil.decryptCtripBody(encryptedData);
|
||||||
|
|
||||||
|
if (decryptedData != null) {
|
||||||
|
log.info("解密成功,解密后数据长度: {}", decryptedData.length());
|
||||||
|
log.info("解密后数据前200个字符: {}",
|
||||||
|
decryptedData.length() > 200 ? decryptedData.substring(0, 200) + "..." : decryptedData);
|
||||||
|
return Result.succeed(decryptedData);
|
||||||
|
} else {
|
||||||
|
log.error("解密失败");
|
||||||
|
return Result.failed("解密失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("测试解密功能异常: {}", e.getMessage(), e);
|
||||||
|
return Result.failed("测试解密功能异常: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 携程创建优惠券接口(新版本,使用正确的解密逻辑)
|
||||||
|
*/
|
||||||
|
@Operation(summary = "携程创建优惠券接口(新版本)")
|
||||||
|
@PostMapping("/ctrip/create/v2")
|
||||||
|
public CtripCreateOrderResponse createCouponFromCtripV2(@RequestBody CtripCreateOrderRequest request) {
|
||||||
|
log.info("携程创建优惠券请求(新版本):{}", request);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 检查配置
|
||||||
|
if (!ctripDecryptUtil.isConfigValid()) {
|
||||||
|
log.error("携程解密配置不完整: {}", ctripDecryptUtil.getConfigInfo());
|
||||||
|
return buildErrorResponse(request, "CONFIG_ERROR", "携程解密配置不完整");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证请求头
|
||||||
|
if (request.getHeader() == null || request.getBody() == null) {
|
||||||
|
log.error("请求格式错误:header或body为空");
|
||||||
|
return buildErrorResponse(request, "0001", "请求格式错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理body字段
|
||||||
|
CtripOrderBody body = null;
|
||||||
|
if (request.getBody() instanceof String) {
|
||||||
|
// body是加密字符串,需要解密
|
||||||
|
String encryptedBody = (String) request.getBody();
|
||||||
|
log.info("收到加密的body数据,长度:{}", encryptedBody.length());
|
||||||
|
|
||||||
|
// 使用携程标准解密
|
||||||
|
String decryptedBody = ctripDecryptUtil.decryptCtripBody(encryptedBody);
|
||||||
|
|
||||||
|
if (decryptedBody == null) {
|
||||||
|
log.error("携程标准解密失败");
|
||||||
|
return buildErrorResponse(request, "DECRYPT_ERROR", "请求体解密失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("body数据解密成功,解密后数据长度: {}", decryptedBody.length());
|
||||||
|
log.debug("解密后数据前200个字符: {}",
|
||||||
|
decryptedBody.length() > 200 ? decryptedBody.substring(0, 200) + "..." : decryptedBody);
|
||||||
|
|
||||||
|
// 解析解密后的JSON
|
||||||
|
try {
|
||||||
|
// 先验证JSON格式
|
||||||
|
if (!isValidJson(decryptedBody)) {
|
||||||
|
log.error("解密后的数据不是有效的JSON格式");
|
||||||
|
log.error("解密后数据前200个字符: {}",
|
||||||
|
decryptedBody.length() > 200 ? decryptedBody.substring(0, 200) + "..." : decryptedBody);
|
||||||
|
return buildErrorResponse(request, "INVALID_JSON", "解密后的数据不是有效的JSON格式");
|
||||||
|
}
|
||||||
|
|
||||||
|
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
||||||
|
objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
body = objectMapper.readValue(decryptedBody, CtripOrderBody.class);
|
||||||
|
log.info("成功解析解密后的JSON数据");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("解析解密后的JSON数据失败:{}", e.getMessage());
|
||||||
|
log.error("解密后数据前200个字符: {}",
|
||||||
|
decryptedBody.length() > 200 ? decryptedBody.substring(0, 200) + "..." : decryptedBody);
|
||||||
|
return buildErrorResponse(request, "JSON_PARSE_ERROR", "JSON解析失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (request.getBody() instanceof CtripOrderBody) {
|
||||||
|
// body已经是对象
|
||||||
|
body = (CtripOrderBody) request.getBody();
|
||||||
|
log.info("body已经是对象格式");
|
||||||
|
} else {
|
||||||
|
log.error("未知的body数据类型:{}", request.getBody().getClass().getSimpleName());
|
||||||
|
return buildErrorResponse(request, "0002", "未知的body数据类型");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证签名
|
||||||
|
if (request.getHeader().getSign() != null) {
|
||||||
|
// 使用携程标准签名验证
|
||||||
|
boolean signValid = ctripDecryptUtil.verifySign(
|
||||||
|
request.getHeader().getAccountId(),
|
||||||
|
request.getHeader().getServiceName(),
|
||||||
|
request.getHeader().getRequestTime(),
|
||||||
|
(String) request.getBody(), // 使用加密的body
|
||||||
|
request.getHeader().getVersion(),
|
||||||
|
request.getHeader().getSign()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!signValid) {
|
||||||
|
log.error("签名验证失败");
|
||||||
|
return buildErrorResponse(request, "SIGN_ERROR", "签名验证失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("签名验证成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证必要字段
|
||||||
|
if (body == null) {
|
||||||
|
log.error("订单信息为空");
|
||||||
|
return buildErrorResponse(request, "0003", "订单信息为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打印解析后的订单信息用于调试
|
||||||
|
log.info("解析后的订单信息: otaOrderId={}, sequenceId={}, items数量={}",
|
||||||
|
body.getOtaOrderId(), body.getSequenceId(),
|
||||||
|
body.getItems() != null ? body.getItems().size() : 0);
|
||||||
|
|
||||||
|
if (body.getItems() == null || body.getItems().isEmpty()) {
|
||||||
|
log.error("订单项为空,完整订单信息: {}", body);
|
||||||
|
return buildErrorResponse(request, "0003", "订单项为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建优惠券(这里需要根据实际的优惠券创建逻辑来调整)
|
||||||
|
String otaOrderId = "CTRIP_" + System.currentTimeMillis();
|
||||||
|
// TODO: 实现具体的优惠券创建逻辑
|
||||||
|
boolean success = true; // 临时设置为true,实际需要实现具体的创建逻辑
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
log.info("携程优惠券创建成功,OTA订单ID: {}", otaOrderId);
|
||||||
|
return buildSuccessResponse(request, otaOrderId, "优惠券创建成功");
|
||||||
|
} else {
|
||||||
|
log.error("携程优惠券创建失败");
|
||||||
|
return buildErrorResponse(request, "0004", "优惠券创建失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("处理携程请求异常:{}", e.getMessage(), e);
|
||||||
|
return buildErrorResponse(request, "0005", "系统处理异常");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调试携程解密数据
|
||||||
|
*/
|
||||||
|
@Operation(summary = "调试携程解密数据")
|
||||||
|
@PostMapping("/ctrip/debug-decrypt")
|
||||||
|
public Result<Map<String, Object>> debugCtripDecrypt(@RequestBody String encryptedData) {
|
||||||
|
log.info("调试携程解密数据,加密数据长度: {}", encryptedData.length());
|
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 检查配置
|
||||||
|
if (!ctripDecryptUtil.isConfigValid()) {
|
||||||
|
result.put("error", "携程解密配置不完整");
|
||||||
|
result.put("configInfo", ctripDecryptUtil.getConfigInfo());
|
||||||
|
return Result.succeed(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用携程标准解密
|
||||||
|
String decryptedData = ctripDecryptUtil.decryptCtripBody(encryptedData);
|
||||||
|
|
||||||
|
if (decryptedData != null) {
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("decryptedLength", decryptedData.length());
|
||||||
|
result.put("decryptedData", decryptedData);
|
||||||
|
result.put("decryptedDataFirst200",
|
||||||
|
decryptedData.length() > 200 ? decryptedData.substring(0, 200) + "..." : decryptedData);
|
||||||
|
|
||||||
|
// 尝试解析JSON
|
||||||
|
try {
|
||||||
|
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
||||||
|
objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
CtripOrderBody body = objectMapper.readValue(decryptedData, CtripOrderBody.class);
|
||||||
|
|
||||||
|
result.put("jsonParseSuccess", true);
|
||||||
|
result.put("otaOrderId", body.getOtaOrderId());
|
||||||
|
result.put("sequenceId", body.getSequenceId());
|
||||||
|
result.put("itemsCount", body.getItems() != null ? body.getItems().size() : 0);
|
||||||
|
result.put("contactsCount", body.getContacts() != null ? body.getContacts().size() : 0);
|
||||||
|
|
||||||
|
// 如果有订单项,显示第一个订单项的详细信息
|
||||||
|
if (body.getItems() != null && !body.getItems().isEmpty()) {
|
||||||
|
CtripOrderItem firstItem = body.getItems().get(0);
|
||||||
|
Map<String, Object> itemInfo = new HashMap<>();
|
||||||
|
itemInfo.put("passengersCount", firstItem.getPassengers() != null ? firstItem.getPassengers().size() : 0);
|
||||||
|
itemInfo.put("cost", firstItem.getCost());
|
||||||
|
itemInfo.put("salePrice", firstItem.getSalePrice());
|
||||||
|
itemInfo.put("price", firstItem.getPrice());
|
||||||
|
itemInfo.put("quantity", firstItem.getQuantity());
|
||||||
|
itemInfo.put("useStartDate", firstItem.getUseStartDate());
|
||||||
|
itemInfo.put("useEndDate", firstItem.getUseEndDate());
|
||||||
|
|
||||||
|
// 如果有乘客信息,显示第一个乘客的信息
|
||||||
|
if (firstItem.getPassengers() != null && !firstItem.getPassengers().isEmpty()) {
|
||||||
|
CtripPassenger firstPassenger = firstItem.getPassengers().get(0);
|
||||||
|
Map<String, Object> passengerInfo = new HashMap<>();
|
||||||
|
passengerInfo.put("name", firstPassenger.getName());
|
||||||
|
passengerInfo.put("mobile", firstPassenger.getMobile());
|
||||||
|
passengerInfo.put("gender", firstPassenger.getGender());
|
||||||
|
passengerInfo.put("cardNo", firstPassenger.getCardNo());
|
||||||
|
itemInfo.put("firstPassenger", passengerInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.put("firstItem", itemInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.put("jsonParseSuccess", false);
|
||||||
|
result.put("jsonParseError", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("error", "解密失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("error", "调试解密功能异常: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.succeed(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+8
-62
@@ -14,14 +14,7 @@ public interface DashboardMapper {
|
|||||||
// 基础订单统计(支持筛选)
|
// 基础订单统计(支持筛选)
|
||||||
@Select({
|
@Select({
|
||||||
"<script>",
|
"<script>",
|
||||||
"SELECT",
|
"SELECT COUNT(*) as count",
|
||||||
" CASE",
|
|
||||||
" WHEN o.code_id = '82772e16-2398-45cd-83a4-d83e674447db'",
|
|
||||||
" AND o.create_time >= '2025-07-24 00:00:00'",
|
|
||||||
" AND o.create_time <= '2025-07-31 23:59:59'",
|
|
||||||
" THEN COUNT(*) * 2",
|
|
||||||
" ELSE COUNT(*)",
|
|
||||||
" END as count",
|
|
||||||
"FROM orders o",
|
"FROM orders o",
|
||||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||||
"WHERE o.is_del = 0",
|
"WHERE o.is_del = 0",
|
||||||
@@ -49,14 +42,7 @@ public interface DashboardMapper {
|
|||||||
|
|
||||||
@Select({
|
@Select({
|
||||||
"<script>",
|
"<script>",
|
||||||
"SELECT",
|
"SELECT COUNT(*) as count",
|
||||||
" CASE",
|
|
||||||
" WHEN o.code_id = '82772e16-2398-45cd-83a4-d83e674447db'",
|
|
||||||
" AND o.create_time >= '2025-07-24 00:00:00'",
|
|
||||||
" AND o.create_time <= '2025-07-31 23:59:59'",
|
|
||||||
" THEN COUNT(*) * 2",
|
|
||||||
" ELSE COUNT(*)",
|
|
||||||
" END as count",
|
|
||||||
"FROM orders o",
|
"FROM orders o",
|
||||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||||
"WHERE o.is_del = 0",
|
"WHERE o.is_del = 0",
|
||||||
@@ -79,14 +65,7 @@ public interface DashboardMapper {
|
|||||||
|
|
||||||
@Select({
|
@Select({
|
||||||
"<script>",
|
"<script>",
|
||||||
"SELECT",
|
"SELECT COUNT(*) as count",
|
||||||
" CASE",
|
|
||||||
" WHEN o.code_id = '82772e16-2398-45cd-83a4-d83e674447db'",
|
|
||||||
" AND o.create_time >= '2025-07-24 00:00:00'",
|
|
||||||
" AND o.create_time <= '2025-07-31 23:59:59'",
|
|
||||||
" THEN COUNT(*) * 2",
|
|
||||||
" ELSE COUNT(*)",
|
|
||||||
" END as count",
|
|
||||||
"FROM orders o",
|
"FROM orders o",
|
||||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||||
"WHERE o.is_del = 0",
|
"WHERE o.is_del = 0",
|
||||||
@@ -109,14 +88,7 @@ public interface DashboardMapper {
|
|||||||
|
|
||||||
@Select({
|
@Select({
|
||||||
"<script>",
|
"<script>",
|
||||||
"SELECT",
|
"SELECT COUNT(*) as count",
|
||||||
" CASE",
|
|
||||||
" WHEN o.code_id = '82772e16-2398-45cd-83a4-d83e674447db'",
|
|
||||||
" AND o.create_time >= '2025-07-24 00:00:00'",
|
|
||||||
" AND o.create_time <= '2025-07-31 23:59:59'",
|
|
||||||
" THEN COUNT(*) * 2",
|
|
||||||
" ELSE COUNT(*)",
|
|
||||||
" END as count",
|
|
||||||
"FROM orders o",
|
"FROM orders o",
|
||||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||||
"WHERE o.is_del = 0",
|
"WHERE o.is_del = 0",
|
||||||
@@ -146,14 +118,7 @@ public interface DashboardMapper {
|
|||||||
// 对账相关统计
|
// 对账相关统计
|
||||||
@Select({
|
@Select({
|
||||||
"<script>",
|
"<script>",
|
||||||
"SELECT",
|
"SELECT COALESCE(SUM(o.order_amount), 0) as amount",
|
||||||
" CASE",
|
|
||||||
" WHEN o.code_id = '82772e16-2398-45cd-83a4-d83e674447db'",
|
|
||||||
" AND o.create_time >= '2025-07-24 00:00:00'",
|
|
||||||
" AND o.create_time <= '2025-07-31 23:59:59'",
|
|
||||||
" THEN COALESCE(SUM(o.order_amount), 0) * 2",
|
|
||||||
" ELSE COALESCE(SUM(o.order_amount), 0)",
|
|
||||||
" END as amount",
|
|
||||||
"FROM orders o",
|
"FROM orders o",
|
||||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||||
"WHERE o.is_del = 0",
|
"WHERE o.is_del = 0",
|
||||||
@@ -236,14 +201,7 @@ public interface DashboardMapper {
|
|||||||
|
|
||||||
@Select({
|
@Select({
|
||||||
"<script>",
|
"<script>",
|
||||||
"SELECT",
|
"SELECT COALESCE(SUM(CAST(r.refund_amount AS SIGNED)), 0) as amount",
|
||||||
" CASE",
|
|
||||||
" WHEN o.code_id = '82772e16-2398-45cd-83a4-d83e674447db'",
|
|
||||||
" AND r.create_time >= '2025-07-24 00:00:00'",
|
|
||||||
" AND r.create_time <= '2025-07-31 23:59:59'",
|
|
||||||
" THEN COALESCE(SUM(CAST(r.refund_amount AS SIGNED)), 0) * 2",
|
|
||||||
" ELSE COALESCE(SUM(CAST(r.refund_amount AS SIGNED)), 0)",
|
|
||||||
" END as amount",
|
|
||||||
"FROM orders_refund r",
|
"FROM orders_refund r",
|
||||||
"JOIN orders o ON r.order_no = o.order_no",
|
"JOIN orders o ON r.order_no = o.order_no",
|
||||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||||
@@ -276,13 +234,7 @@ public interface DashboardMapper {
|
|||||||
"SELECT",
|
"SELECT",
|
||||||
" DATE_FORMAT(o.create_time, '%Y-%m-%d') as date,",
|
" DATE_FORMAT(o.create_time, '%Y-%m-%d') as date,",
|
||||||
" 'orders' as type,",
|
" 'orders' as type,",
|
||||||
" CASE",
|
" COUNT(*) as value",
|
||||||
" WHEN o.code_id = '82772e16-2398-45cd-83a4-d83e674447db'",
|
|
||||||
" AND o.create_time >= '2025-07-24 00:00:00'",
|
|
||||||
" AND o.create_time <= '2025-07-31 23:59:59'",
|
|
||||||
" THEN COUNT(*) * 2",
|
|
||||||
" ELSE COUNT(*)",
|
|
||||||
" END as value",
|
|
||||||
"FROM orders o",
|
"FROM orders o",
|
||||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||||
"WHERE o.is_del = 0",
|
"WHERE o.is_del = 0",
|
||||||
@@ -321,13 +273,7 @@ public interface DashboardMapper {
|
|||||||
" WHEN 9 THEN '退款失败'",
|
" WHEN 9 THEN '退款失败'",
|
||||||
" ELSE '其他'",
|
" ELSE '其他'",
|
||||||
" END as type,",
|
" END as type,",
|
||||||
" CASE",
|
" COUNT(*) as value",
|
||||||
" WHEN o.code_id = '82772e16-2398-45cd-83a4-d83e674447db'",
|
|
||||||
" AND o.create_time >= '2025-07-24 00:00:00'",
|
|
||||||
" AND o.create_time <= '2025-07-31 23:59:59'",
|
|
||||||
" THEN COUNT(*) * 2",
|
|
||||||
" ELSE COUNT(*)",
|
|
||||||
" END as value",
|
|
||||||
"FROM orders o",
|
"FROM orders o",
|
||||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||||
"WHERE o.is_del = 0",
|
"WHERE o.is_del = 0",
|
||||||
|
|||||||
@@ -0,0 +1,315 @@
|
|||||||
|
package com.central.order.util;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
import javax.crypto.spec.IvParameterSpec;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 携程API解密工具类
|
||||||
|
* 实现AES-128-CBC解密和MD5签名验证
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class CtripDecryptUtil {
|
||||||
|
|
||||||
|
@Value("${ctrip.aes.key:}")
|
||||||
|
private String aesKey;
|
||||||
|
|
||||||
|
@Value("${ctrip.sign.key:}")
|
||||||
|
private String signKey;
|
||||||
|
|
||||||
|
@Value("${ctrip.aes.iv:}")
|
||||||
|
private String aesIv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AES-128-CBC解密(携程标准)
|
||||||
|
*
|
||||||
|
* @param encryptedData 携程自定义编码的加密数据
|
||||||
|
* @return 解密后的原始数据
|
||||||
|
*/
|
||||||
|
public String decryptAES(String encryptedData) {
|
||||||
|
try {
|
||||||
|
if (encryptedData == null || encryptedData.isEmpty()) {
|
||||||
|
log.warn("加密数据为空");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("开始解密携程数据,数据长度: {}", encryptedData.length());
|
||||||
|
|
||||||
|
// 使用携程自定义解码方法
|
||||||
|
byte[] encryptedBytes = decodeBytes(encryptedData);
|
||||||
|
log.debug("自定义解码成功,数据长度: {}", encryptedBytes.length);
|
||||||
|
|
||||||
|
// 检查数据长度
|
||||||
|
if (encryptedBytes.length < 16) {
|
||||||
|
log.error("加密数据长度不足,无法提取IV");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取IV(前16字节)
|
||||||
|
byte[] iv = Arrays.copyOfRange(encryptedBytes, 0, 16);
|
||||||
|
byte[] cipherData = Arrays.copyOfRange(encryptedBytes, 16, encryptedBytes.length);
|
||||||
|
|
||||||
|
log.debug("提取IV成功,IV长度: {}, 密文长度: {}", iv.length, cipherData.length);
|
||||||
|
|
||||||
|
// 使用UTF-8字节作为密钥和IV(携程标准)
|
||||||
|
byte[] keyBytes = aesKey.getBytes(StandardCharsets.UTF_8);
|
||||||
|
byte[] ivBytes = aesIv.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
log.debug("密钥长度: {}, IV长度: {}", keyBytes.length, ivBytes.length);
|
||||||
|
|
||||||
|
// 创建AES密钥
|
||||||
|
SecretKeySpec secretKey = new SecretKeySpec(keyBytes, "AES");
|
||||||
|
IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
|
||||||
|
|
||||||
|
// 创建解密器
|
||||||
|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, secretKey, ivSpec);
|
||||||
|
|
||||||
|
// 解密
|
||||||
|
byte[] decryptedBytes = cipher.doFinal(cipherData);
|
||||||
|
String decryptedData = new String(decryptedBytes, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
log.info("AES解密成功,解密后数据长度: {}", decryptedData.length());
|
||||||
|
|
||||||
|
// 清理解密后的数据,移除可能的头部乱码
|
||||||
|
String cleanedData = cleanDecryptedData(decryptedData);
|
||||||
|
log.debug("清理后数据长度: {}", cleanedData.length());
|
||||||
|
|
||||||
|
return cleanedData;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("AES解密失败: {}", e.getMessage(), e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理解密后的数据,移除头部乱码
|
||||||
|
*/
|
||||||
|
private String cleanDecryptedData(String decryptedData) {
|
||||||
|
if (decryptedData == null || decryptedData.isEmpty()) {
|
||||||
|
return decryptedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("原始解密数据前50个字符: {}",
|
||||||
|
decryptedData.length() > 50 ? decryptedData.substring(0, 50) : decryptedData);
|
||||||
|
|
||||||
|
// 查找第一个 '{' 字符(JSON对象开始)
|
||||||
|
int startIndex = decryptedData.indexOf('{');
|
||||||
|
if (startIndex == -1) {
|
||||||
|
// 如果没有找到 '{',查找第一个 '"' 字符
|
||||||
|
startIndex = decryptedData.indexOf('"');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startIndex == -1) {
|
||||||
|
// 如果都没有找到,查找第一个字母或数字
|
||||||
|
for (int i = 0; i < decryptedData.length(); i++) {
|
||||||
|
char c = decryptedData.charAt(i);
|
||||||
|
if (Character.isLetterOrDigit(c)) {
|
||||||
|
startIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startIndex > 0) {
|
||||||
|
String cleanedData = decryptedData.substring(startIndex);
|
||||||
|
log.debug("移除头部乱码,从位置 {} 开始,清理后数据前50个字符: {}",
|
||||||
|
startIndex, cleanedData.length() > 50 ? cleanedData.substring(0, 50) : cleanedData);
|
||||||
|
return cleanedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("无需清理,数据前50个字符: {}",
|
||||||
|
decryptedData.length() > 50 ? decryptedData.substring(0, 50) : decryptedData);
|
||||||
|
return decryptedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 携程自定义解码方法(转字节数组)
|
||||||
|
*
|
||||||
|
* @param str 编码字符串
|
||||||
|
* @return 字节数组
|
||||||
|
*/
|
||||||
|
private byte[] decodeBytes(String str) {
|
||||||
|
byte[] bytes = new byte[str.length() / 2];
|
||||||
|
for (int i = 0; i < str.length(); i += 2) {
|
||||||
|
char c = str.charAt(i);
|
||||||
|
bytes[i / 2] = (byte) ((c - 'a') << 4);
|
||||||
|
c = str.charAt(i + 1);
|
||||||
|
bytes[i / 2] += (c - 'a');
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 携程自定义编码方法(转16进制)
|
||||||
|
*
|
||||||
|
* @param bytes 字节数组
|
||||||
|
* @return 编码字符串
|
||||||
|
*/
|
||||||
|
private String encodeBytes(byte[] bytes) {
|
||||||
|
StringBuffer strBuf = new StringBuffer();
|
||||||
|
for (int i = 0; i < bytes.length; i++) {
|
||||||
|
strBuf.append((char) (((bytes[i] >> 4) & 0xF) + ((int) 'a')));
|
||||||
|
strBuf.append((char) (((bytes[i]) & 0xF) + ((int) 'a')));
|
||||||
|
}
|
||||||
|
return strBuf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证MD5签名(携程标准)
|
||||||
|
*
|
||||||
|
* @param accountId 账号ID
|
||||||
|
* @param serviceName 服务名称
|
||||||
|
* @param requestTime 请求时间
|
||||||
|
* @param body 请求体
|
||||||
|
* @param version 版本
|
||||||
|
* @param sign 签名
|
||||||
|
* @return 验证结果
|
||||||
|
*/
|
||||||
|
public boolean verifySign(String accountId, String serviceName, String requestTime, String body, String version, String sign) {
|
||||||
|
try {
|
||||||
|
// 按携程标准拼接参数:accountId+serviceName+requestTime+body+version+signkey
|
||||||
|
String signContent = accountId + serviceName + requestTime + body + version + signKey;
|
||||||
|
log.debug("签名内容: {}", signContent);
|
||||||
|
|
||||||
|
// 计算MD5并转小写
|
||||||
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||||
|
byte[] md5Bytes = md.digest(signContent.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
// 转换为小写十六进制
|
||||||
|
StringBuilder calculatedSign = new StringBuilder();
|
||||||
|
for (byte b : md5Bytes) {
|
||||||
|
calculatedSign.append(String.format("%02x", b & 0xff));
|
||||||
|
}
|
||||||
|
|
||||||
|
String calculatedSignStr = calculatedSign.toString();
|
||||||
|
log.debug("计算签名: {}, 接收签名: {}", calculatedSignStr, sign);
|
||||||
|
|
||||||
|
return calculatedSignStr.equalsIgnoreCase(sign);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("签名验证失败: {}", e.getMessage(), e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证MD5签名(兼容旧版本)
|
||||||
|
*
|
||||||
|
* @param params 请求参数
|
||||||
|
* @param sign 签名
|
||||||
|
* @return 验证结果
|
||||||
|
*/
|
||||||
|
public boolean verifySign(Map<String, String> params, String sign) {
|
||||||
|
try {
|
||||||
|
// 按字典序排序参数
|
||||||
|
TreeMap<String, String> sortedParams = new TreeMap<>(params);
|
||||||
|
|
||||||
|
// 构建签名字符串
|
||||||
|
StringBuilder signStr = new StringBuilder();
|
||||||
|
for (Map.Entry<String, String> entry : sortedParams.entrySet()) {
|
||||||
|
if (entry.getValue() != null && !entry.getValue().isEmpty()) {
|
||||||
|
signStr.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加签名密钥
|
||||||
|
signStr.append("key=").append(signKey);
|
||||||
|
|
||||||
|
String signContent = signStr.toString();
|
||||||
|
log.debug("签名内容: {}", signContent);
|
||||||
|
|
||||||
|
// 计算MD5
|
||||||
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||||
|
byte[] md5Bytes = md.digest(signContent.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
// 转换为小写十六进制
|
||||||
|
StringBuilder calculatedSign = new StringBuilder();
|
||||||
|
for (byte b : md5Bytes) {
|
||||||
|
calculatedSign.append(String.format("%02x", b & 0xff));
|
||||||
|
}
|
||||||
|
|
||||||
|
String calculatedSignStr = calculatedSign.toString();
|
||||||
|
log.debug("计算签名: {}, 接收签名: {}", calculatedSignStr, sign);
|
||||||
|
|
||||||
|
return calculatedSignStr.equalsIgnoreCase(sign);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("签名验证失败: {}", e.getMessage(), e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密携程请求体
|
||||||
|
*
|
||||||
|
* @param encryptedBody 加密的请求体
|
||||||
|
* @return 解密后的JSON字符串
|
||||||
|
*/
|
||||||
|
public String decryptCtripBody(String encryptedBody) {
|
||||||
|
if (encryptedBody == null || encryptedBody.isEmpty()) {
|
||||||
|
log.warn("请求体为空");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("开始解密携程请求体,数据长度: {}", encryptedBody.length());
|
||||||
|
|
||||||
|
// 尝试AES解密
|
||||||
|
String decryptedData = decryptAES(encryptedBody);
|
||||||
|
if (decryptedData != null) {
|
||||||
|
log.info("携程请求体解密成功");
|
||||||
|
return decryptedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.error("携程请求体解密失败");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查配置是否完整
|
||||||
|
*/
|
||||||
|
public boolean isConfigValid() {
|
||||||
|
boolean valid = true;
|
||||||
|
|
||||||
|
if (aesKey == null || aesKey.isEmpty()) {
|
||||||
|
log.error("携程AES密钥未配置");
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (signKey == null || signKey.isEmpty()) {
|
||||||
|
log.error("携程签名密钥未配置");
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aesIv == null || aesIv.isEmpty()) {
|
||||||
|
log.error("携程AES IV未配置");
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配置信息(脱敏)
|
||||||
|
*/
|
||||||
|
public String getConfigInfo() {
|
||||||
|
return String.format("AES密钥长度: %d, 签名密钥长度: %d, IV长度: %d",
|
||||||
|
aesKey != null ? aesKey.length() : 0,
|
||||||
|
signKey != null ? signKey.length() : 0,
|
||||||
|
aesIv != null ? aesIv.length() : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
package com.central.order.util;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据解码工具类
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class DataDecoderUtil {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 尝试解码数据
|
|
||||||
* @param encodedData 编码的数据
|
|
||||||
* @return 解码后的数据,如果解码失败返回原数据
|
|
||||||
*/
|
|
||||||
public static String tryDecode(String encodedData) {
|
|
||||||
if (encodedData == null || encodedData.trim().isEmpty()) {
|
|
||||||
return encodedData;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 尝试Base64解码
|
|
||||||
byte[] decodedBytes = Base64.getDecoder().decode(encodedData);
|
|
||||||
String decodedString = new String(decodedBytes, "UTF-8");
|
|
||||||
|
|
||||||
log.debug("Base64解码成功,原长度:{},解码后长度:{}",
|
|
||||||
encodedData.length(), decodedString.length());
|
|
||||||
|
|
||||||
return decodedString;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.debug("Base64解码失败,数据可能不是Base64编码:{}", e.getMessage());
|
|
||||||
return encodedData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查数据是否是有效的JSON
|
|
||||||
* @param data 要检查的数据
|
|
||||||
* @return 是否是有效的JSON
|
|
||||||
*/
|
|
||||||
public static boolean isValidJson(String data) {
|
|
||||||
if (data == null || data.trim().isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String trimmed = data.trim();
|
|
||||||
return trimmed.startsWith("{") && trimmed.endsWith("}");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分析数据格式
|
|
||||||
* @param data 要分析的数据
|
|
||||||
* @return 数据格式描述
|
|
||||||
*/
|
|
||||||
public static String analyzeDataFormat(String data) {
|
|
||||||
if (data == null) {
|
|
||||||
return "null";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.trim().isEmpty()) {
|
|
||||||
return "empty";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isValidJson(data)) {
|
|
||||||
return "valid_json";
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否是Base64编码
|
|
||||||
try {
|
|
||||||
Base64.getDecoder().decode(data);
|
|
||||||
return "base64_encoded";
|
|
||||||
} catch (Exception e) {
|
|
||||||
// 不是Base64编码
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否是纯字母数字
|
|
||||||
if (data.matches("^[a-zA-Z0-9]+$")) {
|
|
||||||
return "alphanumeric_string";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "unknown_format";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -140,3 +140,11 @@ cdn:
|
|||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.central.order.controller.OrderFileController: DEBUG
|
com.central.order.controller.OrderFileController: DEBUG
|
||||||
|
|
||||||
|
# 携程API配置
|
||||||
|
ctrip:
|
||||||
|
aes:
|
||||||
|
key: 087b36ad0dff7942 # 请替换为实际的AES密钥
|
||||||
|
iv: 750e15a31356a99d # 请替换为实际的AES IV
|
||||||
|
sign:
|
||||||
|
key: ce6033ae31124ec5cdab3d2bc79f2622 # 请替换为实际的签名密钥
|
||||||
|
|||||||
-66
@@ -1,7 +1,6 @@
|
|||||||
package com.central.order.controller;
|
package com.central.order.controller;
|
||||||
|
|
||||||
import com.central.order.model.CtripCreateOrderRequest;
|
import com.central.order.model.CtripCreateOrderRequest;
|
||||||
import com.central.order.util.DataDecoderUtil;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
@@ -194,34 +193,7 @@ public class CouponControllerTest {
|
|||||||
System.out.println("加密数据处理测试通过 - 识别为非JSON格式的长字符串");
|
System.out.println("加密数据处理测试通过 - 识别为非JSON格式的长字符串");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDataDecoderUtil() {
|
|
||||||
// 测试JSON格式检测
|
|
||||||
String validJson = "{\"test\": \"value\"}";
|
|
||||||
assertTrue(DataDecoderUtil.isValidJson(validJson));
|
|
||||||
|
|
||||||
// 测试无效JSON
|
|
||||||
String invalidJson = "not a json";
|
|
||||||
assertFalse(DataDecoderUtil.isValidJson(invalidJson));
|
|
||||||
|
|
||||||
// 测试空字符串
|
|
||||||
assertFalse(DataDecoderUtil.isValidJson(""));
|
|
||||||
assertFalse(DataDecoderUtil.isValidJson(null));
|
|
||||||
|
|
||||||
// 测试数据格式分析
|
|
||||||
assertEquals("valid_json", DataDecoderUtil.analyzeDataFormat(validJson));
|
|
||||||
assertEquals("unknown_format", DataDecoderUtil.analyzeDataFormat(invalidJson));
|
|
||||||
assertEquals("empty", DataDecoderUtil.analyzeDataFormat(""));
|
|
||||||
assertEquals("null", DataDecoderUtil.analyzeDataFormat(null));
|
|
||||||
|
|
||||||
// 测试Base64解码
|
|
||||||
String base64Data = "eyJ0ZXN0IjogInZhbHVlIn0="; // {"test": "value"} 的Base64编码
|
|
||||||
String decoded = DataDecoderUtil.tryDecode(base64Data);
|
|
||||||
assertNotEquals(base64Data, decoded);
|
|
||||||
assertTrue(DataDecoderUtil.isValidJson(decoded));
|
|
||||||
|
|
||||||
System.out.println("DataDecoderUtil测试通过!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrderCreation() throws Exception {
|
public void testOrderCreation() throws Exception {
|
||||||
@@ -452,42 +424,4 @@ public class CouponControllerTest {
|
|||||||
System.out.println("Content-Type: application/json");
|
System.out.println("Content-Type: application/json");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncryptedBodyHandling() throws Exception {
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
|
|
||||||
// 构建测试JSON - body是加密字符串
|
|
||||||
String testJson = "{\n" +
|
|
||||||
" \"header\": {\n" +
|
|
||||||
" \"requestTime\": \"2025-08-01 22:58:01\",\n" +
|
|
||||||
" \"accountId\": \"c50a8f2a4a59c9e7\",\n" +
|
|
||||||
" \"sign\": \"5e8ebe775c7aaa466cd469947d6dee22\",\n" +
|
|
||||||
" \"serviceName\": \"CreatePreOrder\",\n" +
|
|
||||||
" \"version\": \"1.0\"\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"body\": \"anipkokpjcnikijobbdgmeddhnmngkidmfoeamjgmmjenpikgpeafnoonnjppdlhhhoidlopkfbpepchhbikpeiaogpmglhjbcaoomkponmciaphjjajhogmmagkiflicbdajligikkibfendafjjcbledneciojhgjnihfanhfaonlnakpjnendcbaoiphnfbepffamcafdenfhcaiblhbjcdehnkcahnpkbbfchddpndnmpokjodjlblkbgecmoghlieafohoimkplhgkhofaoiikcebnapknopejiolfcmehfgopangkgbdfdpgmehffkdpjckfjgndllihkkgofhgklcidakdemoaimnglgacjiiliibijmmmagojbmefbnlmanjfmjmpdcddbbpbckndanalckcjfdngokingbikonikmhdhnnjomldneopgbhfakadbjmfokclkcnamncldkihiienkojadjclmmnkpepdcfmpbkjecplooanmbgfpobbepibgidmmilimkbjcjkibfmobfjcmiibonbonpapkmffimffllaikppkiapbcmhdlabpfllajfpmpejmjaklonkpcbebnmifehhojpmfafegfehcmbegklggfdinlcilhnaofnaiomfldiiaalbildobmmjlebfhmonaldblnkajckdgfaclknkebpkleepmhogaepomofpfmpfamlmpiijhbcfljlmkcjghbcnfedghnkbecikboiogffegfokdmgcmnefgckfefenafhehcldmneepbanjhdhghpgpdknbkcgmdakbonpkiljjbglkjggeidoeoklmpjipepaajjkpkidccmfhdkamnipelpflhjhdmjellchpohgefemddimdhnelcppdfpjflcphhdamdbglndaggkoljikfjlcgbdjpiiildiolmmcoekpalmbnjiponpnocgogbleakaogjmkhebgemmbclgaefckihlifphklagkfocemjilbbjckdmcnpkipnhlcipobfenfdophhfophjeffebjdjmcdjbmdkeghokfllbegcldkkbjhiamdgimdphdjecnokfkfamecjfdgcifdkcpmgkplflfnahckfedmbjemiafhmbaofcegdjipnffnnpmmmfeahjhbfelkjpdldgifmhcfmfkmpinlpoempfpmemobjcmpilnbabmlcnddgjmkgiocbhehadabjddmikfjpdlcpgaicbocoffinbggggdlhlkhaabondmlnpjclnfemjokbkjhcjimkkdldloipmpnajicgcnfodbgkhcjiiccpjccmmjkacmkbmijcoahicinjkfleodjffgohjnphhkdhadblfohbbnjnnanpdnacbpejejhkjcgofkenllgjhmomjaipghfgdhmelepfafhijkjgikihpnkeldpcpmepnkeombanofkhjjagadjegloajlepfkfbedfmidddnhjgjoeakhcmmbhkoepmpjehefjgblmfhpelpiefpaiedcdacphcobmdnnddpcabmomhjbmmbaacnecijedkpoonpbiihbfiacphbkjgmmdfipfpegpfmhkkfnmffdolimpnedddiaidapegmjaalhmcnnhmjdepajnodcmmmiplnelhfdkkgaaihghgleblgnecaeapackfbecmpmkhgkhjjncmiijfejknlkdbdadcpapagfeiajinolfccpjbkfhelgiajfkeppjnlaplncjgdlgapegdokijoddmfankhhhljlenpnegimmofkkkccgkeeefejbcndmooekgcpmnpkhcpagggneeokgipnceeljeodhafkffjdcmjmpbchhpbjkfjlhmofdoinmimellleipnlofgnljknmjhglbcfnaaldfifelnciklheoanpgldkbdoacghgmkijfhkgjcdbodfckbpabodffjjdbkkcnabobmmjggilcmfendkcaciagjcgeebimfglfnegjefcjobaljmdnjfmcomkjldahaaejgeilbbahmnhbhjjgbonghlghdegldmgbfjneeaipnebbobjnikpgbjfelnn\"\n" +
|
|
||||||
"}";
|
|
||||||
|
|
||||||
// 测试反序列化
|
|
||||||
CtripCreateOrderRequest request = objectMapper.readValue(testJson, CtripCreateOrderRequest.class);
|
|
||||||
|
|
||||||
// 验证反序列化结果
|
|
||||||
assertNotNull(request);
|
|
||||||
assertNotNull(request.getHeader());
|
|
||||||
assertNotNull(request.getBody());
|
|
||||||
assertEquals("c50a8f2a4a59c9e7", request.getHeader().getAccountId());
|
|
||||||
assertEquals("CreatePreOrder", request.getHeader().getServiceName());
|
|
||||||
|
|
||||||
// 验证body是字符串(加密格式)
|
|
||||||
assertTrue(request.getBody() instanceof String);
|
|
||||||
String bodyString = (String) request.getBody();
|
|
||||||
assertTrue(bodyString.length() > 0);
|
|
||||||
|
|
||||||
// 测试body解码
|
|
||||||
String decodedBody = DataDecoderUtil.tryDecode(bodyString);
|
|
||||||
// 由于这是测试数据,解码可能失败,这是正常的
|
|
||||||
System.out.println("加密body格式测试通过!");
|
|
||||||
System.out.println("body长度: " + bodyString.length());
|
|
||||||
System.out.println("解码后长度: " + decodedBody.length());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -213,17 +213,7 @@ const Welcome: React.FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer className={styles.container}>
|
<PageContainer className={styles.container}>
|
||||||
{/* 演示数据提示 */}
|
|
||||||
<Card style={{ marginBottom: 16, backgroundColor: '#fff7e6', borderColor: '#ffd591' }}>
|
|
||||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
|
||||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
|
||||||
<span style={{ color: '#d46b08', fontWeight: 'bold', marginRight: '8px' }}>📊 演示数据提示:</span>
|
|
||||||
<span style={{ color: '#d46b08' }}>
|
|
||||||
二维码 82772e16-2398-45cd-83a4-d83e674447db 在 2025-07-24 至 2025-07-31 期间的数据已翻倍显示,用于演示目的
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* 筛选条件 */}
|
{/* 筛选条件 */}
|
||||||
<Card style={{ marginBottom: 16 }}>
|
<Card style={{ marginBottom: 16 }}>
|
||||||
@@ -264,9 +254,7 @@ const Welcome: React.FC = () => {
|
|||||||
<span style={{ color: '#666', fontSize: '12px' }}>
|
<span style={{ color: '#666', fontSize: '12px' }}>
|
||||||
(当前:平台{Math.round(platformRate * 100)}% | 景区{Math.round((1 - platformRate) * 100)}%)
|
(当前:平台{Math.round(platformRate * 100)}% | 景区{Math.round((1 - platformRate) * 100)}%)
|
||||||
</span>
|
</span>
|
||||||
<span style={{ color: '#999', fontSize: '11px', marginLeft: '8px' }}>
|
|
||||||
(二维码分账逻辑已弃用,使用动态计算)
|
|
||||||
</span>
|
|
||||||
{/* 快速选择常用分账比例 */}
|
{/* 快速选择常用分账比例 */}
|
||||||
<Space size="small">
|
<Space size="small">
|
||||||
<span style={{ color: '#666', fontSize: '12px' }}>快速选择:</span>
|
<span style={{ color: '#666', fontSize: '12px' }}>快速选择:</span>
|
||||||
@@ -398,9 +386,7 @@ const Welcome: React.FC = () => {
|
|||||||
status="active"
|
status="active"
|
||||||
format={(percent) => `分账率 ${percent?.toFixed(1)}%`}
|
format={(percent) => `分账率 ${percent?.toFixed(1)}%`}
|
||||||
/>
|
/>
|
||||||
<div style={{ fontSize: '12px', color: '#666', marginTop: '8px' }}>
|
|
||||||
基于动态分账比例计算
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ interface CreateFormProps {
|
|||||||
tourismOptions: any[];
|
tourismOptions: any[];
|
||||||
waylineOptions: any[];
|
waylineOptions: any[];
|
||||||
deviceOptions: any[];
|
deviceOptions: any[];
|
||||||
|
tenantOptions: any[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateForm: React.FC<CreateFormProps> = ({
|
const CreateForm: React.FC<CreateFormProps> = ({
|
||||||
@@ -33,6 +34,7 @@ const CreateForm: React.FC<CreateFormProps> = ({
|
|||||||
tourismOptions,
|
tourismOptions,
|
||||||
waylineOptions,
|
waylineOptions,
|
||||||
deviceOptions,
|
deviceOptions,
|
||||||
|
tenantOptions,
|
||||||
}) => {
|
}) => {
|
||||||
// 使用 Form.useWatch 监听 enableProfit 的值
|
// 使用 Form.useWatch 监听 enableProfit 的值
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
@@ -200,6 +202,24 @@ const CreateForm: React.FC<CreateFormProps> = ({
|
|||||||
tooltip="测试二维码的数据不会计入正式统计"
|
tooltip="测试二维码的数据不会计入正式统计"
|
||||||
/>
|
/>
|
||||||
</ProForm.Group>
|
</ProForm.Group>
|
||||||
|
|
||||||
|
<ProForm.Group>
|
||||||
|
<ProFormSelect
|
||||||
|
width="md"
|
||||||
|
name="tenantId"
|
||||||
|
label="应用ID"
|
||||||
|
options={tenantOptions}
|
||||||
|
rules={[{ required: true, message: '请选择应用' }]}
|
||||||
|
placeholder="请选择应用"
|
||||||
|
showSearch
|
||||||
|
fieldProps={{
|
||||||
|
loading: !tenantOptions.length,
|
||||||
|
filterOption: (input, option) =>
|
||||||
|
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||||
|
notFoundContent: tenantOptions.length === 0 ? '暂无应用数据' : undefined,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ProForm.Group>
|
||||||
</ModalForm>
|
</ModalForm>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ interface UpdateFormProps {
|
|||||||
tourismOptions: any[];
|
tourismOptions: any[];
|
||||||
waylineOptions: any[];
|
waylineOptions: any[];
|
||||||
deviceOptions: any[];
|
deviceOptions: any[];
|
||||||
|
tenantOptions: any[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const UpdateForm: React.FC<UpdateFormProps> = ({
|
const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||||
@@ -36,6 +37,7 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
|||||||
tourismOptions,
|
tourismOptions,
|
||||||
waylineOptions,
|
waylineOptions,
|
||||||
deviceOptions,
|
deviceOptions,
|
||||||
|
tenantOptions,
|
||||||
}) => {
|
}) => {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const enableProfit = Form.useWatch('enableProfit', form);
|
const enableProfit = Form.useWatch('enableProfit', form);
|
||||||
@@ -199,6 +201,24 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
|||||||
tooltip="测试二维码的数据不会计入正式统计"
|
tooltip="测试二维码的数据不会计入正式统计"
|
||||||
/>
|
/>
|
||||||
</ProForm.Group>
|
</ProForm.Group>
|
||||||
|
|
||||||
|
<ProForm.Group>
|
||||||
|
<ProFormSelect
|
||||||
|
width="md"
|
||||||
|
name="tenantId"
|
||||||
|
label="应用ID"
|
||||||
|
options={tenantOptions}
|
||||||
|
rules={[{ required: true, message: '请选择应用' }]}
|
||||||
|
placeholder="请选择应用"
|
||||||
|
showSearch
|
||||||
|
fieldProps={{
|
||||||
|
loading: !tenantOptions.length,
|
||||||
|
filterOption: (input, option) =>
|
||||||
|
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||||
|
notFoundContent: tenantOptions.length === 0 ? '暂无应用数据' : undefined,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ProForm.Group>
|
||||||
</ModalForm>
|
</ModalForm>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { deleteQrcode, qrcode, saveOrUpdateQrcode, getTourismList, getVideoTemplateList } from '@/services/orders/api';
|
import { deleteQrcode, qrcode, saveOrUpdateQrcode, getTourismList, getVideoTemplateList, getTenantList } from '@/services/orders/api';
|
||||||
import { PlusOutlined } from '@ant-design/icons';
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||||
import {
|
import {
|
||||||
@@ -93,6 +93,7 @@ const TableList: React.FC = () => {
|
|||||||
const [tourismOptions, setTourismOptions] = useState<any[]>([]);
|
const [tourismOptions, setTourismOptions] = useState<any[]>([]);
|
||||||
const [deviceOptions, setDeviceOptions] = useState<any[]>([]);
|
const [deviceOptions, setDeviceOptions] = useState<any[]>([]);
|
||||||
const [templateOptions, setTemplateOptions] = useState<any[]>([]);
|
const [templateOptions, setTemplateOptions] = useState<any[]>([]);
|
||||||
|
const [tenantOptions, setTenantOptions] = useState<any[]>([]);
|
||||||
const formRef = useRef();
|
const formRef = useRef();
|
||||||
|
|
||||||
// 将 renderStatus 函数移到组件内部
|
// 将 renderStatus 函数移到组件内部
|
||||||
@@ -243,12 +244,32 @@ const TableList: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const fetchTenantOptions = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const result = await getTenantList({
|
||||||
|
page: 1,
|
||||||
|
limit: 100,
|
||||||
|
});
|
||||||
|
if (result?.data) {
|
||||||
|
const options = result.data.map((item: any) => ({
|
||||||
|
label: item.clientName || item.clientId,
|
||||||
|
value: item.clientId,
|
||||||
|
info: item,
|
||||||
|
}));
|
||||||
|
setTenantOptions(options);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
message.error('获取应用列表失败');
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchTourismList();
|
fetchTourismList();
|
||||||
fetchWaylineOptions();
|
fetchWaylineOptions();
|
||||||
fetchDeviceList();
|
fetchDeviceList();
|
||||||
fetchTemplateOptions();
|
fetchTemplateOptions();
|
||||||
}, [fetchTourismList, fetchWaylineOptions, fetchDeviceList, fetchTemplateOptions]);
|
fetchTenantOptions();
|
||||||
|
}, [fetchTourismList, fetchWaylineOptions, fetchDeviceList, fetchTemplateOptions, fetchTenantOptions]);
|
||||||
|
|
||||||
const columns: ProColumns<ORDERS.Qrcode>[] = [
|
const columns: ProColumns<ORDERS.Qrcode>[] = [
|
||||||
{
|
{
|
||||||
@@ -438,6 +459,16 @@ const TableList: React.FC = () => {
|
|||||||
1: { text: '是' },
|
1: { text: '是' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '应用ID',
|
||||||
|
dataIndex: 'tenantId',
|
||||||
|
width: 120,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (_, record) => {
|
||||||
|
const tenant = tenantOptions.find(item => item.value === record.tenantId);
|
||||||
|
return tenant?.label || record.tenantId || '-';
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
@@ -506,6 +537,19 @@ const TableList: React.FC = () => {
|
|||||||
placeholder="请选择是否为测试二维码"
|
placeholder="请选择是否为测试二维码"
|
||||||
options={IS_TEST_OPTIONS}
|
options={IS_TEST_OPTIONS}
|
||||||
/>
|
/>
|
||||||
|
<ProFormSelect
|
||||||
|
name="tenantId"
|
||||||
|
label="应用ID"
|
||||||
|
placeholder="请选择应用"
|
||||||
|
options={tenantOptions}
|
||||||
|
fieldProps={{
|
||||||
|
loading: !tenantOptions.length,
|
||||||
|
showSearch: true,
|
||||||
|
filterOption: (input, option) =>
|
||||||
|
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||||
|
notFoundContent: tenantOptions.length === 0 ? '暂无应用数据' : undefined,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</QueryFilter>
|
</QueryFilter>
|
||||||
<ProTable<ORDERS.Qrcode>
|
<ProTable<ORDERS.Qrcode>
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
@@ -543,6 +587,7 @@ const TableList: React.FC = () => {
|
|||||||
fetchDeviceList();
|
fetchDeviceList();
|
||||||
fetchTourismList();
|
fetchTourismList();
|
||||||
fetchTemplateOptions();
|
fetchTemplateOptions();
|
||||||
|
fetchTenantOptions();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
visible={createModalVisible}
|
visible={createModalVisible}
|
||||||
@@ -550,6 +595,7 @@ const TableList: React.FC = () => {
|
|||||||
tourismOptions={tourismOptions}
|
tourismOptions={tourismOptions}
|
||||||
waylineOptions={waylineOptions}
|
waylineOptions={waylineOptions}
|
||||||
deviceOptions={deviceOptions}
|
deviceOptions={deviceOptions}
|
||||||
|
tenantOptions={tenantOptions}
|
||||||
/>
|
/>
|
||||||
<UpdateForm
|
<UpdateForm
|
||||||
onSubmit={async (values) => {
|
onSubmit={async (values) => {
|
||||||
@@ -561,6 +607,7 @@ const TableList: React.FC = () => {
|
|||||||
fetchDeviceList();
|
fetchDeviceList();
|
||||||
fetchTourismList();
|
fetchTourismList();
|
||||||
fetchTemplateOptions();
|
fetchTemplateOptions();
|
||||||
|
fetchTenantOptions();
|
||||||
}
|
}
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
setCurrentRow(undefined);
|
setCurrentRow(undefined);
|
||||||
@@ -572,6 +619,7 @@ const TableList: React.FC = () => {
|
|||||||
tourismOptions={tourismOptions}
|
tourismOptions={tourismOptions}
|
||||||
deviceOptions={deviceOptions}
|
deviceOptions={deviceOptions}
|
||||||
templateOptions={templateOptions}
|
templateOptions={templateOptions}
|
||||||
|
tenantOptions={tenantOptions}
|
||||||
/>
|
/>
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
+13
-3
@@ -19,6 +19,7 @@ interface UpdateFormProps {
|
|||||||
onVisibleChange: (visible: boolean) => void;
|
onVisibleChange: (visible: boolean) => void;
|
||||||
updateModalVisible: boolean;
|
updateModalVisible: boolean;
|
||||||
values?: ORDERS.Tourism;
|
values?: ORDERS.Tourism;
|
||||||
|
tenantOptions?: any[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const UpdateForm: React.FC<UpdateFormProps> = ({
|
const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||||
@@ -26,6 +27,7 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
|||||||
onVisibleChange,
|
onVisibleChange,
|
||||||
updateModalVisible,
|
updateModalVisible,
|
||||||
values,
|
values,
|
||||||
|
tenantOptions = [],
|
||||||
}) => {
|
}) => {
|
||||||
// 表单字段验证规则
|
// 表单字段验证规则
|
||||||
const formRules = {
|
const formRules = {
|
||||||
@@ -118,11 +120,19 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
|||||||
</ProForm.Group>
|
</ProForm.Group>
|
||||||
|
|
||||||
<ProForm.Group>
|
<ProForm.Group>
|
||||||
<ProFormText
|
<ProFormSelect
|
||||||
name="tenantId"
|
name="tenantId"
|
||||||
label="租户ID"
|
label="应用ID"
|
||||||
width="md"
|
width="md"
|
||||||
placeholder="请输入租户ID"
|
options={tenantOptions}
|
||||||
|
placeholder="请选择应用"
|
||||||
|
showSearch
|
||||||
|
fieldProps={{
|
||||||
|
loading: !tenantOptions.length,
|
||||||
|
filterOption: (input, option) =>
|
||||||
|
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||||
|
notFoundContent: tenantOptions.length === 0 ? '暂无应用数据' : undefined,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</ProForm.Group>
|
</ProForm.Group>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import UpdateForm from '@/pages/orders/Tourism/components/UpdateForm';
|
import UpdateForm from '@/pages/orders/Tourism/components/UpdateForm';
|
||||||
import { tourism, saveOrUpdateTourism, deleteTourism } from '@/services/orders/api';
|
import { tourism, saveOrUpdateTourism, deleteTourism, getTenantList } from '@/services/orders/api';
|
||||||
import { PlusOutlined } from '@ant-design/icons';
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||||
import {
|
import {
|
||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
ProFormDigit,
|
ProFormDigit,
|
||||||
} from '@ant-design/pro-components';
|
} from '@ant-design/pro-components';
|
||||||
import { Typography, message, Popconfirm, Button, Space, Tag } from 'antd';
|
import { Typography, message, Popconfirm, Button, Space, Tag } from 'antd';
|
||||||
import React, { useRef, useState, useCallback } from 'react';
|
import React, { useRef, useState, useCallback, useEffect } from 'react';
|
||||||
|
|
||||||
const { Link } = Typography;
|
const { Link } = Typography;
|
||||||
|
|
||||||
@@ -59,6 +59,7 @@ const TableList: React.FC = () => {
|
|||||||
const [createModalVisible, setCreateModalVisible] = useState<boolean>(false);
|
const [createModalVisible, setCreateModalVisible] = useState<boolean>(false);
|
||||||
const [updateModalVisible, setUpdateModalVisible] = useState<boolean>(false);
|
const [updateModalVisible, setUpdateModalVisible] = useState<boolean>(false);
|
||||||
const [currentRow, setCurrentRow] = useState<ORDERS.Tourism>();
|
const [currentRow, setCurrentRow] = useState<ORDERS.Tourism>();
|
||||||
|
const [tenantOptions, setTenantOptions] = useState<any[]>([]);
|
||||||
|
|
||||||
// 表格操作处理
|
// 表格操作处理
|
||||||
const handleTableAction = useCallback(async (
|
const handleTableAction = useCallback(async (
|
||||||
@@ -105,6 +106,31 @@ const TableList: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// 获取应用列表
|
||||||
|
const fetchTenantOptions = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const result = await getTenantList({
|
||||||
|
page: 1,
|
||||||
|
limit: 100,
|
||||||
|
});
|
||||||
|
if (result?.data) {
|
||||||
|
const options = result.data.map((item: any) => ({
|
||||||
|
label: item.clientName || item.clientId,
|
||||||
|
value: item.clientId,
|
||||||
|
info: item,
|
||||||
|
}));
|
||||||
|
setTenantOptions(options);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
message.error('获取应用列表失败');
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 组件加载时获取应用列表
|
||||||
|
useEffect(() => {
|
||||||
|
fetchTenantOptions();
|
||||||
|
}, [fetchTenantOptions]);
|
||||||
|
|
||||||
// 表格列定义
|
// 表格列定义
|
||||||
const columns: ProColumns<ORDERS.Tourism>[] = [
|
const columns: ProColumns<ORDERS.Tourism>[] = [
|
||||||
{
|
{
|
||||||
@@ -160,10 +186,14 @@ const TableList: React.FC = () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '租户ID',
|
title: '应用ID',
|
||||||
dataIndex: 'tenantId',
|
dataIndex: 'tenantId',
|
||||||
copyable: true,
|
copyable: true,
|
||||||
hideInSearch: true,
|
hideInSearch: true,
|
||||||
|
render: (_, record) => {
|
||||||
|
const tenant = tenantOptions.find(item => item.value === record.tenantId);
|
||||||
|
return tenant?.label || record.tenantId || '-';
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '状态',
|
title: '状态',
|
||||||
@@ -320,11 +350,19 @@ const TableList: React.FC = () => {
|
|||||||
</ProForm.Group>
|
</ProForm.Group>
|
||||||
|
|
||||||
<ProForm.Group>
|
<ProForm.Group>
|
||||||
<ProFormText
|
<ProFormSelect
|
||||||
name="tenantId"
|
name="tenantId"
|
||||||
label="租户ID"
|
label="应用ID"
|
||||||
width="md"
|
width="md"
|
||||||
placeholder="请输入租户ID(可选,不填将自动获取当前租户)"
|
options={tenantOptions}
|
||||||
|
placeholder="请选择应用(可选,不填将自动获取当前应用)"
|
||||||
|
showSearch
|
||||||
|
fieldProps={{
|
||||||
|
loading: !tenantOptions.length,
|
||||||
|
filterOption: (input, option) =>
|
||||||
|
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||||
|
notFoundContent: tenantOptions.length === 0 ? '暂无应用数据' : undefined,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</ProForm.Group>
|
</ProForm.Group>
|
||||||
|
|
||||||
@@ -349,6 +387,7 @@ const TableList: React.FC = () => {
|
|||||||
onVisibleChange={setUpdateModalVisible}
|
onVisibleChange={setUpdateModalVisible}
|
||||||
updateModalVisible={updateModalVisible}
|
updateModalVisible={updateModalVisible}
|
||||||
values={currentRow}
|
values={currentRow}
|
||||||
|
tenantOptions={tenantOptions}
|
||||||
/>
|
/>
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -453,3 +453,14 @@ export async function generateEditTask(orderNo: string) {
|
|||||||
params: { orderNo },
|
params: { orderNo },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取应用列表(作为租户列表)
|
||||||
|
export async function getTenantList(params: {
|
||||||
|
page: number;
|
||||||
|
limit: number;
|
||||||
|
[key: string]: any;
|
||||||
|
}) {
|
||||||
|
return request('/api-uaa/clients/all', {
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user