1
This commit is contained in:
@@ -188,20 +188,34 @@ public class JDOrderController extends BaseController {
|
||||
Object parsed = JSON.parse(result);
|
||||
logger.info("创建礼金响应 - 解析后: {}", parsed);
|
||||
|
||||
// 检查返回结果中giftCouponKey是否为null
|
||||
// 检查返回结果格式
|
||||
if (parsed instanceof JSONObject) {
|
||||
JSONObject jsonObj = (JSONObject) parsed;
|
||||
|
||||
// 检查是否是错误响应(JD项目error方法返回的是{"error": "..."}格式)
|
||||
if (jsonObj.containsKey("error")) {
|
||||
String errorMsg = jsonObj.getString("error");
|
||||
logger.error("创建礼金失败 - JD项目返回错误,请求参数: materialUrl={}, skuId={}, amount={}, quantity={}, owner={}, skuName={}, 错误信息: {}",
|
||||
body.get("materialUrl"), body.get("skuId"), body.get("amount"), body.get("quantity"),
|
||||
body.get("owner"), body.get("skuName"), errorMsg);
|
||||
return AjaxResult.error(errorMsg);
|
||||
}
|
||||
|
||||
// 检查giftCouponKey是否为null(兼容旧格式)
|
||||
Object giftKey = jsonObj.get("giftCouponKey");
|
||||
if (giftKey == null) {
|
||||
// giftCouponKey为null,说明创建失败
|
||||
if (giftKey == null || (giftKey instanceof String && ((String) giftKey).trim().isEmpty())) {
|
||||
// giftCouponKey为null或空,说明创建失败
|
||||
String errorMsg = jsonObj.getString("msg");
|
||||
if (errorMsg == null || errorMsg.isEmpty()) {
|
||||
errorMsg = "礼金创建失败,返回的giftCouponKey为null。可能是商品不支持创建礼金、参数错误或京东API调用失败,请查看JD项目日志";
|
||||
}
|
||||
logger.error("创建礼金失败 - giftCouponKey为null,返回数据: {}", jsonObj.toJSONString());
|
||||
logger.error("创建礼金失败 - giftCouponKey为null,请求参数: materialUrl={}, skuId={}, amount={}, quantity={}, owner={}, skuName={}, 返回数据: {}",
|
||||
body.get("materialUrl"), body.get("skuId"), body.get("amount"), body.get("quantity"),
|
||||
body.get("owner"), body.get("skuName"), jsonObj.toJSONString());
|
||||
return AjaxResult.error(errorMsg);
|
||||
}
|
||||
logger.info("创建礼金成功 - giftCouponKey: {}", giftKey);
|
||||
|
||||
logger.info("创建礼金成功 - giftCouponKey: {}, 请求参数: owner={}, skuId={}", giftKey, body.get("owner"), body.get("skuId"));
|
||||
}
|
||||
|
||||
return AjaxResult.success(parsed);
|
||||
|
||||
Reference in New Issue
Block a user