use of com.github.binarywang.demo.wx.mp.dto.WxMenuKey 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;
}
Aggregations