|
|
|
@@ -1,9 +1,8 @@ |
|
|
|
package com.iformall.mp.manager; |
|
|
|
|
|
|
|
import com.iformall.domain.po.WxAppinfo; |
|
|
|
import com.iformall.mp.handler.*; |
|
|
|
import com.iformall.mp.utils.MpUtil; |
|
|
|
import com.iformall.service.WxAppinfoService; |
|
|
|
import com.iformall.service.wechat.WxOpenService; |
|
|
|
import me.chanjar.weixin.mp.api.WxMpMessageRouter; |
|
|
|
import me.chanjar.weixin.mp.api.WxMpService; |
|
|
|
import me.chanjar.weixin.mp.constant.WxMpEventConstants; |
|
|
|
@@ -15,11 +14,15 @@ import static me.chanjar.weixin.common.api.WxConsts.*; |
|
|
|
/** |
|
|
|
* wechat mp configuration |
|
|
|
* |
|
|
|
* @author Binary Wang(https://github.com/binarywang) |
|
|
|
* @author Stormeye |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
public class WxMpManager { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected WxOpenService openService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxAppinfoService appinfoService; |
|
|
|
@Autowired |
|
|
|
@@ -42,20 +45,7 @@ public class WxMpManager { |
|
|
|
private SubscribeHandler subscribeHandler; |
|
|
|
|
|
|
|
public WxMpService getMpService(String appId) { |
|
|
|
WxAppinfo appinfo = appinfoService.getByAppId(appId); |
|
|
|
if(appinfo == null) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
WxMpService mpService = MpUtil.getMpService(appinfo); |
|
|
|
return mpService; |
|
|
|
} |
|
|
|
|
|
|
|
public WxMpMessageRouter getRouter(WxAppinfo appinfo) { |
|
|
|
WxMpService mpService = MpUtil.getMpService(appinfo); |
|
|
|
if(mpService != null) { |
|
|
|
return newRouter(mpService); |
|
|
|
} |
|
|
|
return null; |
|
|
|
return openService.getWxOpenComponentService().getWxMpServiceByAppid(appId); |
|
|
|
} |
|
|
|
|
|
|
|
public WxMpMessageRouter getRouter(WxMpService mpService) { |
|
|
|
@@ -69,52 +59,65 @@ public class WxMpManager { |
|
|
|
newRouter.rule().handler(this.logHandler).next(); |
|
|
|
|
|
|
|
// 接收客服会话管理事件 |
|
|
|
newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
|
|
|
.event(WxMpEventConstants.CustomerService.KF_CREATE_SESSION) |
|
|
|
.handler(this.kfSessionHandler).end(); |
|
|
|
newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
|
|
|
.event(WxMpEventConstants.CustomerService.KF_CLOSE_SESSION) |
|
|
|
.handler(this.kfSessionHandler) |
|
|
|
.end(); |
|
|
|
newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
|
|
|
.event(WxMpEventConstants.CustomerService.KF_SWITCH_SESSION) |
|
|
|
.handler(this.kfSessionHandler).end(); |
|
|
|
newRouter.rule().async(false) |
|
|
|
.msgType(XmlMsgType.EVENT) |
|
|
|
.event(WxMpEventConstants.CustomerService.KF_CREATE_SESSION) |
|
|
|
.handler(this.kfSessionHandler).end(); |
|
|
|
newRouter.rule().async(false) |
|
|
|
.msgType(XmlMsgType.EVENT) |
|
|
|
.event(WxMpEventConstants.CustomerService.KF_CLOSE_SESSION) |
|
|
|
.handler(this.kfSessionHandler).end(); |
|
|
|
newRouter.rule().async(false) |
|
|
|
.msgType(XmlMsgType.EVENT) |
|
|
|
.event(WxMpEventConstants.CustomerService.KF_SWITCH_SESSION) |
|
|
|
.handler(this.kfSessionHandler).end(); |
|
|
|
|
|
|
|
// 门店审核事件 |
|
|
|
newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
|
|
|
.event(WxMpEventConstants.POI_CHECK_NOTIFY) |
|
|
|
.handler(this.storeCheckNotifyHandler).end(); |
|
|
|
newRouter.rule().async(false) |
|
|
|
.msgType(XmlMsgType.EVENT) |
|
|
|
.event(WxMpEventConstants.POI_CHECK_NOTIFY) |
|
|
|
.handler(this.storeCheckNotifyHandler).end(); |
|
|
|
|
|
|
|
// 自定义菜单事件 |
|
|
|
newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
|
|
|
.event(MenuButtonType.CLICK).handler(this.menuHandler).end(); |
|
|
|
newRouter.rule().async(false) |
|
|
|
.msgType(XmlMsgType.EVENT) |
|
|
|
.event(MenuButtonType.CLICK) |
|
|
|
.handler(this.menuHandler).end(); |
|
|
|
|
|
|
|
// 点击菜单连接事件 |
|
|
|
newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
|
|
|
.event(MenuButtonType.VIEW).handler(this.nullHandler).end(); |
|
|
|
newRouter.rule().async(false) |
|
|
|
.msgType(XmlMsgType.EVENT) |
|
|
|
.event(MenuButtonType.VIEW) |
|
|
|
.handler(this.nullHandler).end(); |
|
|
|
|
|
|
|
// 关注事件 |
|
|
|
newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
|
|
|
.event(EventType.SUBSCRIBE).handler(this.subscribeHandler) |
|
|
|
.end(); |
|
|
|
newRouter.rule().async(false) |
|
|
|
.msgType(XmlMsgType.EVENT) |
|
|
|
.event(EventType.SUBSCRIBE) |
|
|
|
.handler(this.subscribeHandler).end(); |
|
|
|
|
|
|
|
// 取消关注事件 |
|
|
|
newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
|
|
|
.event(EventType.UNSUBSCRIBE) |
|
|
|
.handler(this.unsubscribeHandler).end(); |
|
|
|
newRouter.rule().async(false) |
|
|
|
.msgType(XmlMsgType.EVENT) |
|
|
|
.event(EventType.UNSUBSCRIBE) |
|
|
|
.handler(this.unsubscribeHandler).end(); |
|
|
|
|
|
|
|
// 上报地理位置事件 |
|
|
|
newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
|
|
|
.event(EventType.LOCATION).handler(this.locationHandler) |
|
|
|
.end(); |
|
|
|
newRouter.rule().async(false) |
|
|
|
.msgType(XmlMsgType.EVENT) |
|
|
|
.event(EventType.LOCATION) |
|
|
|
.handler(this.locationHandler).end(); |
|
|
|
|
|
|
|
// 接收地理位置消息 |
|
|
|
newRouter.rule().async(false).msgType(XmlMsgType.LOCATION) |
|
|
|
.handler(this.locationHandler).end(); |
|
|
|
newRouter.rule().async(false) |
|
|
|
.msgType(XmlMsgType.LOCATION) |
|
|
|
.handler(this.locationHandler).end(); |
|
|
|
|
|
|
|
// 扫码事件 |
|
|
|
newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
|
|
|
.event(EventType.SCAN).handler(this.nullHandler).end(); |
|
|
|
newRouter.rule().async(false) |
|
|
|
.msgType(XmlMsgType.EVENT) |
|
|
|
.event(EventType.SCAN) |
|
|
|
.handler(this.nullHandler).end(); |
|
|
|
|
|
|
|
// 默认 |
|
|
|
newRouter.rule().async(false).handler(this.msgHandler).end(); |
|
|
|
|