/* * 签到时返回的图文消息 */ public static String signNewsMessage(String toUserName, String fromUserName) { String message = null; List<Article> articleList = new ArrayList<Article>(); NewsMessage newsMessage = new NewsMessage(); Article article = new Article(); article.setTitle("打卡成功!"); article.setDescription("↓↓↓戳我,就现在"); article.setPicUrl( "http://imgsrc.baidu.com/forum/w%3D580/sign=5fac7d37253fb80e0cd161df06d12ffb/bf19852397dda144f3711db4b6b7d0a20df4868e.jpg"); article.setUrl(SIGN_URL + "?openid=" + fromUserName); // article.setUrl("H7t11zWvCnnGk6Cg-v-IO2JfBwEAYWGLaNUWssLNPq1YcDts5V5SGwM9-q01SIgP"); articleList.add(article); newsMessage.setFromUserName(toUserName); newsMessage.setToUserName(fromUserName); newsMessage.setArticles(articleList); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); newsMessage.setCreateTime(sdf.format(new Date())); newsMessage.setArticleCount(articleList.size()); newsMessage.setMsgType(MESSAGE_NEWS); message = MessageUtil.newsMessageToXml(newsMessage); return message; }
/* * 点击搞笑一则,随机获取图文消息 */ public static String getOneNews(String toUserName, String fromUserName) throws IOException { String message = null; List<Article> articleList = new ArrayList<Article>(); NewsMessage newsMessage = new NewsMessage(); Items[] items = GetItems.getItems(); int random = (int) Math.round(Math.random() * 20); System.out.println(random); for (int i = 0; i < 10; i++) { Article article = new Article(); article.setTitle(items[random].getHeader()); article.setDescription(items[random].getContent()); article.setPicUrl(items[random].getThumbnail()); article.setUrl(ARTICLE_URL + "?articleId=" + items[random].getArticalId()); articleList.add(article); ++random; } newsMessage.setFromUserName(toUserName); newsMessage.setToUserName(fromUserName); newsMessage.setArticles(articleList); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); newsMessage.setCreateTime(sdf.format(new Date())); newsMessage.setArticleCount(articleList.size()); newsMessage.setMsgType(MESSAGE_NEWS); message = MessageUtil.newsMessageToXml(newsMessage); return message; }