Search in sources :

Example 1 with AbstractBuilder

use of com.github.binarywang.demo.spring.builder.AbstractBuilder 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.spring.dto.WxMenuKey) TextBuilder(com.github.binarywang.demo.spring.builder.TextBuilder) AbstractBuilder(com.github.binarywang.demo.spring.builder.AbstractBuilder) ImageBuilder(com.github.binarywang.demo.spring.builder.ImageBuilder) BaseWxService(com.github.binarywang.demo.spring.service.BaseWxService)

Aggregations

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