mp:增加 MpServiceFactory 管理创建的 MpService~
parent
627cb39517
commit
275a1b10f6
@ -0,0 +1,46 @@
|
|||||||
|
package cn.iocoder.yudao.module.mp.framework.mp.config;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.mp.framework.mp.core.DefaultMpServiceFactory;
|
||||||
|
import cn.iocoder.yudao.module.mp.framework.mp.core.MpServiceFactory;
|
||||||
|
import cn.iocoder.yudao.module.mp.service.fansmsgres.NullHandler;
|
||||||
|
import cn.iocoder.yudao.module.mp.service.handler.*;
|
||||||
|
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
|
||||||
|
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信公众号的配置类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class MpConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
||||||
|
public RedisTemplateWxRedisOps redisTemplateWxRedisOps(StringRedisTemplate stringRedisTemplate) {
|
||||||
|
return new RedisTemplateWxRedisOps(stringRedisTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
||||||
|
public MpServiceFactory mpServiceFactory(RedisTemplateWxRedisOps redisTemplateWxRedisOps,
|
||||||
|
WxMpProperties wxMpProperties,
|
||||||
|
LogHandler logHandler,
|
||||||
|
KfSessionHandler kfSessionHandler,
|
||||||
|
StoreCheckNotifyHandler storeCheckNotifyHandler,
|
||||||
|
MenuHandler menuHandler,
|
||||||
|
NullHandler nullHandler,
|
||||||
|
SubscribeHandler subscribeHandler,
|
||||||
|
UnsubscribeHandler unsubscribeHandler,
|
||||||
|
LocationHandler locationHandler,
|
||||||
|
ScanHandler scanHandler,
|
||||||
|
DefaultMessageHandler msgHandler) {
|
||||||
|
return new DefaultMpServiceFactory(redisTemplateWxRedisOps, wxMpProperties,
|
||||||
|
logHandler, kfSessionHandler, storeCheckNotifyHandler, menuHandler,
|
||||||
|
nullHandler, subscribeHandler, unsubscribeHandler, locationHandler, scanHandler, msgHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* @date 2022/6/20
|
* 属于 mp 模块的 framework 封装
|
||||||
* @author feng-dan
|
*
|
||||||
* @version 1.0
|
* @author 芋道源码
|
||||||
*/
|
*/
|
||||||
package cn.iocoder.yudao.module.mp.framework;
|
package cn.iocoder.yudao.module.mp.framework;
|
||||||
|
|||||||
@ -1,106 +0,0 @@
|
|||||||
package cn.iocoder.yudao.module.mp.framework.weixin;
|
|
||||||
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.mp.handler.*;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import me.chanjar.weixin.common.api.WxConsts;
|
|
||||||
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
|
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
|
||||||
import me.chanjar.weixin.mp.constant.WxMpEventConstants;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fengdan
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class WxMpMessageRouterConfiguration {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private WxMpService wxMpService;
|
|
||||||
@Resource
|
|
||||||
private LogHandler logHandler;
|
|
||||||
@Resource
|
|
||||||
private KfSessionHandler kfSessionHandler;
|
|
||||||
@Resource
|
|
||||||
private StoreCheckNotifyHandler storeCheckNotifyHandler;
|
|
||||||
@Resource
|
|
||||||
private MenuHandler menuHandler;
|
|
||||||
@Resource
|
|
||||||
private NullHandler nullHandler;
|
|
||||||
@Resource
|
|
||||||
private SubscribeHandler subscribeHandler;
|
|
||||||
@Resource
|
|
||||||
private UnsubscribeHandler unsubscribeHandler;
|
|
||||||
@Resource
|
|
||||||
private LocationHandler locationHandler;
|
|
||||||
@Resource
|
|
||||||
private ScanHandler scanHandler;
|
|
||||||
@Resource
|
|
||||||
private MsgHandler msgHandler;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public WxMpMessageRouter messageRouter() {
|
|
||||||
final WxMpMessageRouter newRouter = new WxMpMessageRouter(wxMpService);
|
|
||||||
// 记录所有事件的日志 (异步执行)
|
|
||||||
newRouter.rule().handler(logHandler).next();
|
|
||||||
|
|
||||||
// 接收客服会话管理事件
|
|
||||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
|
||||||
.event(WxMpEventConstants.CustomerService.KF_CREATE_SESSION)
|
|
||||||
.handler(kfSessionHandler).end();
|
|
||||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
|
||||||
.event(WxMpEventConstants.CustomerService.KF_CLOSE_SESSION)
|
|
||||||
.handler(kfSessionHandler)
|
|
||||||
.end();
|
|
||||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
|
||||||
.event(WxMpEventConstants.CustomerService.KF_SWITCH_SESSION)
|
|
||||||
.handler(kfSessionHandler).end();
|
|
||||||
|
|
||||||
// 门店审核事件
|
|
||||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
|
||||||
.event(WxMpEventConstants.POI_CHECK_NOTIFY)
|
|
||||||
.handler(storeCheckNotifyHandler).end();
|
|
||||||
|
|
||||||
// 自定义菜单事件
|
|
||||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
|
||||||
.event(WxConsts.MenuButtonType.CLICK).handler(menuHandler).end();
|
|
||||||
|
|
||||||
// 点击菜单连接事件
|
|
||||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
|
||||||
.event(WxConsts.MenuButtonType.VIEW).handler(nullHandler).end();
|
|
||||||
|
|
||||||
// 关注事件
|
|
||||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
|
||||||
.event(WxConsts.EventType.SUBSCRIBE).handler(subscribeHandler)
|
|
||||||
.end();
|
|
||||||
|
|
||||||
// 取消关注事件
|
|
||||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
|
||||||
.event(WxConsts.EventType.UNSUBSCRIBE)
|
|
||||||
.handler(unsubscribeHandler).end();
|
|
||||||
|
|
||||||
// 上报地理位置事件
|
|
||||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
|
||||||
.event(WxConsts.EventType.LOCATION).handler(locationHandler)
|
|
||||||
.end();
|
|
||||||
|
|
||||||
// 接收地理位置消息
|
|
||||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.LOCATION)
|
|
||||||
.handler(locationHandler).end();
|
|
||||||
|
|
||||||
// 扫码事件
|
|
||||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
|
||||||
.event(WxConsts.EventType.SCAN).handler(scanHandler).end();
|
|
||||||
|
|
||||||
// 默认
|
|
||||||
newRouter.rule().async(false).handler(msgHandler).end();
|
|
||||||
|
|
||||||
return newRouter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package cn.iocoder.yudao.module.mp.mq.costomer;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener;
|
||||||
|
import cn.iocoder.yudao.module.mp.mq.message.MpConfigRefreshMessage;
|
||||||
|
import cn.iocoder.yudao.module.mp.service.account.MpAccountService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 针对 {@link MpConfigRefreshMessage} 的消费者
|
||||||
|
*
|
||||||
|
* @author lyz
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class MpConfigRefreshConsumer extends AbstractChannelMessageListener<MpConfigRefreshMessage> {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MpAccountService wxAccountService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMessage(MpConfigRefreshMessage message) {
|
||||||
|
log.info("[onMessage][收到 MpConfig 刷新消息]");
|
||||||
|
wxAccountService.initLocalCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,29 +0,0 @@
|
|||||||
package cn.iocoder.yudao.module.mp.mq.costomer;
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener;
|
|
||||||
import cn.iocoder.yudao.module.mp.mq.message.WxConfigDataRefreshMessage;
|
|
||||||
import cn.iocoder.yudao.module.mp.service.account.WxAccountService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 针对 {@link WxConfigDataRefreshMessage} 的消费者
|
|
||||||
*
|
|
||||||
* @author lyz
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class WxConfigDataRefreshConsumer extends AbstractChannelMessageListener<WxConfigDataRefreshMessage> {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private WxAccountService wxAccountService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessage(WxConfigDataRefreshMessage message) {
|
|
||||||
log.info("[onMessage][收到 WxConfigData 刷新消息]");
|
|
||||||
wxAccountService.initLoadWxMpConfigStorages();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue