|
@@ -1,15 +1,14 @@
|
|
package com.jpsoft.weixin.controller;
|
|
package com.jpsoft.weixin.controller;
|
|
|
|
|
|
-import cn.hutool.core.date.DateTime;
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
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.callback.EventCallback;
|
|
import com.jpsoft.weixin.callback.PromotionCallback;
|
|
import com.jpsoft.weixin.callback.PromotionCallback;
|
|
import com.jpsoft.weixin.config.PICCAdminScanConfig;
|
|
import com.jpsoft.weixin.config.PICCAdminScanConfig;
|
|
import com.jpsoft.weixin.config.PICCEntScanConfig;
|
|
import com.jpsoft.weixin.config.PICCEntScanConfig;
|
|
import com.jpsoft.weixin.config.WeixinConfig;
|
|
import com.jpsoft.weixin.config.WeixinConfig;
|
|
-import com.jpsoft.weixin.util.WeixinUtil;
|
|
|
|
|
|
+import com.jpsoft.weixin.entity.ReplyMessage;
|
|
|
|
+import com.jpsoft.weixin.service.ReplyMessageService;
|
|
|
|
+import com.jpsoft.weixin.utils.WeixinUtil;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
@@ -27,10 +26,10 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.HttpClientBuilder;
|
|
import org.apache.http.impl.client.HttpClientBuilder;
|
|
import org.apache.http.util.EntityUtils;
|
|
import org.apache.http.util.EntityUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.ValueOperations;
|
|
import org.springframework.data.redis.core.ValueOperations;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
-import org.springframework.util.StreamUtils;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -62,6 +61,9 @@ public class WeixinController {
|
|
@Autowired
|
|
@Autowired
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ReplyMessageService replyMessageService;
|
|
|
|
+
|
|
@ApiOperation(value="验证服务器地址的有效性")
|
|
@ApiOperation(value="验证服务器地址的有效性")
|
|
@GetMapping("/")
|
|
@GetMapping("/")
|
|
@ResponseBody
|
|
@ResponseBody
|
|
@@ -160,8 +162,11 @@ public class WeixinController {
|
|
response.setContentType("text/html; charset=UTF-8");
|
|
response.setContentType("text/html; charset=UTF-8");
|
|
response.setCharacterEncoding("UTF-8");
|
|
response.setCharacterEncoding("UTF-8");
|
|
|
|
|
|
|
|
+ String event = requestJson.getStr("Event");
|
|
String eventKey = requestJson.getStr("EventKey");
|
|
String eventKey = requestJson.getStr("EventKey");
|
|
|
|
+ //微信公众号编号
|
|
String toUserName = requestJson.getStr("ToUserName");
|
|
String toUserName = requestJson.getStr("ToUserName");
|
|
|
|
+ //扫码用户openID
|
|
String fromUserName = requestJson.getStr("FromUserName");
|
|
String fromUserName = requestJson.getStr("FromUserName");
|
|
|
|
|
|
List<EventCallback> callbackList = registerCallbackList();
|
|
List<EventCallback> callbackList = registerCallbackList();
|
|
@@ -185,7 +190,21 @@ public class WeixinController {
|
|
|
|
|
|
if(!processed) {
|
|
if(!processed) {
|
|
String responseText = "success";
|
|
String responseText = "success";
|
|
- response.getWriter().print(responseText);
|
|
|
|
|
|
+
|
|
|
|
+ if(event.equals("subscribe")){
|
|
|
|
+ ReplyMessage replyMessage = replyMessageService.findByEvent(toUserName,event);
|
|
|
|
+
|
|
|
|
+ if(replyMessage!=null) {
|
|
|
|
+ WeixinUtil.replyTextMessage(response, toUserName, fromUserName, replyMessage.getMessage());
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ log.warn(fromUserName + ",事件:" + event + "未设置自动回复!");
|
|
|
|
+ response.getWriter().print(responseText);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ response.getWriter().print(responseText);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex){
|
|
catch (Exception ex){
|