Search in sources :

Example 1 with WxCpXmlOutTextMessage

use of me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage 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 2 with WxCpXmlOutTextMessage

use of me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage in project weixin-java-tools by chanjarster.

the class TextBuilder method build.

public WxCpXmlOutTextMessage build() {
    WxCpXmlOutTextMessage m = new WxCpXmlOutTextMessage();
    setCommon(m);
    m.setContent(this.content);
    return m;
}
Also used : WxCpXmlOutTextMessage(me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage)

Aggregations

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