diff --git a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaPayServiceImpl.java b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaPayServiceImpl.java index 05386611..8fe801f8 100644 --- a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaPayServiceImpl.java +++ b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaPayServiceImpl.java @@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Lazy; import org.springframework.data.util.Pair; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -298,20 +299,30 @@ public class LakalaPayServiceImpl implements LakalaPayService { JSONObject header = new JSONObject(); header.put("Authorization", authorization); - JSONObject lakalaRespJSON = RestTemplateHttpUtil.sendLklPost(reqUrl, header, reqBody, JSONObject.class); + // 这里的请求方法,对返回的字段进行了处理,需要注意 + ResponseEntity lakalaRespJSON = RestTemplateHttpUtil.sendPostBodyBackEntity(reqUrl, header, reqBody, JSONObject.class); log.debug("拉卡拉合单交易响应参数:{}", lakalaRespJSON); // 7. 处理响应结果 - if (ObjectUtil.isNotEmpty(lakalaRespJSON) && lklPaySuccessCode.equals(lakalaRespJSON.getStr("retCode"))) { - // 新增一个拉卡拉订单记录 shop_order_lkl 表 - JSONObject lklPayReqAndRespJson = new JSONObject(); - lklPayReqAndRespJson.put("req", reqData); - lklPayReqAndRespJson.put("resp", lakalaRespJSON); - shopService.lklPayAddShopOrderLkl(lklPayReqAndRespJson); + if (lakalaRespJSON == null) { + return new JSONObject().set("code", "BBS00001").set("msg", "拉卡拉合单交易无响应值").set("resp_data", null); } + JSONObject respBody = lakalaRespJSON.getBody(); + + // 7. 处理响应结果 + if (!lklPaySuccessCode.equals(respBody.getStr("code")) || respBody == null) { + return new JSONObject().set("code", "BBS00001").set("msg", "拉卡拉合单交易无响应值").set("resp_data", null); + } + + // 新增一个拉卡拉订单记录 shop_order_lkl 表 + JSONObject lklPayReqAndRespJson = new JSONObject(); + lklPayReqAndRespJson.put("req", reqData); + lklPayReqAndRespJson.put("resp", respBody); // 返回原始响应数据 + shopService.lklPayAddShopOrderLkl(lklPayReqAndRespJson); + // 8. 返回响应结果 - return lakalaRespJSON; + return respBody; } catch (Exception e) { log.error("拉卡拉合单交易出错,订单号:{},错误信息:", orderId, e); diff --git a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayUserPayServiceImpl.java b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayUserPayServiceImpl.java index 9ff56ce8..3f834bad 100644 --- a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayUserPayServiceImpl.java +++ b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayUserPayServiceImpl.java @@ -688,7 +688,7 @@ public class PayUserPayServiceImpl extends BaseServiceImpl