Search in sources :

Example 1 with WxSessionManager

use of me.chanjar.weixin.common.session.WxSessionManager in project weixin-java-tools by chanjarster.

the class WxCpMessageRouterTest method testConcurrency.

public void testConcurrency() throws InterruptedException {
    final WxCpMessageRouter router = new WxCpMessageRouter(null);
    router.rule().handler(new WxCpMessageHandler() {

        @Override
        public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService wxCpService, WxSessionManager sessionManager) {
            return null;
        }
    }).end();
    final WxCpXmlMessage m = new WxCpXmlMessage();
    Runnable r = new Runnable() {

        @Override
        public void run() {
            router.route(m);
            try {
                Thread.sleep(1000l);
            } catch (InterruptedException e) {
            }
        }
    };
    for (int i = 0; i < 10; i++) {
        new Thread(r).start();
    }
    Thread.sleep(1000l * 2);
}
Also used : WxCpXmlMessage(me.chanjar.weixin.cp.bean.WxCpXmlMessage) WxSessionManager(me.chanjar.weixin.common.session.WxSessionManager) Map(java.util.Map)

Example 2 with WxSessionManager

use of me.chanjar.weixin.common.session.WxSessionManager in project weixin-java-tools by chanjarster.

the class WxCpDemoServer method initWeixin.

private static void initWeixin() {
    InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml");
    WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage.fromXml(is1);
    wxCpConfigStorage = config;
    wxCpService = new WxCpServiceImpl();
    wxCpService.setWxCpConfigStorage(config);
    WxCpMessageHandler handler = new WxCpMessageHandler() {

        @Override
        public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService wxCpService, WxSessionManager sessionManager) {
            WxCpXmlOutTextMessage m = WxCpXmlOutMessage.TEXT().content("测试加密消息").fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName()).build();
            return m;
        }
    };
    WxCpMessageHandler oauth2handler = new WxCpMessageHandler() {

        @Override
        public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService wxCpService, WxSessionManager sessionManager) {
            String href = "<a href=\"" + wxCpService.oauth2buildAuthorizationUrl(wxCpConfigStorage.getOauth2redirectUri(), null) + "\">测试oauth2</a>";
            return WxCpXmlOutMessage.TEXT().content(href).fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName()).build();
        }
    };
    wxCpMessageRouter = new WxCpMessageRouter(wxCpService);
    wxCpMessageRouter.rule().async(false).content(// 拦截内容为“哈哈”的消息
    "哈哈").handler(handler).end().rule().async(false).content("oauth").handler(oauth2handler).end();
}
Also used : WxCpXmlMessage(me.chanjar.weixin.cp.bean.WxCpXmlMessage) InputStream(java.io.InputStream) WxSessionManager(me.chanjar.weixin.common.session.WxSessionManager) WxCpXmlOutTextMessage(me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage) Map(java.util.Map)

Example 3 with WxSessionManager

use of me.chanjar.weixin.common.session.WxSessionManager in project weixin-java-tools by chanjarster.

the class WxMpMessageRouterTest method testConcurrency.

public void testConcurrency() throws InterruptedException {
    final WxMpMessageRouter router = new WxMpMessageRouter(null);
    router.rule().handler(new WxMpMessageHandler() {

        @Override
        public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) {
            return null;
        }
    }).end();
    final WxMpXmlMessage m = new WxMpXmlMessage();
    Runnable r = new Runnable() {

        @Override
        public void run() {
            router.route(m);
            try {
                Thread.sleep(1000l);
            } catch (InterruptedException e) {
            }
        }
    };
    for (int i = 0; i < 10; i++) {
        new Thread(r).start();
    }
    Thread.sleep(1000l * 2);
}
Also used : WxSessionManager(me.chanjar.weixin.common.session.WxSessionManager) WxMpXmlMessage(me.chanjar.weixin.mp.bean.WxMpXmlMessage) Map(java.util.Map)

Aggregations

Map (java.util.Map)3 WxSessionManager (me.chanjar.weixin.common.session.WxSessionManager)3 WxCpXmlMessage (me.chanjar.weixin.cp.bean.WxCpXmlMessage)2 InputStream (java.io.InputStream)1 WxCpXmlOutTextMessage (me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage)1 WxMpXmlMessage (me.chanjar.weixin.mp.bean.WxMpXmlMessage)1