|
|
@@ -0,0 +1,108 @@
|
|
|
+package com.dataeasy.server;
|
|
|
+
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import me.chanjar.weixin.mp.api.WxMpMessageRouter;
|
|
|
+import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
+import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
|
|
+import me.chanjar.weixin.mp.config.WxMpConfigStorage;
|
|
|
+import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+
|
|
|
+import static me.chanjar.weixin.mp.constant.WxMpEventConstants.CustomerService.KF_CLOSE_SESSION;
|
|
|
+import static me.chanjar.weixin.mp.constant.WxMpEventConstants.CustomerService.KF_CREATE_SESSION;
|
|
|
+import static me.chanjar.weixin.mp.constant.WxMpEventConstants.CustomerService.KF_SWITCH_SESSION; /**
|
|
|
+ * @author myou
|
|
|
+ * @version 1.0.0
|
|
|
+ * @date 2025/3/1 21:36
|
|
|
+ * @description TODO
|
|
|
+ */
|
|
|
+@AllArgsConstructor
|
|
|
+@Configuration
|
|
|
+public class WxMpConfiguration {
|
|
|
+// @Autowired
|
|
|
+// private ImgHandler imgHandler;
|
|
|
+// @Autowired
|
|
|
+// private TextMsgHandler textMsgHandler;
|
|
|
+// @Autowired
|
|
|
+// private KfSessionHandler kfSessionHandler;
|
|
|
+// @Autowired
|
|
|
+// private MenuHandler menuHandler;
|
|
|
+// @Autowired
|
|
|
+// private ScanHandler scanHandler;
|
|
|
+// @Autowired
|
|
|
+// private MsgHandler msgHandler;
|
|
|
+// @Autowired
|
|
|
+// private LogHandler logHandler;
|
|
|
+// @Autowired
|
|
|
+// private WxMpProperties wxMpProperties;
|
|
|
+// @Autowired
|
|
|
+// private SubscribeHandler subscribeHandler;
|
|
|
+// @Autowired
|
|
|
+// private UnsubscribeHandler unsubscribeHandler;
|
|
|
+
|
|
|
+// @Bean
|
|
|
+// public WxMpService wxMpService() {
|
|
|
+// WxMpServiceImpl wxMpService = new WxMpServiceImpl();
|
|
|
+// wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
|
|
|
+// // 设置多个微信公众号的配置
|
|
|
+// // wxMpService.setMultiConfigStorages();
|
|
|
+// return wxMpService;
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 这个地方的配置是保存在本地,生产环境需要自己扩展,可以保存在Redis中等等
|
|
|
+ *
|
|
|
+ * @return WxMpConfigStorage
|
|
|
+ */
|
|
|
+// public WxMpConfigStorage wxMpConfigStorage() {
|
|
|
+// WxMpDefaultConfigImpl storage = new WxMpDefaultConfigImpl();
|
|
|
+// storage.setAppId(wxMpProperties.getAppId());
|
|
|
+// storage.setSecret(wxMpProperties.getSecret());
|
|
|
+// storage.setAesKey(wxMpProperties.getAesKey());
|
|
|
+// storage.setToken(wxMpProperties.getToken());
|
|
|
+// return storage;
|
|
|
+// }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public WxMpMessageRouter messageRouter(WxMpService wxMpService) {
|
|
|
+ final WxMpMessageRouter newRouter = new WxMpMessageRouter(wxMpService);
|
|
|
+
|
|
|
+// // 记录所有事件的日志 (异步执行)
|
|
|
+// newRouter.rule().handler(this.logHandler).next();
|
|
|
+//
|
|
|
+// // 接收客服会话管理事件
|
|
|
+// newRouter.rule().async(false).msgType(EVENT).event(KF_CREATE_SESSION)
|
|
|
+// .handler(this.kfSessionHandler).end();
|
|
|
+// newRouter.rule().async(false).msgType(EVENT).event(KF_CLOSE_SESSION)
|
|
|
+// .handler(this.kfSessionHandler).end();
|
|
|
+// newRouter.rule().async(false).msgType(EVENT).event(KF_SWITCH_SESSION)
|
|
|
+// .handler(this.kfSessionHandler).end();
|
|
|
+//
|
|
|
+//
|
|
|
+// // 自定义菜单事件
|
|
|
+// newRouter.rule().async(false).msgType(EVENT).event(EventType.CLICK).handler(this.menuHandler).end();
|
|
|
+//
|
|
|
+// // 关注事件
|
|
|
+// newRouter.rule().async(false).msgType(EVENT).event(SUBSCRIBE).handler(this.subscribeHandler).end();
|
|
|
+//
|
|
|
+// // 取消关注事件
|
|
|
+// newRouter.rule().async(false).msgType(EVENT).event(UNSUBSCRIBE).handler(this.unsubscribeHandler).end();
|
|
|
+//
|
|
|
+// // 扫码事件
|
|
|
+// newRouter.rule().async(false).msgType(EVENT).event(EventType.SCAN).handler(this.scanHandler).end();
|
|
|
+//
|
|
|
+// // 文本消息处理
|
|
|
+// newRouter.rule().async(false).msgType(XmlMsgType.TEXT).handler(this.textMsgHandler).end();
|
|
|
+//
|
|
|
+// // 图片消息处理
|
|
|
+// newRouter.rule().async(false).msgType(XmlMsgType.IMAGE).handler(this.imgHandler).end();
|
|
|
+//
|
|
|
+// // 默认
|
|
|
+// newRouter.rule().async(false).handler(this.msgHandler).end();
|
|
|
+
|
|
|
+ return newRouter;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|