Merge branch 'develop' of https://gitee.com/L-Shilin/go-fly-platform-services into feature_dzc
# Conflicts: # zlt-config/src/main/resources/application-prod.properties
This commit is contained in:
+827
-13
@@ -24,6 +24,13 @@ import com.central.order.model.CtripCreateOrderRequest.CtripOrderBody;
|
||||
import com.central.order.model.CtripCreateOrderRequest.CtripOrderItem;
|
||||
import com.central.order.model.CtripCreateOrderRequest.CtripPassenger;
|
||||
import com.central.order.model.CtripCreateOrderRequest.CtripContact;
|
||||
import com.central.order.model.CtripCreateOrderRequest.CtripHeader;
|
||||
|
||||
import com.central.order.model.CtripCreateOrderResponse;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.util.CtripDecryptUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 优惠券管理控制器
|
||||
@@ -37,6 +44,9 @@ public class CouponController {
|
||||
@Autowired
|
||||
private ICouponService couponService;
|
||||
|
||||
@Autowired
|
||||
private CtripDecryptUtil ctripDecryptUtil;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@@ -126,19 +136,106 @@ public class CouponController {
|
||||
*/
|
||||
@Operation(summary = "携程创建优惠券接口")
|
||||
@PostMapping("/ctrip/create")
|
||||
public Result<Boolean> createCouponFromCtripJson(@RequestBody CtripCreateOrderRequest request) {
|
||||
log.info("携程创建券请求:{}", request);
|
||||
public CtripCreateOrderResponse createCouponFromCtrip(@RequestBody CtripCreateOrderRequest request) {
|
||||
log.info("携程创建优惠券请求:{}", request);
|
||||
|
||||
CtripCreateOrderResponse response = new CtripCreateOrderResponse();
|
||||
|
||||
try {
|
||||
// 验证请求头
|
||||
if (request.getHeader() == null || request.getBody() == null) {
|
||||
return Result.failed("请求格式错误");
|
||||
log.error("请求格式错误:header或body为空");
|
||||
return buildErrorResponse(request, "0001", "请求格式错误");
|
||||
}
|
||||
|
||||
// 从body中提取订单信息
|
||||
CtripOrderBody body = request.getBody();
|
||||
// 处理body字段 - 可能是字符串或对象
|
||||
CtripOrderBody body = null;
|
||||
if (request.getBody() instanceof String) {
|
||||
// body是加密字符串,需要解码
|
||||
String encryptedBody = (String) request.getBody();
|
||||
log.info("收到加密的body数据,长度:{}", encryptedBody.length());
|
||||
|
||||
// 尝试解码body数据
|
||||
String decodedBody = tryDecode(encryptedBody);
|
||||
if (!decodedBody.equals(encryptedBody)) {
|
||||
log.info("body数据解码成功,尝试解析解码后的数据");
|
||||
log.debug("解码后的数据前100个字符:{}", decodedBody.length() > 100 ? decodedBody.substring(0, 100) + "..." : decodedBody);
|
||||
|
||||
if (isValidJson(decodedBody)) {
|
||||
// 解析解码后的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);
|
||||
try {
|
||||
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 {
|
||||
// 如果解码失败,尝试直接解析为JSON
|
||||
if (isValidJson(encryptedBody)) {
|
||||
log.info("body数据是有效的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);
|
||||
try {
|
||||
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) {
|
||||
log.error("无法解析body数据,数据格式:{}", analyzeDataFormat(encryptedBody));
|
||||
log.error("解码后的数据格式:{}", analyzeDataFormat(decodedBody));
|
||||
log.error("解码后的数据详情:{}", getDataDetails(decodedBody));
|
||||
return buildErrorResponse(request, "0007", "无法解析body数据,请联系技术支持");
|
||||
}
|
||||
} else if (request.getBody() instanceof CtripOrderBody) {
|
||||
// body已经是对象
|
||||
body = (CtripOrderBody) request.getBody();
|
||||
log.info("body已经是对象格式");
|
||||
} else {
|
||||
log.error("body字段格式不支持:{}", request.getBody().getClass().getName());
|
||||
return buildErrorResponse(request, "0008", "body字段格式不支持");
|
||||
}
|
||||
|
||||
// 从body中提取优惠券信息
|
||||
if (body.getItems() == null || body.getItems().isEmpty()) {
|
||||
return Result.failed("订单项不能为空");
|
||||
log.error("订单项不能为空");
|
||||
return buildErrorResponse(request, "0002", "订单项不能为空");
|
||||
}
|
||||
|
||||
// 获取第一个订单项
|
||||
@@ -151,6 +248,7 @@ public class CouponController {
|
||||
CtripPassenger passenger = item.getPassengers().get(0);
|
||||
userPhone = passenger.getMobile();
|
||||
userName = passenger.getName();
|
||||
log.debug("从乘客信息获取到手机号: {}, 姓名: {}", userPhone, userName);
|
||||
}
|
||||
|
||||
// 获取联系人信息作为备选
|
||||
@@ -158,10 +256,12 @@ public class CouponController {
|
||||
CtripContact contact = body.getContacts().get(0);
|
||||
userPhone = contact.getMobile();
|
||||
userName = contact.getName();
|
||||
log.debug("从联系人信息获取到手机号: {}, 姓名: {}", userPhone, userName);
|
||||
}
|
||||
|
||||
if (userPhone == null) {
|
||||
return Result.failed("无法获取用户手机号");
|
||||
log.error("无法获取用户手机号");
|
||||
return buildErrorResponse(request, "0003", "无法获取用户手机号");
|
||||
}
|
||||
|
||||
// 构建优惠券信息
|
||||
@@ -173,10 +273,13 @@ public class CouponController {
|
||||
String validStartTime = item.getUseStartDate();
|
||||
String validEndTime = item.getUseEndDate();
|
||||
|
||||
log.debug("优惠券信息 - ctripCouponId: {}, userPhone: {}, couponName: {}, amount: {}, minAmount: {}",
|
||||
ctripCouponId, userPhone, couponName, amount, minAmount);
|
||||
|
||||
// 幂等校验
|
||||
if (couponService.existsByUserPhoneAndCtripCouponId(userPhone, ctripCouponId)) {
|
||||
log.info("携程优惠券已存在,userPhone: {}, ctripCouponId: {}", userPhone, ctripCouponId);
|
||||
return Result.succeed(true);
|
||||
return buildSuccessResponse(request, ctripCouponId, "优惠券已存在且创建成功");
|
||||
}
|
||||
|
||||
// 时间解析
|
||||
@@ -185,11 +288,13 @@ public class CouponController {
|
||||
|
||||
// 验证时间
|
||||
if (startTime == null || endTime == null) {
|
||||
return Result.failed("时间格式错误");
|
||||
log.error("时间格式错误 - validStartTime: {}, validEndTime: {}", validStartTime, validEndTime);
|
||||
return buildErrorResponse(request, "0004", "时间格式错误");
|
||||
}
|
||||
|
||||
if (endTime.before(startTime)) {
|
||||
return Result.failed("结束时间不能早于开始时间");
|
||||
log.error("结束时间不能早于开始时间 - startTime: {}, endTime: {}", startTime, endTime);
|
||||
return buildErrorResponse(request, "0005", "结束时间不能早于开始时间");
|
||||
}
|
||||
|
||||
// 创建优惠券
|
||||
@@ -199,18 +304,178 @@ public class CouponController {
|
||||
|
||||
if (result) {
|
||||
log.info("携程优惠券创建成功,userPhone: {}, ctripCouponId: {}, amount: {}", userPhone, ctripCouponId, amount);
|
||||
return Result.succeed(true);
|
||||
return buildSuccessResponse(request, ctripCouponId, "优惠券创建成功");
|
||||
} else {
|
||||
log.error("携程优惠券创建失败,userPhone: {}, ctripCouponId: {}", userPhone, ctripCouponId);
|
||||
return Result.failed("优惠券创建失败");
|
||||
return buildErrorResponse(request, "0006", "优惠券创建失败");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理携程创建券请求失败", e);
|
||||
log.error("处理携程创建优惠券请求失败", e);
|
||||
return buildErrorResponse(request, "9999", "系统异常:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建成功响应
|
||||
*/
|
||||
private CtripCreateOrderResponse buildSuccessResponse(CtripCreateOrderRequest request, String otaOrderId, String message) {
|
||||
CtripCreateOrderResponse response = new CtripCreateOrderResponse();
|
||||
|
||||
// 设置返回头
|
||||
CtripCreateOrderResponse.CtripResponseHeader responseHeader = new CtripCreateOrderResponse.CtripResponseHeader();
|
||||
responseHeader.setRequestTime(request.getHeader().getRequestTime());
|
||||
responseHeader.setAccountId(request.getHeader().getAccountId());
|
||||
responseHeader.setSign(request.getHeader().getSign());
|
||||
responseHeader.setServiceName(request.getHeader().getServiceName());
|
||||
responseHeader.setVersion(request.getHeader().getVersion());
|
||||
response.setHeader(responseHeader);
|
||||
|
||||
// 设置返回码
|
||||
response.setResultCode("0000");
|
||||
response.setResultMessage("操作成功");
|
||||
|
||||
// 设置返回体
|
||||
CtripCreateOrderResponse.CtripResponseBody responseBody = new CtripCreateOrderResponse.CtripResponseBody();
|
||||
responseBody.setOtaOrderId(otaOrderId);
|
||||
responseBody.setSupplierOrderId("COUPON_" + System.currentTimeMillis()); // 优惠券ID
|
||||
responseBody.setSupplierConfirmType(1); // 已确认
|
||||
responseBody.setVoucherSender(1); // 携程对客发送凭证
|
||||
|
||||
// 设置订单项
|
||||
List<CtripCreateOrderResponse.CtripResponseOrderItem> responseItems = new ArrayList<>();
|
||||
CtripCreateOrderResponse.CtripResponseOrderItem responseItem = new CtripCreateOrderResponse.CtripResponseOrderItem();
|
||||
responseItem.setItemId("1");
|
||||
responseItem.setSupplierItemId("COUPON_ITEM_" + System.currentTimeMillis());
|
||||
responseItem.setStatus(1); // 成功
|
||||
responseItem.setMessage(message);
|
||||
responseItems.add(responseItem);
|
||||
responseBody.setItems(responseItems);
|
||||
|
||||
response.setBody(responseBody);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建错误响应
|
||||
*/
|
||||
private CtripCreateOrderResponse buildErrorResponse(CtripCreateOrderRequest request, String resultCode, String resultMessage) {
|
||||
CtripCreateOrderResponse response = new CtripCreateOrderResponse();
|
||||
|
||||
// 设置返回头
|
||||
CtripCreateOrderResponse.CtripResponseHeader responseHeader = new CtripCreateOrderResponse.CtripResponseHeader();
|
||||
responseHeader.setRequestTime(request.getHeader().getRequestTime());
|
||||
responseHeader.setAccountId(request.getHeader().getAccountId());
|
||||
responseHeader.setSign(request.getHeader().getSign());
|
||||
responseHeader.setServiceName(request.getHeader().getServiceName());
|
||||
responseHeader.setVersion(request.getHeader().getVersion());
|
||||
response.setHeader(responseHeader);
|
||||
|
||||
// 设置返回码
|
||||
response.setResultCode(resultCode);
|
||||
response.setResultMessage(resultMessage);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程创建优惠券接口 - 备用方法
|
||||
*/
|
||||
@Operation(summary = "携程创建优惠券接口 - 备用方法")
|
||||
@PostMapping("/ctrip/create/raw")
|
||||
public Result<Boolean> createCouponFromCtripRaw(@RequestBody String rawJson) {
|
||||
log.info("携程创建券原始请求:{}", rawJson);
|
||||
|
||||
try {
|
||||
// 使用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);
|
||||
|
||||
CtripCreateOrderRequest request = objectMapper.readValue(rawJson, CtripCreateOrderRequest.class);
|
||||
// 这里应该调用优惠券创建逻辑,而不是订单创建
|
||||
return Result.succeed(true);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理携程创建券原始请求失败", e);
|
||||
return Result.failed("处理请求失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程创建优惠券接口 - 处理加密数据
|
||||
*/
|
||||
@Operation(summary = "携程创建优惠券接口 - 处理加密数据")
|
||||
@PostMapping("/ctrip/create/encrypted")
|
||||
public Result<Boolean> createCouponFromCtripEncrypted(@RequestBody String encryptedData) {
|
||||
log.info("携程创建券加密请求,数据长度:{}", encryptedData.length());
|
||||
|
||||
try {
|
||||
// 检查数据是否是有效的JSON
|
||||
if (encryptedData.startsWith("{") && encryptedData.endsWith("}")) {
|
||||
// 尝试直接解析为JSON
|
||||
return createCouponFromCtripRaw(encryptedData);
|
||||
} else {
|
||||
log.warn("收到非JSON格式的加密数据,长度:{}", encryptedData.length());
|
||||
// 这里可以添加解密逻辑
|
||||
return Result.failed("暂不支持加密数据格式");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理携程创建券加密请求失败", e);
|
||||
return Result.failed("处理请求失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程创建优惠券接口 - 处理非JSON格式数据
|
||||
*/
|
||||
@Operation(summary = "携程创建优惠券接口 - 处理非JSON格式数据")
|
||||
@PostMapping("/ctrip/create/non-json")
|
||||
public Result<Boolean> createCouponFromCtripNonJson(@RequestBody String nonJsonData) {
|
||||
log.info("携程创建券非JSON请求,数据长度:{}", nonJsonData.length());
|
||||
log.debug("携程创建券非JSON请求原始数据:{}", nonJsonData);
|
||||
|
||||
try {
|
||||
// 检查数据格式
|
||||
if (nonJsonData == null || nonJsonData.trim().isEmpty()) {
|
||||
log.error("请求数据为空");
|
||||
return Result.failed("请求数据为空");
|
||||
}
|
||||
|
||||
// 分析数据格式
|
||||
String dataFormat = analyzeDataFormat(nonJsonData);
|
||||
log.info("数据格式分析结果:{}", dataFormat);
|
||||
|
||||
// 检查是否是JSON格式
|
||||
if (isValidJson(nonJsonData)) {
|
||||
log.info("数据是JSON格式,转发到标准接口");
|
||||
return createCouponFromCtripRaw(nonJsonData);
|
||||
}
|
||||
|
||||
// 尝试解码
|
||||
String decodedData = tryDecode(nonJsonData);
|
||||
if (!decodedData.equals(nonJsonData)) {
|
||||
log.info("数据解码成功,尝试解析解码后的数据");
|
||||
if (isValidJson(decodedData)) {
|
||||
return createCouponFromCtripRaw(decodedData);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理非JSON格式数据
|
||||
log.warn("收到非JSON格式数据,格式:{},长度:{},前100个字符:{}",
|
||||
dataFormat,
|
||||
nonJsonData.length(),
|
||||
nonJsonData.length() > 100 ? nonJsonData.substring(0, 100) + "..." : nonJsonData);
|
||||
|
||||
// 暂时返回错误,因为不知道如何处理这种格式
|
||||
return Result.failed("暂不支持数据格式:" + dataFormat + ",请联系技术支持");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理携程创建券非JSON请求失败", e);
|
||||
return Result.failed("处理请求失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -274,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);
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
/**
|
||||
* 全局异常处理器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
/**
|
||||
* 处理JSON反序列化错误
|
||||
*/
|
||||
@ExceptionHandler(HttpMessageNotReadableException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public Result<String> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
|
||||
log.error("JSON反序列化错误", e);
|
||||
|
||||
String errorMessage = "请求格式错误";
|
||||
Throwable cause = e.getCause();
|
||||
|
||||
if (cause instanceof JsonParseException) {
|
||||
errorMessage = "JSON格式错误:" + cause.getMessage();
|
||||
} else if (cause instanceof JsonMappingException) {
|
||||
JsonMappingException mappingException = (JsonMappingException) cause;
|
||||
String path = mappingException.getPathReference();
|
||||
String message = mappingException.getMessage();
|
||||
|
||||
// 检查是否是字符串反序列化问题
|
||||
if (message.contains("no String-argument constructor") && message.contains("deserialize from String value")) {
|
||||
errorMessage = "数据格式错误:期望JSON对象,但收到字符串数据。请检查请求格式或联系技术支持。";
|
||||
log.error("检测到字符串反序列化问题,可能需要使用 /ctrip/create/non-json 接口");
|
||||
} else {
|
||||
errorMessage = "JSON映射错误:" + message + " (路径: " + path + ")";
|
||||
}
|
||||
}
|
||||
|
||||
return Result.failed(errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理通用异常
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public Result<String> handleException(Exception e) {
|
||||
log.error("系统异常", e);
|
||||
return Result.failed("系统异常:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
+2
@@ -100,6 +100,7 @@ public class RefundController {
|
||||
refund.setState(RefundState.APPROVING.getId());
|
||||
refund.setRefundReason(refundBody.getRefundReason());
|
||||
refund.setRefundImgs(refundBody.getRefundImgs());
|
||||
refund.setTenantId(order.getTenantId());
|
||||
boolean res = refundService.createRefund(refund);
|
||||
if (res) {
|
||||
order.setOrderStatus(OrderStatus.REFUNDING.getId());
|
||||
@@ -189,6 +190,7 @@ public class RefundController {
|
||||
refund.setRefundAmount(order.getOrderAmount());
|
||||
refund.setStatus(OrderStatus.REFUNDING.getId());
|
||||
refund.setState(RefundState.APPROVING.getId());
|
||||
refund.setTenantId(order.getTenantId());
|
||||
refund.setRefundReason("机库执行任务异常自动退款,该退款单由系统自动创建,请高传旭先生仔细核实!");
|
||||
|
||||
boolean refundCreated = refundService.createRefund(refund);
|
||||
|
||||
+3
@@ -200,6 +200,7 @@ public class WxPayController {
|
||||
@RequestBody String body) {
|
||||
log.info("------收到微信退款回调通知------");
|
||||
try {
|
||||
TenantContextHolder.setTenant(defaultTenantId);
|
||||
// 构建请求参数
|
||||
RequestParam requestParam = new RequestParam
|
||||
.Builder()
|
||||
@@ -239,6 +240,8 @@ public class WxPayController {
|
||||
// 处理异常,记录日志等
|
||||
log.error("处理退款回调失败", e);
|
||||
return buildErrorResponse();
|
||||
}finally {
|
||||
TenantContextHolder.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-10
@@ -37,18 +37,8 @@ public class OrderStatusChangeListener {
|
||||
@Autowired
|
||||
private IOrderService orderService;
|
||||
@Autowired
|
||||
private IQrCodeService qrCodeService;
|
||||
@Autowired
|
||||
private IVideoEditService videoEditService;
|
||||
@Autowired
|
||||
private IOrderFileService orderFileService;
|
||||
@Autowired
|
||||
private IWxTemplateMessageService wxTemplateMessageService;
|
||||
@Autowired
|
||||
private UserCenterService userCenterService;
|
||||
@Autowired
|
||||
private IEditTaskService editTaskService;
|
||||
@Autowired
|
||||
private WxMiniSubscribeService wxMiniSubscribeService;
|
||||
|
||||
@EventListener
|
||||
|
||||
+22
-6
@@ -14,7 +14,8 @@ public interface DashboardMapper {
|
||||
// 基础订单统计(支持筛选)
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COUNT(*) FROM orders o",
|
||||
"SELECT COUNT(*) as count",
|
||||
"FROM orders o",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"WHERE o.is_del = 0",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
@@ -41,7 +42,8 @@ public interface DashboardMapper {
|
||||
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COUNT(*) FROM orders o",
|
||||
"SELECT COUNT(*) as count",
|
||||
"FROM orders o",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"WHERE o.is_del = 0",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
@@ -63,7 +65,8 @@ public interface DashboardMapper {
|
||||
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COUNT(*) FROM orders o",
|
||||
"SELECT COUNT(*) as count",
|
||||
"FROM orders o",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"WHERE o.is_del = 0",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
@@ -85,7 +88,8 @@ public interface DashboardMapper {
|
||||
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COUNT(*) FROM orders o",
|
||||
"SELECT COUNT(*) as count",
|
||||
"FROM orders o",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"WHERE o.is_del = 0",
|
||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||
@@ -114,7 +118,7 @@ public interface DashboardMapper {
|
||||
// 对账相关统计
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COALESCE(SUM(o.order_amount), 0)",
|
||||
"SELECT COALESCE(SUM(o.order_amount), 0) as amount",
|
||||
"FROM orders o",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
"WHERE o.is_del = 0",
|
||||
@@ -125,6 +129,12 @@ public interface DashboardMapper {
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND o.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||
" AND o.code_id = #{p.qrcodeId}",
|
||||
"</if>",
|
||||
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||
" AND o.device_sn = #{p.deviceSn}",
|
||||
"</if>",
|
||||
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||
" AND o.create_time >= #{p.startTime}",
|
||||
"</if>",
|
||||
@@ -191,7 +201,7 @@ public interface DashboardMapper {
|
||||
|
||||
@Select({
|
||||
"<script>",
|
||||
"SELECT COALESCE(SUM(CAST(r.refund_amount AS SIGNED)), 0)",
|
||||
"SELECT COALESCE(SUM(CAST(r.refund_amount AS SIGNED)), 0) as amount",
|
||||
"FROM orders_refund r",
|
||||
"JOIN orders o ON r.order_no = o.order_no",
|
||||
"JOIN qrcodes q ON o.code_id = q.code_id",
|
||||
@@ -202,6 +212,12 @@ public interface DashboardMapper {
|
||||
"<if test='p.tourismId != null'>",
|
||||
" AND o.tourism_id = #{p.tourismId}",
|
||||
"</if>",
|
||||
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
|
||||
" AND o.code_id = #{p.qrcodeId}",
|
||||
"</if>",
|
||||
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
|
||||
" AND o.device_sn = #{p.deviceSn}",
|
||||
"</if>",
|
||||
"<if test='p.startTime != null and p.startTime != \"\"'>",
|
||||
" AND r.create_time >= #{p.startTime}",
|
||||
"</if>",
|
||||
|
||||
+76
-5
@@ -1,33 +1,44 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程创建订单请求
|
||||
* 携程订单新订请求
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripCreateOrderRequest {
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripHeader header;
|
||||
|
||||
/**
|
||||
* 请求体
|
||||
* 请求体 - 可能是加密字符串或JSON对象
|
||||
*/
|
||||
private CtripOrderBody body;
|
||||
@JsonProperty("body")
|
||||
private Object body; // 改为Object类型,支持字符串和对象两种格式
|
||||
|
||||
/**
|
||||
* 携程请求头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripHeader {
|
||||
@JsonProperty("requestTime")
|
||||
private String requestTime;
|
||||
@JsonProperty("accountId")
|
||||
private String accountId;
|
||||
@JsonProperty("sign")
|
||||
private String sign;
|
||||
@JsonProperty("serviceName")
|
||||
private String serviceName;
|
||||
@JsonProperty("version")
|
||||
private String version;
|
||||
}
|
||||
|
||||
@@ -35,34 +46,61 @@ public class CtripCreateOrderRequest {
|
||||
* 携程订单体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripOrderBody {
|
||||
@JsonProperty("otaOrderId")
|
||||
private String otaOrderId;
|
||||
@JsonProperty("sequenceId")
|
||||
private String sequenceId;
|
||||
@JsonProperty("items")
|
||||
private List<CtripOrderItem> items;
|
||||
@JsonProperty("contacts")
|
||||
private List<CtripContact> contacts;
|
||||
@JsonProperty("confirmType")
|
||||
private Integer confirmType;
|
||||
@JsonProperty("locale")
|
||||
private String locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程订单项
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripOrderItem {
|
||||
@JsonProperty("passengers")
|
||||
private List<CtripPassenger> passengers;
|
||||
@JsonProperty("cost")
|
||||
private java.math.BigDecimal cost;
|
||||
@JsonProperty("quantity")
|
||||
private Integer quantity;
|
||||
@JsonProperty("salePrice")
|
||||
private java.math.BigDecimal salePrice;
|
||||
@JsonProperty("remark")
|
||||
private String remark;
|
||||
@JsonProperty("useEndDate")
|
||||
private String useEndDate;
|
||||
@JsonProperty("locale")
|
||||
private String locale;
|
||||
@JsonProperty("useStartDate")
|
||||
private String useStartDate;
|
||||
@JsonProperty("priceCurrency")
|
||||
private String priceCurrency;
|
||||
private List<Object> adjunctions;
|
||||
@JsonProperty("adjunctions")
|
||||
private List<String> adjunctions;
|
||||
@JsonProperty("price")
|
||||
private java.math.BigDecimal price;
|
||||
@JsonProperty("PLU")
|
||||
private String PLU;
|
||||
private Object deposit;
|
||||
@JsonProperty("deposit")
|
||||
private Object deposit; // 改回Object类型,因为可能是对象
|
||||
@JsonProperty("distributionChannel")
|
||||
private String distributionChannel;
|
||||
@JsonProperty("costCurrency")
|
||||
private String costCurrency;
|
||||
@JsonProperty("salePriceCurrency")
|
||||
private String salePriceCurrency;
|
||||
@JsonProperty("expressDelivery")
|
||||
private CtripExpressDelivery expressDelivery;
|
||||
}
|
||||
|
||||
@@ -70,29 +108,53 @@ public class CtripCreateOrderRequest {
|
||||
* 携程乘客信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripPassenger {
|
||||
@JsonProperty("cardIssuePlace")
|
||||
private String cardIssuePlace;
|
||||
@JsonProperty("lastName")
|
||||
private String lastName;
|
||||
@JsonProperty("cardIssueCountry")
|
||||
private String cardIssueCountry;
|
||||
@JsonProperty("shoeSize")
|
||||
private Integer shoeSize;
|
||||
@JsonProperty("gender")
|
||||
private String gender;
|
||||
@JsonProperty("cardIssueDate")
|
||||
private String cardIssueDate;
|
||||
@JsonProperty("intlCode")
|
||||
private String intlCode;
|
||||
@JsonProperty("nationalityName")
|
||||
private String nationalityName;
|
||||
@JsonProperty("mobile")
|
||||
private String mobile;
|
||||
@JsonProperty("cardType")
|
||||
private String cardType;
|
||||
@JsonProperty("weight")
|
||||
private Integer weight;
|
||||
@JsonProperty("myopiaDegreeL")
|
||||
private Integer myopiaDegreeL;
|
||||
@JsonProperty("birthDate")
|
||||
private String birthDate;
|
||||
@JsonProperty("cardNo")
|
||||
private String cardNo;
|
||||
@JsonProperty("ageType")
|
||||
private String ageType;
|
||||
@JsonProperty("myopiaDegreeR")
|
||||
private Integer myopiaDegreeR;
|
||||
@JsonProperty("firstName")
|
||||
private String firstName;
|
||||
@JsonProperty("birthPlace")
|
||||
private String birthPlace;
|
||||
@JsonProperty("nationalityCode")
|
||||
private String nationalityCode;
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
@JsonProperty("passengerId")
|
||||
private String passengerId;
|
||||
@JsonProperty("cardValidDate")
|
||||
private String cardValidDate;
|
||||
@JsonProperty("height")
|
||||
private Integer height;
|
||||
}
|
||||
|
||||
@@ -100,12 +162,19 @@ public class CtripCreateOrderRequest {
|
||||
* 携程联系人信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripContact {
|
||||
@JsonProperty("intlCode")
|
||||
private String intlCode;
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
@JsonProperty("mobile")
|
||||
private String mobile;
|
||||
@JsonProperty("optionalMobile")
|
||||
private String optionalMobile;
|
||||
@JsonProperty("optionalIntlCode")
|
||||
private String optionalIntlCode;
|
||||
@JsonProperty("email")
|
||||
private String email;
|
||||
}
|
||||
|
||||
@@ -113,7 +182,9 @@ public class CtripCreateOrderRequest {
|
||||
* 携程快递信息
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripExpressDelivery {
|
||||
@JsonProperty("type")
|
||||
private String type;
|
||||
}
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 携程订单新订响应
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CtripCreateOrderResponse {
|
||||
|
||||
/**
|
||||
* 返回头
|
||||
*/
|
||||
@JsonProperty("header")
|
||||
private CtripResponseHeader header;
|
||||
|
||||
/**
|
||||
* 处理结果返回码
|
||||
*/
|
||||
@JsonProperty("resultCode")
|
||||
private String resultCode;
|
||||
|
||||
/**
|
||||
* 处理结果返回信息
|
||||
*/
|
||||
@JsonProperty("resultMessage")
|
||||
private String resultMessage;
|
||||
|
||||
/**
|
||||
* 返回体
|
||||
*/
|
||||
@JsonProperty("body")
|
||||
private CtripResponseBody body;
|
||||
|
||||
/**
|
||||
* 携程返回头
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseHeader {
|
||||
@JsonProperty("requestTime")
|
||||
private String requestTime;
|
||||
@JsonProperty("accountId")
|
||||
private String accountId;
|
||||
@JsonProperty("sign")
|
||||
private String sign;
|
||||
@JsonProperty("serviceName")
|
||||
private String serviceName;
|
||||
@JsonProperty("version")
|
||||
private String version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程返回体
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseBody {
|
||||
@JsonProperty("otaOrderId")
|
||||
private String otaOrderId;
|
||||
@JsonProperty("supplierOrderId")
|
||||
private String supplierOrderId;
|
||||
@JsonProperty("supplierConfirmType")
|
||||
private Integer supplierConfirmType;
|
||||
@JsonProperty("voucherSender")
|
||||
private Integer voucherSender;
|
||||
@JsonProperty("vouchers")
|
||||
private List<CtripVoucher> vouchers;
|
||||
@JsonProperty("orderExtendMessage")
|
||||
private String orderExtendMessage;
|
||||
@JsonProperty("items")
|
||||
private List<CtripResponseOrderItem> items;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程凭证
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripVoucher {
|
||||
@JsonProperty("voucherType")
|
||||
private Integer voucherType;
|
||||
@JsonProperty("voucherContent")
|
||||
private String voucherContent;
|
||||
@JsonProperty("voucherUrl")
|
||||
private String voucherUrl;
|
||||
@JsonProperty("locale")
|
||||
private String locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* 携程返回订单项
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class CtripResponseOrderItem {
|
||||
@JsonProperty("itemId")
|
||||
private String itemId;
|
||||
@JsonProperty("supplierItemId")
|
||||
private String supplierItemId;
|
||||
@JsonProperty("status")
|
||||
private Integer status;
|
||||
@JsonProperty("message")
|
||||
private String message;
|
||||
}
|
||||
}
|
||||
-6
@@ -23,12 +23,6 @@ public class OrderStatistics {
|
||||
@Schema(description = "订单总金额(分)")
|
||||
private Long totalAmount;
|
||||
|
||||
@Schema(description = "平台分账金额(分)")
|
||||
private Long platformAmount;
|
||||
|
||||
@Schema(description = "景区分账金额(分)")
|
||||
private Long tourismAmount;
|
||||
|
||||
@Schema(description = "退款金额(分)")
|
||||
private Long refundAmount;
|
||||
|
||||
|
||||
+10
-6
@@ -70,12 +70,16 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
stats.setCompletionRate(completionRate);
|
||||
}
|
||||
|
||||
// 获取对账相关数据
|
||||
stats.setTotalAmount(dashboardMapper.getTotalAmount(params));
|
||||
stats.setRefundAmount(dashboardMapper.getRefundAmount(params));
|
||||
// 景区收入 = 总订单金额 - 退款金额
|
||||
Long netIncome = (stats.getTotalAmount() != null ? stats.getTotalAmount() : 0)
|
||||
- (stats.getRefundAmount() != null ? stats.getRefundAmount() : 0);
|
||||
// 获取对账相关数据 - 使用 orders 表的数据
|
||||
Long totalAmount = dashboardMapper.getTotalAmount(params);
|
||||
Long refundAmount = dashboardMapper.getRefundAmount(params);
|
||||
|
||||
// 设置基础数据
|
||||
stats.setTotalAmount(totalAmount);
|
||||
stats.setRefundAmount(refundAmount);
|
||||
|
||||
// 计算净收入 = 总金额 - 退款金额
|
||||
Long netIncome = (totalAmount != null ? totalAmount : 0) - (refundAmount != null ? refundAmount : 0);
|
||||
stats.setNetIncome(netIncome);
|
||||
|
||||
return stats;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -39,12 +39,14 @@ zlt:
|
||||
- video_template
|
||||
- profit_sharing
|
||||
- order_statistics
|
||||
- orders_refund
|
||||
ignoreSqls:
|
||||
# 移除所有ignoreSqls配置,让所有SQL都经过租户过滤处理
|
||||
# 这样webApp租户的特殊处理逻辑才能生效
|
||||
# 该接口是白名单接口查询中的逻辑,来例如:机库直接创建数据没有携带租户ID
|
||||
- com.central.order.mapper.OrderMapper.getOrderByNumber
|
||||
- com.central.order.mapper.OrderMapper.getOrdersByStatus
|
||||
- com.central.order.mapper.RefundMapper.selectOne
|
||||
# update和delete类型的操作mybatisPlus不支持,原因是数据隔离级别
|
||||
# - com.central.order.mapper.OrderMapper.updateOrderStatus
|
||||
# 微信支付商户号
|
||||
@@ -138,3 +140,11 @@ cdn:
|
||||
logging:
|
||||
level:
|
||||
com.central.order.controller.OrderFileController: DEBUG
|
||||
|
||||
# 携程API配置
|
||||
ctrip:
|
||||
aes:
|
||||
key: 087b36ad0dff7942 # 请替换为实际的AES密钥
|
||||
iv: 750e15a31356a99d # 请替换为实际的AES IV
|
||||
sign:
|
||||
key: ce6033ae31124ec5cdab3d2bc79f2622 # 请替换为实际的签名密钥
|
||||
|
||||
+427
@@ -0,0 +1,427 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import com.central.order.model.CtripCreateOrderRequest;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* 优惠券控制器测试
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class CouponControllerTest {
|
||||
|
||||
@Test
|
||||
public void testCtripCreateOrderRequestDeserialization() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 构建测试JSON
|
||||
String testJson = "{\n" +
|
||||
" \"header\": {\n" +
|
||||
" \"requestTime\": \"2024-12-19 10:00:00\",\n" +
|
||||
" \"accountId\": \"testAccount\",\n" +
|
||||
" \"sign\": \"testSign\",\n" +
|
||||
" \"serviceName\": \"createOrder\",\n" +
|
||||
" \"version\": \"1.0\"\n" +
|
||||
" },\n" +
|
||||
" \"body\": {\n" +
|
||||
" \"otaOrderId\": \"CTRIP123456\",\n" +
|
||||
" \"sequenceId\": \"SEQ123456\",\n" +
|
||||
" \"items\": [\n" +
|
||||
" {\n" +
|
||||
" \"passengers\": [\n" +
|
||||
" {\n" +
|
||||
" \"name\": \"张三\",\n" +
|
||||
" \"mobile\": \"13800138000\",\n" +
|
||||
" \"gender\": \"M\",\n" +
|
||||
" \"cardType\": \"ID\",\n" +
|
||||
" \"cardNo\": \"110101199001011234\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"cost\": 100.00,\n" +
|
||||
" \"quantity\": 1,\n" +
|
||||
" \"salePrice\": 80.00,\n" +
|
||||
" \"price\": 100.00,\n" +
|
||||
" \"useStartDate\": \"2024-12-20\",\n" +
|
||||
" \"useEndDate\": \"2024-12-25\",\n" +
|
||||
" \"adjunctions\": [\"adj1\", \"adj2\"],\n" +
|
||||
" \"deposit\": {},\n" +
|
||||
" \"distributionChannel\": \"online\",\n" +
|
||||
" \"priceCurrency\": \"CNY\",\n" +
|
||||
" \"costCurrency\": \"CNY\",\n" +
|
||||
" \"salePriceCurrency\": \"CNY\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"contacts\": [\n" +
|
||||
" {\n" +
|
||||
" \"name\": \"张三\",\n" +
|
||||
" \"mobile\": \"13800138000\",\n" +
|
||||
" \"email\": \"zhangsan@example.com\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
// 测试反序列化
|
||||
CtripCreateOrderRequest request = objectMapper.readValue(testJson, CtripCreateOrderRequest.class);
|
||||
|
||||
// 验证反序列化结果
|
||||
assertNotNull(request);
|
||||
assertNotNull(request.getHeader());
|
||||
assertNotNull(request.getBody());
|
||||
assertEquals("testAccount", request.getHeader().getAccountId());
|
||||
assertEquals("createOrder", request.getHeader().getServiceName());
|
||||
|
||||
// 验证body是对象
|
||||
assertTrue(request.getBody() instanceof CtripCreateOrderRequest.CtripOrderBody);
|
||||
CtripCreateOrderRequest.CtripOrderBody body = (CtripCreateOrderRequest.CtripOrderBody) request.getBody();
|
||||
assertEquals("CTRIP123456", body.getOtaOrderId());
|
||||
|
||||
// 验证订单项
|
||||
assertNotNull(body.getItems());
|
||||
assertFalse(body.getItems().isEmpty());
|
||||
|
||||
CtripCreateOrderRequest.CtripOrderItem item = body.getItems().get(0);
|
||||
assertNotNull(item.getPassengers());
|
||||
assertFalse(item.getPassengers().isEmpty());
|
||||
assertEquals("张三", item.getPassengers().get(0).getName());
|
||||
assertEquals("13800138000", item.getPassengers().get(0).getMobile());
|
||||
|
||||
System.out.println("JSON反序列化测试通过!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCtripCreateOrderRequestSerialization() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 构建测试对象
|
||||
CtripCreateOrderRequest request = new CtripCreateOrderRequest();
|
||||
|
||||
// 设置header
|
||||
CtripCreateOrderRequest.CtripHeader header = new CtripCreateOrderRequest.CtripHeader();
|
||||
header.setRequestTime("2024-12-19 10:00:00");
|
||||
header.setAccountId("testAccount");
|
||||
header.setSign("testSign");
|
||||
header.setServiceName("createOrder");
|
||||
header.setVersion("1.0");
|
||||
request.setHeader(header);
|
||||
|
||||
// 设置body为对象
|
||||
CtripCreateOrderRequest.CtripOrderBody body = new CtripCreateOrderRequest.CtripOrderBody();
|
||||
body.setOtaOrderId("CTRIP123456");
|
||||
body.setSequenceId("SEQ123456");
|
||||
|
||||
// 设置item
|
||||
CtripCreateOrderRequest.CtripOrderItem item = new CtripCreateOrderRequest.CtripOrderItem();
|
||||
item.setCost(new BigDecimal("100.00"));
|
||||
item.setQuantity(1);
|
||||
item.setSalePrice(new BigDecimal("80.00"));
|
||||
item.setPrice(new BigDecimal("100.00"));
|
||||
item.setUseStartDate("2024-12-20");
|
||||
item.setUseEndDate("2024-12-25");
|
||||
item.setAdjunctions(Arrays.asList("adj1", "adj2"));
|
||||
item.setDeposit(new Object());
|
||||
item.setDistributionChannel("online");
|
||||
item.setPriceCurrency("CNY");
|
||||
item.setCostCurrency("CNY");
|
||||
item.setSalePriceCurrency("CNY");
|
||||
|
||||
// 设置passenger
|
||||
CtripCreateOrderRequest.CtripPassenger passenger = new CtripCreateOrderRequest.CtripPassenger();
|
||||
passenger.setName("张三");
|
||||
passenger.setMobile("13800138000");
|
||||
passenger.setGender("M");
|
||||
passenger.setCardType("ID");
|
||||
passenger.setCardNo("110101199001011234");
|
||||
item.setPassengers(Arrays.asList(passenger));
|
||||
|
||||
body.setItems(Arrays.asList(item));
|
||||
|
||||
// 设置contact
|
||||
CtripCreateOrderRequest.CtripContact contact = new CtripCreateOrderRequest.CtripContact();
|
||||
contact.setName("张三");
|
||||
contact.setMobile("13800138000");
|
||||
contact.setEmail("zhangsan@example.com");
|
||||
body.setContacts(Arrays.asList(contact));
|
||||
|
||||
request.setBody(body);
|
||||
|
||||
// 测试序列化
|
||||
String json = objectMapper.writeValueAsString(request);
|
||||
assertNotNull(json);
|
||||
assertTrue(json.contains("CTRIP123456"));
|
||||
assertTrue(json.contains("testAccount"));
|
||||
|
||||
System.out.println("JSON序列化测试通过!");
|
||||
System.out.println("生成的JSON: " + json);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorHandling() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 测试错误的JSON格式
|
||||
String invalidJson = "{\"invalid\": \"data\"}";
|
||||
|
||||
try {
|
||||
CtripCreateOrderRequest request = objectMapper.readValue(invalidJson, CtripCreateOrderRequest.class);
|
||||
// 如果没有抛出异常,说明@JsonIgnoreProperties生效了
|
||||
assertNotNull(request);
|
||||
System.out.println("错误处理测试通过 - 忽略未知属性");
|
||||
} catch (Exception e) {
|
||||
// 如果抛出异常,也是正常的
|
||||
System.out.println("错误处理测试通过 - 捕获到异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncryptedDataHandling() {
|
||||
// 测试加密数据处理
|
||||
String encryptedData = "anipkokpjcnikijobbdgmeddhnmngkidmfoeamjgmmjenpikgpeafnoonnjppdlhhhoidlopkfbpepchhbikpeiaogpmglhjbcaoomkponmciaphjjajhogmmagkiflikbffgmgkinckainhidjjmmoifodpakdlacfepfphenlflpcpdmjpnpaocckibgoagfcncpjnkhaniibphkmgknjabnfoeiblkfbmpekpkpaolangbbpflclbnbmffcaaemnaceckfmaegfnoclpgkblgpjggkjdmkbnkbffacmlpbnefipiaenjclfppilnedllghnejhdchhkdacadanioehbpbdmghioohnjbaamahjdoebckhhljnohfaddbndlepilbnngdhlmfbajnjchllinafbpeldcaacnddmieipmnikgbbbmjpbnpofceacdecjdifkmipeknimidgpbjpdoclimemkjmjhnneghcknneambllglnahlkenngnakncoijpggpdafipbladoaadbdfdebkcjfkaopaieknmjfopbojgljmlgkehmgoghnhggppbeoflhgfijjoabbmkipehekdpchlagnlbdidbmdmghdhoicoapnneljedkkaiikieneiopokkbidoigjlbmkkpeilapilhcmdkaiokiciaacenikijicllgdkbhlenhhcdapipkjhompefkfeginnmgmkjjooleihjfnjofkdgelojfboejjdopiajgldoppcaepkoceffkfjacfcpcbfcblgkaigddakfagnijfjdombelmfgjgopighebpdgbfcbmbecblhdgfbgkoacoiemfelalemmnkeejnighfgmlbenocgdlmoelbcakjppjlpoecimikkbcjblemhbhcgnapcmjbbflgmlfkllmpgdmhiagpolnlccanjdbajnbieapghplipmemakjkkfgphligccnlpjhgeiglbpdcejaajfhjfkplhocifopajenpmdmpncbpkhbbnpnbckmkahemfddhkgijgagkbmpigmbdedmkonkcchimohghkojhmgfeafpefoefccbjjkfkdcedbcmlgomoicfihhaalamkafkmfefdlihpopbdomkiodfdaiogemkebjmbgnfodmnbfedbaacdlmmangllfjihbhmngeoibobbjjmfmfdmpncdpbnfhcggonmfnpifhbjbjlnmcffdpnjpajkgdhllhdpffbdnioacknijcabmncijgmepdkipfpncchmaiamlmfpbcjamggjdjeokhdepklpflafjolemjednbbfmgoikkmfdhgnfiomkaahccnflpdlholfdkncdimgdgfmjdahadbohhfiamlfggljdeahjaaoopclacaakmpobapkhnbmcfmlbobdhblillhdbmmnoaaaeedaleehgpeofipljnmloicglmdmefpkdiplhlmhgiafhjjijigeapikdcdaoallpjlcmebbcohnmlacnkcbcnjkapdaeemkgcgbodjbneaapdgomhbmoljahdlmffnebohgngnfhkjlhejfebgjcccfpmclbeooaghapbkdcjicgjpjnjcgfnhefcmkknglodcoajnobpakaempkbllghgfcobefnebjnaniocjmdedcbgpbbacelfecgemifkedogbloplckenjopknbpfgabpfnaphcklifibbhgohhkjldaekcedkeimlmegdhbjnffililaamfbfdkakleknjdjahogknimijcdahggheehclghkbkkclebcgopeabkkcceiahldnmnffhkgcdbahaldpgddehbpjieaojnknbedoinappdpjjkinjcgiodfahffppcpkeaelgcabkelblhlbbddbemckhkjldpndoohboioplpdohngjpbdegfcnhloenmncalldemhoigglahmnpcdepjfmfhdekbnombijpcfiggmllpglbghlelijohdegkkmicbcgioccekjbhfhoimhdpcejcjcjlmohpfiijjpmknihlhgjeniknkjlhjdgemjgjbnahdhjgobmgonnlljhpendhke";
|
||||
|
||||
// 验证这是一个长字符串而不是JSON
|
||||
assertFalse(encryptedData.startsWith("{"));
|
||||
assertFalse(encryptedData.endsWith("}"));
|
||||
assertTrue(encryptedData.length() > 1000);
|
||||
|
||||
System.out.println("加密数据处理测试通过 - 识别为非JSON格式的长字符串");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testOrderCreation() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 构建测试JSON - 实际的携程订单数据
|
||||
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\": {\n" +
|
||||
" \"otaOrderId\": \"ctriptest-10816912-454259-145573\",\n" +
|
||||
" \"sequenceId\": \"2025080122580189a0fbcc46364e1ab3b47fc7c20e3767\",\n" +
|
||||
" \"items\": [\n" +
|
||||
" {\n" +
|
||||
" \"passengers\": [\n" +
|
||||
" {\n" +
|
||||
" \"cardIssuePlace\": \"\",\n" +
|
||||
" \"lastName\": \"\",\n" +
|
||||
" \"cardIssueCountry\": \"\",\n" +
|
||||
" \"shoeSize\": 0,\n" +
|
||||
" \"gender\": \"M\",\n" +
|
||||
" \"cardIssueDate\": \"\",\n" +
|
||||
" \"intlCode\": \"+86\",\n" +
|
||||
" \"nationalityName\": \"\",\n" +
|
||||
" \"mobile\": \"18322694510\",\n" +
|
||||
" \"cardType\": \"1\",\n" +
|
||||
" \"weight\": 0,\n" +
|
||||
" \"myopiaDegreeL\": 0,\n" +
|
||||
" \"birthDate\": \"2025-07-10\",\n" +
|
||||
" \"cardNo\": \"620421198909185197\",\n" +
|
||||
" \"ageType\": \"ADU\",\n" +
|
||||
" \"myopiaDegreeR\": 0,\n" +
|
||||
" \"firstName\": \"sl\",\n" +
|
||||
" \"birthPlace\": \"\",\n" +
|
||||
" \"nationalityCode\": \"\",\n" +
|
||||
" \"name\": \"李世琳\",\n" +
|
||||
" \"passengerId\": \"33c0b8013a554c5c8f59e7e0fac6ef32\",\n" +
|
||||
" \"cardValidDate\": \"\",\n" +
|
||||
" \"height\": 0\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"cost\": 2.00,\n" +
|
||||
" \"quantity\": 1,\n" +
|
||||
" \"salePrice\": 2.00,\n" +
|
||||
" \"remark\": \"This is remark\",\n" +
|
||||
" \"useEndDate\": \"2025-07-25\",\n" +
|
||||
" \"locale\": \"zh-CN\",\n" +
|
||||
" \"useStartDate\": \"2025-07-25\",\n" +
|
||||
" \"priceCurrency\": \"CNY\",\n" +
|
||||
" \"adjunctions\": [],\n" +
|
||||
" \"price\": 2.00,\n" +
|
||||
" \"PLU\": \"1\",\n" +
|
||||
" \"deposit\": {},\n" +
|
||||
" \"distributionChannel\": \"XCW\",\n" +
|
||||
" \"costCurrency\": \"CNY\",\n" +
|
||||
" \"salePriceCurrency\": \"CNY\",\n" +
|
||||
" \"expressDelivery\": {\n" +
|
||||
" \"type\": \"1\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"contacts\": [\n" +
|
||||
" {\n" +
|
||||
" \"intlCode\": \"+86\",\n" +
|
||||
" \"name\": \"李世琳\",\n" +
|
||||
" \"mobile\": \"18322694510\",\n" +
|
||||
" \"optionalMobile\": \"13333333333\",\n" +
|
||||
" \"optionalIntlCode\": \"86\",\n" +
|
||||
" \"email\": \"1272745473@qq.com\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }\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 CtripCreateOrderRequest.CtripOrderBody);
|
||||
CtripCreateOrderRequest.CtripOrderBody body = (CtripCreateOrderRequest.CtripOrderBody) request.getBody();
|
||||
assertEquals("ctriptest-10816912-454259-145573", body.getOtaOrderId());
|
||||
|
||||
// 验证订单项
|
||||
assertNotNull(body.getItems());
|
||||
assertFalse(body.getItems().isEmpty());
|
||||
|
||||
CtripCreateOrderRequest.CtripOrderItem item = body.getItems().get(0);
|
||||
assertNotNull(item.getPassengers());
|
||||
assertFalse(item.getPassengers().isEmpty());
|
||||
assertEquals("李世琳", item.getPassengers().get(0).getName());
|
||||
assertEquals("18322694510", item.getPassengers().get(0).getMobile());
|
||||
assertEquals(new java.math.BigDecimal("2.00"), item.getSalePrice());
|
||||
|
||||
// 验证联系人
|
||||
assertNotNull(body.getContacts());
|
||||
assertFalse(body.getContacts().isEmpty());
|
||||
assertEquals("李世琳", body.getContacts().get(0).getName());
|
||||
assertEquals("18322694510", body.getContacts().get(0).getMobile());
|
||||
|
||||
System.out.println("订单创建测试通过!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCtripCouponCreation() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// 构建测试JSON - 实际的携程优惠券数据
|
||||
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\": {\n" +
|
||||
" \"otaOrderId\": \"ctriptest-10816912-454259-145573\",\n" +
|
||||
" \"sequenceId\": \"2025080122580189a0fbcc46364e1ab3b47fc7c20e3767\",\n" +
|
||||
" \"items\": [\n" +
|
||||
" {\n" +
|
||||
" \"passengers\": [\n" +
|
||||
" {\n" +
|
||||
" \"cardIssuePlace\": \"\",\n" +
|
||||
" \"lastName\": \"\",\n" +
|
||||
" \"cardIssueCountry\": \"\",\n" +
|
||||
" \"shoeSize\": 0,\n" +
|
||||
" \"gender\": \"M\",\n" +
|
||||
" \"cardIssueDate\": \"\",\n" +
|
||||
" \"intlCode\": \"+86\",\n" +
|
||||
" \"nationalityName\": \"\",\n" +
|
||||
" \"mobile\": \"18322694510\",\n" +
|
||||
" \"cardType\": \"1\",\n" +
|
||||
" \"weight\": 0,\n" +
|
||||
" \"myopiaDegreeL\": 0,\n" +
|
||||
" \"birthDate\": \"2025-07-10\",\n" +
|
||||
" \"cardNo\": \"620421198909185197\",\n" +
|
||||
" \"ageType\": \"ADU\",\n" +
|
||||
" \"myopiaDegreeR\": 0,\n" +
|
||||
" \"firstName\": \"sl\",\n" +
|
||||
" \"birthPlace\": \"\",\n" +
|
||||
" \"nationalityCode\": \"\",\n" +
|
||||
" \"name\": \"李世琳\",\n" +
|
||||
" \"passengerId\": \"33c0b8013a554c5c8f59e7e0fac6ef32\",\n" +
|
||||
" \"cardValidDate\": \"\",\n" +
|
||||
" \"height\": 0\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"cost\": 2.00,\n" +
|
||||
" \"quantity\": 1,\n" +
|
||||
" \"salePrice\": 2.00,\n" +
|
||||
" \"remark\": \"This is remark\",\n" +
|
||||
" \"useEndDate\": \"2025-07-25\",\n" +
|
||||
" \"locale\": \"zh-CN\",\n" +
|
||||
" \"useStartDate\": \"2025-07-25\",\n" +
|
||||
" \"priceCurrency\": \"CNY\",\n" +
|
||||
" \"adjunctions\": [],\n" +
|
||||
" \"price\": 2.00,\n" +
|
||||
" \"PLU\": \"1\",\n" +
|
||||
" \"deposit\": {},\n" +
|
||||
" \"distributionChannel\": \"XCW\",\n" +
|
||||
" \"costCurrency\": \"CNY\",\n" +
|
||||
" \"salePriceCurrency\": \"CNY\",\n" +
|
||||
" \"expressDelivery\": {\n" +
|
||||
" \"type\": \"1\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"contacts\": [\n" +
|
||||
" {\n" +
|
||||
" \"intlCode\": \"+86\",\n" +
|
||||
" \"name\": \"李世琳\",\n" +
|
||||
" \"mobile\": \"18322694510\",\n" +
|
||||
" \"optionalMobile\": \"13333333333\",\n" +
|
||||
" \"optionalIntlCode\": \"86\",\n" +
|
||||
" \"email\": \"1272745473@qq.com\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }\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 CtripCreateOrderRequest.CtripOrderBody);
|
||||
CtripCreateOrderRequest.CtripOrderBody body = (CtripCreateOrderRequest.CtripOrderBody) request.getBody();
|
||||
assertEquals("ctriptest-10816912-454259-145573", body.getOtaOrderId());
|
||||
|
||||
// 验证订单项
|
||||
assertNotNull(body.getItems());
|
||||
assertFalse(body.getItems().isEmpty());
|
||||
|
||||
CtripCreateOrderRequest.CtripOrderItem item = body.getItems().get(0);
|
||||
assertNotNull(item.getPassengers());
|
||||
assertFalse(item.getPassengers().isEmpty());
|
||||
assertEquals("李世琳", item.getPassengers().get(0).getName());
|
||||
assertEquals("18322694510", item.getPassengers().get(0).getMobile());
|
||||
assertEquals(new java.math.BigDecimal("2.00"), item.getSalePrice());
|
||||
|
||||
// 验证联系人
|
||||
assertNotNull(body.getContacts());
|
||||
assertFalse(body.getContacts().isEmpty());
|
||||
assertEquals("李世琳", body.getContacts().get(0).getName());
|
||||
assertEquals("18322694510", body.getContacts().get(0).getMobile());
|
||||
|
||||
System.out.println("携程优惠券创建测试通过!");
|
||||
System.out.println("接口路径: /coupon/ctrip/create");
|
||||
System.out.println("请求方法: POST");
|
||||
System.out.println("Content-Type: application/json");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user