|
@@ -1,58 +1,61 @@
|
|
|
package com.kym.miniapp.controller;
|
|
package com.kym.miniapp.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
-import com.kym.common.annotation.SysLog;
|
|
|
|
|
-import com.kym.common.utils.wx.WxPbUtil;
|
|
|
|
|
-import jakarta.annotation.Resource;
|
|
|
|
|
|
|
+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.utils.CommUtil;
|
|
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
-import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
|
|
-import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
|
|
-import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
|
|
|
|
-import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
|
|
|
|
-import org.slf4j.Logger;
|
|
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.io.PrintWriter;
|
|
import java.io.PrintWriter;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
-@RestController
|
|
|
|
|
|
|
+@Controller
|
|
|
@RequestMapping("wx")
|
|
@RequestMapping("wx")
|
|
|
|
|
+@Slf4j
|
|
|
public class WeixinController {
|
|
public class WeixinController {
|
|
|
/**
|
|
/**
|
|
|
* 消息通知(订阅、用户消息)
|
|
* 消息通知(订阅、用户消息)
|
|
|
*
|
|
*
|
|
|
* @param request
|
|
* @param request
|
|
|
- *//*
|
|
|
|
|
|
|
+ */
|
|
|
|
|
|
|
|
@PostMapping(value = "check", produces = MediaType.TEXT_XML_VALUE)
|
|
@PostMapping(value = "check", produces = MediaType.TEXT_XML_VALUE)
|
|
|
- @SysLog("微信服务器推送消息")
|
|
|
|
|
|
|
+ @ApiLog("微信公众号服务器推送消息")
|
|
|
public void handleMessage(HttpServletRequest request, HttpServletResponse response) {
|
|
public void handleMessage(HttpServletRequest request, HttpServletResponse response) {
|
|
|
String result = "";
|
|
String result = "";
|
|
|
try {
|
|
try {
|
|
|
- String xml = IoUtil.getContent(request.getInputStream());
|
|
|
|
|
- logger.info("wx pb receive message:\n{}", xml);
|
|
|
|
|
- Map<String, Object> ret = wxPbService.handleMessage(xml);
|
|
|
|
|
|
|
+ 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)) {
|
|
if (!CommUtil.isEmptyOrNull(ret)) {
|
|
|
response.setContentType("text/html");
|
|
response.setContentType("text/html");
|
|
|
- result = XmlUtil.map2xml(ret);
|
|
|
|
|
|
|
+ result = XmlUtil.mapToXmlStr(ret);
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- logger.error("WxPbController.handleMessage ERR", e);
|
|
|
|
|
|
|
+ log.error("WxController.handleMessage ERR", e);
|
|
|
} finally {
|
|
} finally {
|
|
|
try {
|
|
try {
|
|
|
- logger.info("WxPbController.handleMessage response: \n{}",result);
|
|
|
|
|
|
|
+ log.info("WxController.handleMessage response: \n{}", result);
|
|
|
PrintWriter writer = response.getWriter();
|
|
PrintWriter writer = response.getWriter();
|
|
|
writer.print(result);
|
|
writer.print(result);
|
|
|
writer.close();
|
|
writer.close();
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
|
- logger.error(e.getMessage(),e);
|
|
|
|
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-*/
|
|
|
|
|
|
|
|
|
|
// @Resource
|
|
// @Resource
|
|
|
// WxMpService wxMpService;
|
|
// WxMpService wxMpService;
|