Skip to content

Commit 5edc221

Browse files
committed
简化代码
1 parent dadcc25 commit 5edc221

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

src/main/java/com/github/binarywang/demo/wx/mp/config/WxMpConfiguration.java

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
package com.github.binarywang.demo.wx.mp.config;
22

33
import com.github.binarywang.demo.wx.mp.handler.*;
4-
import com.google.common.collect.Maps;
54
import lombok.AllArgsConstructor;
65
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
76
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
87
import me.chanjar.weixin.mp.api.WxMpService;
98
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
109
import me.chanjar.weixin.mp.constant.WxMpEventConstants;
11-
import org.springframework.beans.factory.annotation.Autowired;
1210
import org.springframework.boot.context.properties.EnableConfigurationProperties;
1311
import org.springframework.context.annotation.Bean;
1412
import org.springframework.context.annotation.Configuration;
1513

1614
import java.util.List;
17-
import java.util.Map;
1815
import java.util.stream.Collectors;
1916

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;
2126

2227
/**
2328
* wechat mp configuration
@@ -69,52 +74,36 @@ public WxMpMessageRouter messageRouter(WxMpService wxMpService) {
6974
newRouter.rule().handler(this.logHandler).next();
7075

7176
// 接收客服会话管理事件
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)
7478
.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)
8182
.handler(this.kfSessionHandler).end();
8283

8384
// 门店审核事件
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();
8786

8887
// 自定义菜单事件
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();
9189

9290
// 点击菜单连接事件
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();
9592

9693
// 关注事件
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();
10095

10196
// 取消关注事件
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();
10598

10699
// 上报地理位置事件
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();
110101

111102
// 接收地理位置消息
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();
114104

115105
// 扫码事件
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();
118107

119108
// 默认
120109
newRouter.rule().async(false).handler(this.msgHandler).end();

0 commit comments

Comments
 (0)