if (eventType.equalsIgnoreCase(MessageUtil.EVENT_TYPE_CLICK)) { // 事件KEY值,与创建自定义菜单时指定的KEY值对应 String eventKey = requestMap.get("EventKey"); if (eventKey.equals("CONTACT_US")) { NewsMessage newsMessage = buildmessage(open_id, toUserName, 1); // 将图文消息对象转换成xml字符串 respMessage = MessageUtil.newsMessageToXml(newsMessage); } } private NewsMessage buildmessage(String open_id, String toUserName, Integer type) { // 创建图文消息 NewsMessage newsMessage = new NewsMessage(); newsMessage.setToUserName(open_id); newsMessage.setFromUserName(toUserName); newsMessage.setCreateTime(new Date().getTime()); newsMessage.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_NEWS); newsMessage.setFuncFlag(0); List<WelMsgEntity> welMsgEntities = welMsgService.findAll(type); List<WelMsgEntity> needlist = new ArrayList<WelMsgEntity>(); if (welMsgEntities.size() > 0) { for (WelMsgEntity welMsgEntity : welMsgEntities) { if (needlist.size() < 8) { needlist.add(welMsgEntity); } } } List<Article> articleList = new ArrayList<Article>(); for (WelMsgEntity welMsgEntity : needlist) { Article article = new Article(); article.setTitle(welMsgEntity.getTitle()); article.setDescription(welMsgEntity.getDescription()); article.setPicUrl(fileURLPrefix + welMsgEntity.getPicurl()); article.setUrl(welMsgEntity.getUrl()); articleList.add(article); } // 设置图文消息个数 newsMessage.setArticleCount(articleList.size()); // 设置图文消息包含的图文集合 newsMessage.setArticles(articleList); return newsMessage; }
if (eventType.equalsIgnoreCase(MessageUtil.EVENT_TYPE_CLICK)) {
// 事件KEY值,与创建自定义菜单时指定的KEY值对应
String eventKey = requestMap.get("EventKey");
if (eventKey.equals("CONTACT_US")) {
NewsMessage newsMessage = buildmessage(open_id, toUserName, 1);
// 将图文消息对象转换成xml字符串
respMessage = MessageUtil.newsMessageToXml(newsMessage);
}
}
时间: 2024-10-24 13:26:50