|
@@ -1,11 +1,8 @@
|
|
|
package com.kym.miniapp.controller;
|
|
package com.kym.miniapp.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
-import cn.hutool.core.io.IoUtil;
|
|
|
|
|
-import cn.hutool.core.util.CharsetUtil;
|
|
|
|
|
-import cn.hutool.core.util.XmlUtil;
|
|
|
|
|
import com.kym.common.annotation.ApiLog;
|
|
import com.kym.common.annotation.ApiLog;
|
|
|
-import com.kym.common.utils.CommUtil;
|
|
|
|
|
|
|
+import com.kym.service.wechat.WeixinMPService;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -14,15 +11,18 @@ import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
-import java.io.PrintWriter;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
@Controller
|
|
@Controller
|
|
|
@RequestMapping("wx")
|
|
@RequestMapping("wx")
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
-public class WeixinController {
|
|
|
|
|
|
|
+public class WeixinMPController {
|
|
|
|
|
+
|
|
|
|
|
+ private final WeixinMPService weixinMPService;
|
|
|
|
|
+
|
|
|
|
|
+ public WeixinMPController(WeixinMPService weixinMPService) {
|
|
|
|
|
+ this.weixinMPService = weixinMPService;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 消息通知(订阅、用户消息)
|
|
* 消息通知(订阅、用户消息)
|
|
|
*
|
|
*
|
|
@@ -30,36 +30,14 @@ public class WeixinController {
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
@PostMapping(value = "check", produces = MediaType.TEXT_XML_VALUE)
|
|
@PostMapping(value = "check", produces = MediaType.TEXT_XML_VALUE)
|
|
|
- @ApiLog("微信公众号服务器推送消息")
|
|
|
|
|
|
|
+ @ApiLog(value = "微信公众号服务器推送消息", ignoreParams = true)
|
|
|
public void handleMessage(HttpServletRequest request, HttpServletResponse response) {
|
|
public void handleMessage(HttpServletRequest request, HttpServletResponse response) {
|
|
|
- String result = "";
|
|
|
|
|
- try {
|
|
|
|
|
- String xml = IoUtil.read(request.getInputStream(), CharsetUtil.CHARSET_UTF_8);
|
|
|
|
|
- log.info("wx mp receive xml message:\n{}", xml);
|
|
|
|
|
-
|
|
|
|
|
- Map<String, Object> ret = XmlUtil.xmlToMap(xml);
|
|
|
|
|
- log.info("wx mp receive map message:\n{}", ret);
|
|
|
|
|
- if (!CommUtil.isEmptyOrNull(ret)) {
|
|
|
|
|
- response.setContentType("text/html");
|
|
|
|
|
- result = XmlUtil.mapToXmlStr(ret);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("WxController.handleMessage ERR", e);
|
|
|
|
|
- } finally {
|
|
|
|
|
- try {
|
|
|
|
|
- log.info("WxController.handleMessage response: \n{}", result);
|
|
|
|
|
- PrintWriter writer = response.getWriter();
|
|
|
|
|
- writer.print(result);
|
|
|
|
|
- writer.close();
|
|
|
|
|
- } catch (IOException e) {
|
|
|
|
|
- log.error(e.getMessage(), e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ weixinMPService.handleWxMPNotify(request, response);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// @Resource
|
|
// @Resource
|
|
|
// WxMpService wxMpService;
|
|
// WxMpService wxMpService;
|
|
|
-// private Logger logger = LoggerFactory.getLogger(WeixinController.class);
|
|
|
|
|
|
|
+// private Logger logger = LoggerFactory.getLogger(WeixinMPController.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
/*
|