java微信扫码关注_微信扫码关注公众号

import com.cyb.weixin.mp.handler.*;importcom.google.common.collect.Maps;importme.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;importme.chanjar.weixin.mp.api.WxMpMessageRouter;importme.chanjar.weixin.mp.api.WxMpService;importme.chanjar.weixin.mp.api.impl.WxMpServiceImpl;importme.chanjar.weixin.mp.constant.WxMpEventConstants;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.boot.context.properties.EnableConfigurationProperties;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;importjava.util.List;importjava.util.Map;importjava.util.stream.Collectors;import static me.chanjar.weixin.common.api.WxConsts.*;/*** wechat mp configuration

*

*@authorBinary Wang(https://github.com/binarywang)*/@Configuration

@EnableConfigurationProperties(WxMpProperties.class)public classWxMpConfiguration {privateLogHandler logHandler;privateNullHandler nullHandler;privateKfSessionHandler kfSessionHandler;privateStoreCheckNotifyHandler storeCheckNotifyHandler;privateLocationHandler locationHandler;privateMenuHandler menuHandler;privateMsgHandler msgHandler;privateUnsubscribeHandler unsubscribeHandler;privateSubscribeHandler subscribeHandler;privateScanHandler scanHandler;privateWxMpProperties properties;private static Map routers =Maps.newHashMap();private static Map mpServices =Maps.newHashMap();

@AutowiredpublicWxMpConfiguration(LogHandler logHandler, NullHandler nullHandler, KfSessionHandler kfSessionHandler,

StoreCheckNotifyHandler storeCheckNotifyHandler, LocationHandler locationHandler,

MenuHandler menuHandler, MsgHandler msgHandler, UnsubscribeHandler unsubscribeHandler,

SubscribeHandler subscribeHandler, ScanHandler scanHandler, WxMpProperties properties) {this.logHandler =logHandler;this.nullHandler =nullHandler;this.kfSessionHandler =kfSessionHandler;this.storeCheckNotifyHandler =storeCheckNotifyHandler;this.locationHandler =locationHandler;this.menuHandler =menuHandler;this.msgHandler =msgHandler;this.unsubscribeHandler =unsubscribeHandler;this.subscribeHandler =subscribeHandler;this.scanHandler =scanHandler;this.properties =properties;

}public static MapgetRouters() {returnrouters;

}public static MapgetMpServices() {returnmpServices;

}

@BeanpublicObject services() {//代码里getConfigs()处报错的同学,请注意仔细阅读项目说明,你的IDE需要引入lombok插件!!!!

final List configs = this.properties.getConfigs();if (configs == null) {throw new RuntimeException("大哥,拜托先看下项目首页的说明(readme文件),添加下相关配置,注意别配错了!");

}

mpServices= configs.stream().map(a ->{

WxMpInMemoryConfigStorage configStorage= newWxMpInMemoryConfigStorage();

configStorage.setAppId(a.getAppId());

configStorage.setSecret(a.getSecret());

configStorage.setToken(a.getToken());

configStorage.setAesKey(a.getAesKey());

WxMpService service= newWxMpServiceImpl();

service.setWxMpConfigStorage(configStorage);

routers.put(a.getAppId(),this.newRouter(service));returnservice;

}).collect(Collectors.toMap(s-> s.getWxMpConfigStorage().getAppId(), a -> a, (o, n) ->o));returnBoolean.TRUE;

}privateWxMpMessageRouter newRouter(WxMpService wxMpService) {final WxMpMessageRouter newRouter = newWxMpMessageRouter(wxMpService);//记录所有事件的日志 (异步执行)

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.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.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.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.LOCATION)

.handler(this.locationHandler).end();//扫码事件

newRouter.rule().async(false).msgType(XmlMsgType.EVENT)

.event(EventType.SCAN).handler(this.scanHandler).end();//默认

newRouter.rule().async(false).handler(this.msgHandler).end();returnnewRouter;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值