package com.gxwebsoft.open.config;

import com.gxwebsoft.open.mp.SubscribeHandler;
import com.gxwebsoft.open.mp.TextHandler;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MpMessageRouterConfig {
    @Autowired
    private SubscribeHandler subscriptHandler;
    @Autowired
    private TextHandler textHandler;


    @Bean
    public WxMpMessageRouter messageRouter(WxMpService wxMpService) {
        final WxMpMessageRouter router = new WxMpMessageRouter(wxMpService);
        System.out.println("初始化消息路由器");
        router.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT).event(WxConsts.EventType.SUBSCRIBE).handler(subscriptHandler).end();
        router.rule().async(false).msgType(WxConsts.XmlMsgType.TEXT).handler(textHandler).end();
        return router;
    }
}