|
@@ -105,6 +105,7 @@ public class TestController {
|
|
|
@GetMapping(value = "/notifyMsg")
|
|
|
@ApiOperation("处理服务器推送消息")
|
|
|
public String checkSign(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ log.info("-----------进入---------");
|
|
|
try {
|
|
|
String signature = request.getParameter("signature");
|
|
|
String timestamp = request.getParameter("timestamp");
|
|
@@ -115,9 +116,10 @@ public class TestController {
|
|
|
log.info("-----------微信验签---------");
|
|
|
return SignUtil.checkSignature(signature, timestamp, nonce) == true ? echostr : null;
|
|
|
}else{
|
|
|
- //推送消息处理
|
|
|
+ log.info("-----------推送消息处理---------");
|
|
|
handlePublicMsg(request);
|
|
|
}
|
|
|
+ log.info("-----------方法未执行---------");
|
|
|
} catch (Exception e) {
|
|
|
log.error("验证公众号token失败", e);
|
|
|
}
|
|
@@ -181,29 +183,34 @@ public class TestController {
|
|
|
* 处理微信公众号请求信息
|
|
|
*/
|
|
|
public String handlePublicMsg(HttpServletRequest request) throws Exception {
|
|
|
+ log.info("1....");
|
|
|
// 获得微信端返回的xml数据
|
|
|
- /*InputStream is = null;
|
|
|
+ InputStream is = null;
|
|
|
InputStreamReader isr = null;
|
|
|
- BufferedReader br = null;*/
|
|
|
+ BufferedReader br = null;
|
|
|
try {
|
|
|
- /*is = request.getInputStream();
|
|
|
+ is = request.getInputStream();
|
|
|
isr = new InputStreamReader(is, "utf-8");
|
|
|
br = new BufferedReader(isr);
|
|
|
+ log.info("2....");
|
|
|
String str = null;
|
|
|
StringBuffer returnXml= new StringBuffer();
|
|
|
while ((str = br.readLine()) != null) {
|
|
|
+ log.info("3....");
|
|
|
//返回的是xml数据
|
|
|
returnXml.append(str);
|
|
|
- }*/
|
|
|
+ }
|
|
|
// Map<String, String> decryptMap = xmlToMap(returnXml.toString());
|
|
|
- Map<String, String> decryptMap = xmlToMap(IOUtils.toString(request.getInputStream()));
|
|
|
+ Map<String, String> decryptMap = xmlToMap(returnXml.toString());
|
|
|
// // 得到公众号传来的加密信息并解密,得到的是明文xml数据
|
|
|
// String decryptXml = WXPublicUtils.decrypt(encryptMap.get("Encrypt"));
|
|
|
// 将xml数据转换为map
|
|
|
//Map<String, String> decryptMap = xmlToMap(encryptMap);
|
|
|
+ log.info("5....");
|
|
|
|
|
|
// 区分消息类型
|
|
|
String msgType = decryptMap.get("MsgType");
|
|
|
+ log.info("5.1...");
|
|
|
// 普通消息
|
|
|
if ("text".equals(msgType)) { // 文本消息
|
|
|
// todo 处理文本消息
|
|
@@ -216,6 +223,7 @@ public class TestController {
|
|
|
// 区分事件推送
|
|
|
String event = decryptMap.get("Event");
|
|
|
if ("subscribe".equals(event)) { // 订阅事件 或 未关注扫描二维码事件
|
|
|
+ log.info("5.2...");
|
|
|
// 返回消息时ToUserName的值与FromUserName的互换
|
|
|
Map<String, String> returnMap = new HashMap<>();
|
|
|
returnMap.put("ToUserName", decryptMap.get("FromUserName"));
|
|
@@ -228,6 +236,7 @@ public class TestController {
|
|
|
} else if ("unsubscribe".equals(event)) { // 取消订阅事件
|
|
|
// todo 处理取消订阅事件
|
|
|
} else if ("SCAN".equals(event)) { // 已关注扫描二维码事件
|
|
|
+ log.info("5.3...");
|
|
|
// 返回消息时ToUserName的值与FromUserName的互换
|
|
|
Map<String, String> returnMap = new HashMap<>();
|
|
|
returnMap.put("ToUserName", decryptMap.get("FromUserName"));
|
|
@@ -248,7 +257,7 @@ public class TestController {
|
|
|
} catch (Exception e) {
|
|
|
log.error("处理微信公众号请求信息,失败", e);
|
|
|
}
|
|
|
- return null;
|
|
|
+ return "22222";
|
|
|
}
|
|
|
|
|
|
|
|
@@ -261,6 +270,7 @@ public class TestController {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public static Map<String, String> xmlToMap(String strXML) throws Exception {
|
|
|
+ log.info("4....");
|
|
|
try {
|
|
|
Map<String, String> data = new HashMap<>();
|
|
|
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|