|
1 | 1 | package com.github.binarywang.demo.wx.mp.config;
|
2 | 2 |
|
3 | 3 | import com.github.binarywang.demo.wx.mp.handler.*;
|
4 |
| -import com.google.common.collect.Maps; |
5 | 4 | import lombok.AllArgsConstructor;
|
6 | 5 | import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
|
7 | 6 | import me.chanjar.weixin.mp.api.WxMpMessageRouter;
|
8 | 7 | import me.chanjar.weixin.mp.api.WxMpService;
|
9 | 8 | import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
10 | 9 | import me.chanjar.weixin.mp.constant.WxMpEventConstants;
|
11 |
| -import org.springframework.beans.factory.annotation.Autowired; |
12 | 10 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
13 | 11 | import org.springframework.context.annotation.Bean;
|
14 | 12 | import org.springframework.context.annotation.Configuration;
|
15 | 13 |
|
16 | 14 | import java.util.List;
|
17 |
| -import java.util.Map; |
18 | 15 | import java.util.stream.Collectors;
|
19 | 16 |
|
20 |
| -import static me.chanjar.weixin.common.api.WxConsts.*; |
| 17 | +import static me.chanjar.weixin.common.api.WxConsts.EventType; |
| 18 | +import static me.chanjar.weixin.common.api.WxConsts.EventType.SUBSCRIBE; |
| 19 | +import static me.chanjar.weixin.common.api.WxConsts.EventType.UNSUBSCRIBE; |
| 20 | +import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType.CLICK; |
| 21 | +import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType.VIEW; |
| 22 | +import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType; |
| 23 | +import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType.EVENT; |
| 24 | +import static me.chanjar.weixin.mp.constant.WxMpEventConstants.CustomerService.*; |
| 25 | +import static me.chanjar.weixin.mp.constant.WxMpEventConstants.POI_CHECK_NOTIFY; |
21 | 26 |
|
22 | 27 | /**
|
23 | 28 | * wechat mp configuration
|
@@ -69,52 +74,36 @@ public WxMpMessageRouter messageRouter(WxMpService wxMpService) {
|
69 | 74 | newRouter.rule().handler(this.logHandler).next();
|
70 | 75 |
|
71 | 76 | // 接收客服会话管理事件
|
72 |
| - newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
73 |
| - .event(WxMpEventConstants.CustomerService.KF_CREATE_SESSION) |
| 77 | + newRouter.rule().async(false).msgType(EVENT).event(KF_CREATE_SESSION) |
74 | 78 | .handler(this.kfSessionHandler).end();
|
75 |
| - newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
76 |
| - .event(WxMpEventConstants.CustomerService.KF_CLOSE_SESSION) |
77 |
| - .handler(this.kfSessionHandler) |
78 |
| - .end(); |
79 |
| - newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
80 |
| - .event(WxMpEventConstants.CustomerService.KF_SWITCH_SESSION) |
| 79 | + newRouter.rule().async(false).msgType(EVENT).event(KF_CLOSE_SESSION) |
| 80 | + .handler(this.kfSessionHandler).end(); |
| 81 | + newRouter.rule().async(false).msgType(EVENT).event(KF_SWITCH_SESSION) |
81 | 82 | .handler(this.kfSessionHandler).end();
|
82 | 83 |
|
83 | 84 | // 门店审核事件
|
84 |
| - newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
85 |
| - .event(WxMpEventConstants.POI_CHECK_NOTIFY) |
86 |
| - .handler(this.storeCheckNotifyHandler).end(); |
| 85 | + newRouter.rule().async(false).msgType(EVENT).event(POI_CHECK_NOTIFY).handler(this.storeCheckNotifyHandler).end(); |
87 | 86 |
|
88 | 87 | // 自定义菜单事件
|
89 |
| - newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
90 |
| - .event(MenuButtonType.CLICK).handler(this.menuHandler).end(); |
| 88 | + newRouter.rule().async(false).msgType(EVENT).event(CLICK).handler(this.menuHandler).end(); |
91 | 89 |
|
92 | 90 | // 点击菜单连接事件
|
93 |
| - newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
94 |
| - .event(MenuButtonType.VIEW).handler(this.nullHandler).end(); |
| 91 | + newRouter.rule().async(false).msgType(EVENT).event(VIEW).handler(this.nullHandler).end(); |
95 | 92 |
|
96 | 93 | // 关注事件
|
97 |
| - newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
98 |
| - .event(EventType.SUBSCRIBE).handler(this.subscribeHandler) |
99 |
| - .end(); |
| 94 | + newRouter.rule().async(false).msgType(EVENT).event(SUBSCRIBE).handler(this.subscribeHandler).end(); |
100 | 95 |
|
101 | 96 | // 取消关注事件
|
102 |
| - newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
103 |
| - .event(EventType.UNSUBSCRIBE) |
104 |
| - .handler(this.unsubscribeHandler).end(); |
| 97 | + newRouter.rule().async(false).msgType(EVENT).event(UNSUBSCRIBE).handler(this.unsubscribeHandler).end(); |
105 | 98 |
|
106 | 99 | // 上报地理位置事件
|
107 |
| - newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
108 |
| - .event(EventType.LOCATION).handler(this.locationHandler) |
109 |
| - .end(); |
| 100 | + newRouter.rule().async(false).msgType(EVENT).event(EventType.LOCATION).handler(this.locationHandler).end(); |
110 | 101 |
|
111 | 102 | // 接收地理位置消息
|
112 |
| - newRouter.rule().async(false).msgType(XmlMsgType.LOCATION) |
113 |
| - .handler(this.locationHandler).end(); |
| 103 | + newRouter.rule().async(false).msgType(XmlMsgType.LOCATION).handler(this.locationHandler).end(); |
114 | 104 |
|
115 | 105 | // 扫码事件
|
116 |
| - newRouter.rule().async(false).msgType(XmlMsgType.EVENT) |
117 |
| - .event(EventType.SCAN).handler(this.scanHandler).end(); |
| 106 | + newRouter.rule().async(false).msgType(EVENT).event(EventType.SCAN).handler(this.scanHandler).end(); |
118 | 107 |
|
119 | 108 | // 默认
|
120 | 109 | newRouter.rule().async(false).handler(this.msgHandler).end();
|
|
0 commit comments