diff --git a/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java b/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java index 73f24d48a..5509d5bea 100644 --- a/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java +++ b/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java @@ -34,11 +34,11 @@ public class NotifyController { @RequestMapping("payCallBack") public String notifyCallBack(HttpServletRequest request, @RequestBody CzgBaseRespParams respParams) throws IOException { + JSONObject czg = CzgPayUtils.getCzg(respParams); + log.info("2支付回调数据为:{}", czg); Map map = getRequestParams(request); log.info("1支付回调数据为:{}", map); - JSONObject czg = CzgPayUtils.getCzg(respParams); AssertUtil.isNull(czg, "回调数据为空"); - log.info("2支付回调数据为:{}", czg); orderInfoService.payCallBackOrder(czg.getString("mchOrderNo"), czg); return SUCCESS; } @@ -53,20 +53,9 @@ public class NotifyController { */ public static Map getRequestParams(HttpServletRequest request) throws IOException { Map params = new HashMap<>(); - - // 获取查询参数 - Enumeration paramNames = request.getParameterNames(); - while (paramNames.hasMoreElements()) { - String paramName = paramNames.nextElement(); - String paramValue = request.getParameter(paramName); - params.put(paramName, paramValue); - } - log.info("param体请求参数为:{}", params); - // 如果是 POST 请求,尝试读取请求体 - if ("POST" .equalsIgnoreCase(request.getMethod())) { + if ("POST".equalsIgnoreCase(request.getMethod())) { String contentType = request.getContentType(); - if (contentType != null && contentType.startsWith("application/json")) { - // 处理 JSON 格式的请求体 + if (contentType != null) { StringBuilder sb = new StringBuilder(); try (BufferedReader reader = request.getReader()) { String line; @@ -74,17 +63,23 @@ public class NotifyController { sb.append(line); } } + if (!sb.isEmpty()) { - // 这里只是简单将 JSON 字符串作为一个整体参数,实际使用中可能需要解析 JSON - params.put("requestBody", sb.toString()); - } - } else if (contentType != null && contentType.startsWith("application/x-www-form-urlencoded")) { - // 处理表单格式的请求体 - Enumeration bodyParamNames = request.getParameterNames(); - while (bodyParamNames.hasMoreElements()) { - String paramName = bodyParamNames.nextElement(); - String paramValue = request.getParameter(paramName); - params.put(paramName, paramValue); + if (contentType.startsWith("application/json")) { + // 处理 JSON 格式的请求体 + params.put("requestBody", sb.toString()); + } else if (contentType.startsWith("application/x-www-form-urlencoded")) { + // 处理表单格式的请求体 + String[] pairs = sb.toString().split("&"); + for (String pair : pairs) { + String[] keyValue = pair.split("=", 2); + if (keyValue.length == 2) { + String paramName = keyValue[0]; + String paramValue = keyValue[1]; + params.put(paramName, paramValue); + } + } + } } } }