|
@@ -2,6 +2,8 @@ package com.jpsoft.weixin.controller;
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.itextpdf.text.io.StreamUtil;
|
|
|
import com.jpsoft.weixin.callback.EventCallback;
|
|
|
import com.jpsoft.weixin.config.PICCAdminScanConfig;
|
|
|
import com.jpsoft.weixin.config.PICCEntScanConfig;
|
|
@@ -27,14 +29,18 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.data.redis.core.ValueOperations;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.util.StreamUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStreamReader;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Api(description = "微信中控")
|
|
|
@Controller
|
|
@@ -71,7 +77,7 @@ public class WeixinController {
|
|
|
return echostr;
|
|
|
}
|
|
|
else{
|
|
|
- return null;
|
|
|
+ return "index";
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -132,18 +138,30 @@ public class WeixinController {
|
|
|
@PostMapping("/")
|
|
|
public void processEvent(HttpServletRequest request, HttpServletResponse response){
|
|
|
try{
|
|
|
- Map<String,Object> dataMap = WeixinUtil.xmlToMap(request.getInputStream());
|
|
|
+ log.warn("收到post请求");
|
|
|
+
|
|
|
+ JSONObject requestJson = null;
|
|
|
+
|
|
|
+ if("json".equals(weixinConfig.getContentType())){
|
|
|
+ String jsonStr = new BufferedReader(new InputStreamReader(request.getInputStream()))
|
|
|
+ .lines().parallel().collect(Collectors.joining(System.lineSeparator()));
|
|
|
+
|
|
|
+ requestJson = new JSONObject(jsonStr);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ requestJson = WeixinUtil.xmlToJson(request.getInputStream());
|
|
|
+ }
|
|
|
|
|
|
//{Ticket=gQEH8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyckZDekV1RHg5SFAxczNwYjF1MWIAAgTX10teAwQsAQAA, CreateTime=1582028776, EventKey=1457, Event=SCAN, ToUserName=gh_b6e865f48dea, FromUserName=op6Frsy4xuXYGqjaJ12Xv5Q-9NtU, MsgType=event}
|
|
|
- log.warn(dataMap.toString());
|
|
|
+ log.warn(requestJson.toString());
|
|
|
|
|
|
response.setContentType("UTF-8");
|
|
|
response.setContentType("text/html; charset=UTF-8");
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
|
|
|
|
- String eventKey = (String)dataMap.get("EventKey");
|
|
|
- String toUserName = (String)dataMap.get("ToUserName");
|
|
|
- String fromUserName = (String)dataMap.get("FromUserName");
|
|
|
+ String eventKey = requestJson.getStr("EventKey");
|
|
|
+ String toUserName = requestJson.getStr("ToUserName");
|
|
|
+ String fromUserName = requestJson.getStr("FromUserName");
|
|
|
|
|
|
List<EventCallback> callbackList = registerCallbackList();
|
|
|
|
|
@@ -171,6 +189,12 @@ public class WeixinController {
|
|
|
}
|
|
|
catch (Exception ex){
|
|
|
log.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ try {
|
|
|
+ response.getWriter().print("fail");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|