public static StringBuffer confArticleBuf( String to, String from, ArrayList<com.gizwits.weixin.newGokitdog.bean.Article> articles) { StringBuffer sbBuffer = new StringBuffer(); int articleCount = articles.size(); sbBuffer .append("<xml><ToUserName><![CDATA[") .append(to) .append("]]></ToUserName><FromUserName><![CDATA[") .append(from) .append("]]></FromUserName><CreateTime>") .append(System.currentTimeMillis()) .append("</CreateTime><MsgType><![CDATA[news]]></MsgType>") .append("<ArticleCount>") .append(articleCount) .append("</ArticleCount><Articles>"); for (com.gizwits.weixin.newGokitdog.bean.Article article : articles) { sbBuffer .append("<item><Title><![CDATA[") .append(article.getTitle()) .append("]]></Title><Description><![CDATA[") .append(article.getDescription()) .append("]]></Description><PicUrl><![CDATA[") .append(article.getPicUrl()) .append("]]></PicUrl><Url><![CDATA[") .append(article.getUrl()) .append("]]></Url></item>"); } sbBuffer.append("</Articles></xml>"); return sbBuffer; }
// 建立微信的图文消息 public static StringBuffer buildArticle(Article article) { StringBuffer sb = new StringBuffer(); sb.append("{\"title\":\""); sb.append(article.getTitle()); sb.append("\",\"description\":\""); sb.append(article.getDescription()); sb.append("\",\"url\":\""); sb.append(article.getUrl()); sb.append("\",\"picurl\":\""); sb.append(article.getPicUrl()); sb.append("\"}"); return sb; }