WxMpConfiguration.java 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.izouma.zhirongip.config;
  2. import com.izouma.zhirongip.mpHandler.LogHandler;
  3. import lombok.AllArgsConstructor;
  4. import me.chanjar.weixin.mp.api.WxMpMessageRouter;
  5. import me.chanjar.weixin.mp.api.WxMpService;
  6. import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
  7. import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
  8. import org.springframework.boot.context.properties.EnableConfigurationProperties;
  9. import org.springframework.context.annotation.Bean;
  10. import org.springframework.context.annotation.Configuration;
  11. @AllArgsConstructor
  12. @Configuration
  13. @EnableConfigurationProperties(WxMpProperties.class)
  14. public class WxMpConfiguration {
  15. private final WxMpProperties properties;
  16. private final LogHandler logHandler;
  17. @Bean
  18. public WxMpService wxMpService() {
  19. WxMpDefaultConfigImpl mpConfig = new WxMpDefaultConfigImpl();
  20. mpConfig.setAppId(properties.getAppId());
  21. mpConfig.setSecret(properties.getAppSecret());
  22. mpConfig.setAccessToken(properties.getToken());
  23. mpConfig.setAesKey(properties.getAesKey());
  24. WxMpService service = new WxMpServiceImpl();
  25. service.setWxMpConfigStorage(mpConfig);
  26. return service;
  27. }
  28. @Bean
  29. public WxMpMessageRouter messageRouter(WxMpService wxMpService) {
  30. final WxMpMessageRouter newRouter = new WxMpMessageRouter(wxMpService);
  31. // 记录所有事件的日志 (异步执行)
  32. newRouter.rule().handler(this.logHandler).next();
  33. /*// 接收客服会话管理事件
  34. newRouter.rule().async(false).msgType(EVENT).event(KF_CREATE_SESSION).handler(this.kfSessionHandler).end();
  35. newRouter.rule().async(false).msgType(EVENT).event(KF_CLOSE_SESSION).handler(this.kfSessionHandler).end();
  36. newRouter.rule().async(false).msgType(EVENT).event(KF_SWITCH_SESSION).handler(this.kfSessionHandler).end();
  37. // 门店审核事件
  38. newRouter.rule().async(false).msgType(EVENT).event(POI_CHECK_NOTIFY).handler(this.storeCheckNotifyHandler).end();
  39. // 自定义菜单事件
  40. newRouter.rule().async(false).msgType(EVENT).event(WxConsts.EventType.CLICK).handler(this.menuHandler).end();
  41. // 点击菜单连接事件
  42. newRouter.rule().async(false).msgType(EVENT).event(WxConsts.EventType.VIEW).handler(this.nullHandler).end();
  43. // 关注事件
  44. newRouter.rule().async(false).msgType(EVENT).event(SUBSCRIBE).handler(this.subscribeHandler).end();
  45. // 取消关注事件
  46. newRouter.rule().async(false).msgType(EVENT).event(UNSUBSCRIBE).handler(this.unsubscribeHandler).end();
  47. // 上报地理位置事件
  48. newRouter.rule().async(false).msgType(EVENT).event(WxConsts.EventType.LOCATION).handler(this.locationHandler).end();
  49. // 接收地理位置消息
  50. newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.LOCATION).handler(this.locationHandler).end();
  51. // 扫码事件
  52. newRouter.rule().async(false).msgType(EVENT).event(WxConsts.EventType.SCAN).handler(this.scanHandler).end();
  53. // 默认
  54. newRouter.rule().async(false).handler(this.msgHandler).end();*/
  55. return newRouter;
  56. }
  57. }