@PostMapping("payAccept")
public void payAccept() throws IOException {
log.info("接收到支付通知1111111111");
Map<String, String> response;
try {
log.info("接收到支付通知2222222222222222");
String requestStr = HttpsUtil.parseRequst(HttpsUtil.request());
log.debug("回调参数 : " + requestStr);
response = HttpsUtil.toMap(requestStr.getBytes(), "UTF-8");
if ("SUCCESS".equals(response.get("return_code"))) {
log.debug("***支付成功回调参数:** " + response);
SortedMap<Object, Object> parameters = new TreeMap<Object, Object>();
parameters.putAll(response);
String appid = response.get("appid");
parameters.put("key", PayConfig.key);
String signCheck = WeixinUtil.createSign("UTF-8", parameters);
if (!signCheck.equals(response.get("sign"))) {
return;
}
if ("SUCCESS".equals(response.get("result_code"))) {
log.debug("***支付成功回调参数222222:** ");
}else {
HttpsUtil.response().getWriter().write(WeixinUtil.SUCCESS);
}
HttpsUtil.response().getWriter().write(WeixinUtil.SUCCESS);
return;
}
} catch (Exception e) {
e.printStackTrace();
log.error("发送通知异常:"+e.toString());
}
}
public static HttpServletRequest request() {
HttpServletRequest request = (HttpServletRequest) currentRequest.get();
logger.debug("Request parameters:");
Enumeration<String> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
String paramName = parameterNames.nextElement();
String paramValue = request.getParameter(paramName);
logger.debug("请求参数request:"+paramName + ": " + paramValue);
}
return request;
}
HttpsUtil.request()没有接收到任何参数,运行到log.info("接收到支付通知2222222222222222");就报空指针了。
直接去抄sdk的demo https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay6_0.shtml