|
11 | 11 | import com.github.binarywang.demo.spring.handler.MenuHandler; |
12 | 12 | import com.github.binarywang.demo.spring.handler.MsgHandler; |
13 | 13 | import com.github.binarywang.demo.spring.handler.NullHandler; |
| 14 | +import com.github.binarywang.demo.spring.handler.LogHandler; |
14 | 15 | import com.github.binarywang.demo.spring.handler.SubscribeHandler; |
15 | 16 | import com.github.binarywang.demo.spring.handler.UnsubscribeHandler; |
16 | | -import com.google.gson.JsonArray; |
17 | | -import com.google.gson.JsonParser; |
18 | 17 |
|
19 | 18 | import me.chanjar.weixin.common.api.WxConsts; |
20 | 19 | import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage; |
21 | 20 | import me.chanjar.weixin.mp.api.WxMpMessageRouter; |
22 | 21 | import me.chanjar.weixin.mp.api.WxMpServiceImpl; |
23 | 22 | import me.chanjar.weixin.mp.bean.WxMpXmlMessage; |
24 | 23 | import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; |
| 24 | +import me.chanjar.weixin.mp.bean.customerservice.result.WxMpKfOnlineList; |
25 | 25 |
|
26 | 26 | /** |
27 | 27 | * |
|
31 | 31 | public abstract class BaseWxService extends WxMpServiceImpl { |
32 | 32 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
33 | 33 |
|
| 34 | + @Autowired |
| 35 | + protected LogHandler logHandler; |
| 36 | + |
34 | 37 | @Autowired |
35 | 38 | protected NullHandler nullHandler; |
36 | 39 |
|
@@ -65,9 +68,12 @@ private void refreshRouter() { |
65 | 68 |
|
66 | 69 | final WxMpMessageRouter newRouter = new WxMpMessageRouter(this); |
67 | 70 |
|
| 71 | + //记录所有事件的日志 |
| 72 | + newRouter.rule().handler(this.logHandler).next(); |
| 73 | + |
68 | 74 | // 自定义菜单事件 |
69 | | - newRouter.rule().async(false).event(WxConsts.BUTTON_CLICK) |
70 | | - .handler(this.getMenuHandler()).end(); |
| 75 | + newRouter.rule().async(false).msgType(WxConsts.XML_MSG_EVENT) |
| 76 | + .event(WxConsts.BUTTON_CLICK).handler(this.getMenuHandler()).end(); |
71 | 77 |
|
72 | 78 | // 点击菜单连接事件 |
73 | 79 | newRouter.rule().async(false).msgType(WxConsts.XML_MSG_EVENT) |
@@ -112,13 +118,10 @@ public WxMpXmlOutMessage route(WxMpXmlMessage message) { |
112 | 118 | return null; |
113 | 119 | } |
114 | 120 |
|
115 | | - public boolean isCustomerServiceOnline() { |
| 121 | + public boolean hasKefuOnline() { |
116 | 122 | try { |
117 | | - String url = "https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist"; |
118 | | - String executeResult = this.get(url, null); |
119 | | - JsonArray jsonArray = new JsonParser().parse(executeResult) |
120 | | - .getAsJsonObject().get("kf_online_list").getAsJsonArray(); |
121 | | - return jsonArray.size() > 0; |
| 123 | + WxMpKfOnlineList kfOnlineList = this.getKefuService().kfOnlineList(); |
| 124 | + return kfOnlineList != null && kfOnlineList.getKfOnlineList().size() > 0; |
122 | 125 | } catch (Exception e) { |
123 | 126 | this.logger.error("获取客服在线状态异常: " + e.getMessage(), e); |
124 | 127 | } |
|
0 commit comments