88
99import com .github .binarywang .demo .spring .config .WxConfig ;
1010import com .github .binarywang .demo .spring .handler .AbstractHandler ;
11+ import com .github .binarywang .demo .spring .handler .KfSessionHandler ;
12+ import com .github .binarywang .demo .spring .handler .LogHandler ;
1113import com .github .binarywang .demo .spring .handler .MenuHandler ;
1214import com .github .binarywang .demo .spring .handler .MsgHandler ;
1315import com .github .binarywang .demo .spring .handler .NullHandler ;
14- import com .github .binarywang .demo .spring .handler .LogHandler ;
1516import com .github .binarywang .demo .spring .handler .SubscribeHandler ;
1617import com .github .binarywang .demo .spring .handler .UnsubscribeHandler ;
1718
@@ -37,6 +38,9 @@ public abstract class BaseWxService extends WxMpServiceImpl {
3738 @ Autowired
3839 protected NullHandler nullHandler ;
3940
41+ @ Autowired
42+ protected KfSessionHandler kfSessionHandler ;
43+
4044 private WxMpMessageRouter router ;
4145
4246 protected abstract WxConfig getServerConfig ();
@@ -50,7 +54,7 @@ public abstract class BaseWxService extends WxMpServiceImpl {
5054 protected abstract AbstractHandler getLocationHandler ();
5155
5256 protected abstract MsgHandler getMsgHandler ();
53-
57+
5458 protected abstract AbstractHandler getScanHandler ();
5559
5660 @ PostConstruct
@@ -68,9 +72,19 @@ private void refreshRouter() {
6872
6973 final WxMpMessageRouter newRouter = new WxMpMessageRouter (this );
7074
71- //记录所有事件的日志
75+ // 记录所有事件的日志
7276 newRouter .rule ().handler (this .logHandler ).next ();
7377
78+ // 接收客服会话管理事件
79+ newRouter .rule ().async (false ).msgType (WxConsts .XML_MSG_EVENT )
80+ .event (WxConsts .EVT_KF_CREATE_SESSION ).handler (this .kfSessionHandler ).end ();
81+
82+ newRouter .rule ().async (false ).msgType (WxConsts .XML_MSG_EVENT )
83+ .event (WxConsts .EVT_KF_CLOSE_SESSION ).handler (this .kfSessionHandler ).end ();
84+
85+ newRouter .rule ().async (false ).msgType (WxConsts .XML_MSG_EVENT )
86+ .event (WxConsts .EVT_KF_SWITCH_SESSION ).handler (this .kfSessionHandler ).end ();
87+
7488 // 自定义菜单事件
7589 newRouter .rule ().async (false ).msgType (WxConsts .XML_MSG_EVENT )
7690 .event (WxConsts .BUTTON_CLICK ).handler (this .getMenuHandler ()).end ();
@@ -107,6 +121,7 @@ private void refreshRouter() {
107121 this .router = newRouter ;
108122 }
109123
124+
110125 public WxMpXmlOutMessage route (WxMpXmlMessage message ) {
111126 try {
112127 final WxMpXmlOutMessage responseMessage = this .router .route (message );
0 commit comments