Search in sources :

Example 1 with ImageBuilder

use of com.github.binarywang.demo.wx.mp.builder.ImageBuilder in project weixin-java-mp-multi-demo by binarywang.

the class MenuHandler method handle.

@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) {
    BaseWxService weixinService = (BaseWxService) wxMpService;
    String key = wxMessage.getEventKey();
    WxMenuKey menuKey = null;
    try {
        menuKey = JSON.parseObject(key, WxMenuKey.class);
    } catch (Exception e) {
        return WxMpXmlOutMessage.TEXT().content(key).fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).build();
    }
    AbstractBuilder builder = null;
    switch(menuKey.getType()) {
        case XmlMsgType.TEXT:
            builder = new TextBuilder();
            break;
        case XmlMsgType.IMAGE:
            builder = new ImageBuilder();
            break;
        case XmlMsgType.VOICE:
            break;
        case XmlMsgType.VIDEO:
            break;
        case XmlMsgType.NEWS:
            break;
        default:
            break;
    }
    if (builder != null) {
        try {
            return builder.build(menuKey.getContent(), wxMessage, weixinService);
        } catch (Exception e) {
            this.logger.error(e.getMessage(), e);
        }
    }
    return null;
}
Also used : WxMenuKey(com.github.binarywang.demo.wx.mp.dto.WxMenuKey) TextBuilder(com.github.binarywang.demo.wx.mp.builder.TextBuilder) AbstractBuilder(com.github.binarywang.demo.wx.mp.builder.AbstractBuilder) ImageBuilder(com.github.binarywang.demo.wx.mp.builder.ImageBuilder) BaseWxService(com.github.binarywang.demo.wx.mp.service.BaseWxService)

Aggregations

AbstractBuilder (com.github.binarywang.demo.wx.mp.builder.AbstractBuilder)1 ImageBuilder (com.github.binarywang.demo.wx.mp.builder.ImageBuilder)1 TextBuilder (com.github.binarywang.demo.wx.mp.builder.TextBuilder)1 WxMenuKey (com.github.binarywang.demo.wx.mp.dto.WxMenuKey)1 BaseWxService (com.github.binarywang.demo.wx.mp.service.BaseWxService)1