// 單圖文訊息
if ("1".equals(content))
{
Article article = new Article();
article.setTitle("微信公眾帳號開發教程Java版");
article.setDescription("為幫助初學者入門,特推出此係列教程,也希望藉此機會認識更多同行!");
article.setPicUrl("http://0.xiaoqrobot.duapp.com/images/avatar_liufeng.jpg");
article.setUrl("http://blog.csdn.net/lyq8479");
articleList.add(article);
// 設定圖文訊息個數
newsMessage.setArticleCount(articleList.size());
// 設定圖文訊息包含的圖文集合
newsMessage.setArticles(articleList);
// 將圖文訊息物件轉換成xml字串
respMessage = MessageUtil.newsMessageToXml(newsMessage);
}
// 單圖文訊息---不含圖片
else if ("2".equals(content))
{
Article article = new Article();
article.setTitle("微信公眾帳號開發教程Java版");
// 圖文訊息中可以使用QQ表情、符號表情
article.setDescription("柳峰,80後," + emoji(0x1F6B9)
+ ",微信公眾帳號開發經驗4個月。為幫助初學者入門,特推出此係列連載教程,也希望藉此機會認識更多同行!\n\n目前已推出教程共12篇,包括介面配置、訊息封裝、框架搭建、QQ表情傳送、符號表情傳送等。\n\n後期還計劃推出一些實用功能的開發講解,例如:天氣預報、周邊搜尋、聊天功能等。");
// 將圖片置為空
article.setPicUrl("");
article.setUrl("http://blog.csdn.net/lyq8479");
articleList.add(article);
newsMessage.setArticleCount(articleList.size());
newsMessage.setArticles(articleList);
respMessage = MessageUtil.newsMessageToXml(newsMessage);
}
// 多圖文訊息
else if ("3".equals(content))
{
Article article1 = new Article();
article1.setTitle("微信公眾帳號開發教程\n引言");
article1.setDescription("");
article1.setPicUrl("http://0.xiaoqrobot.duapp.com/images/avatar_liufeng.jpg");
article1.setUrl("http://blog.csdn.net/lyq8479/article/details/8937622");
Article article2 = new Article();
article2.setTitle("第2篇\n微信公眾帳號的型別");
article2.setDescription("");
article2.setPicUrl("http://avatar.csdn.net/1/4/A/1_lyq8479.jpg");
article2.setUrl("http://blog.csdn.net/lyq8479/article/details/8941577");
Article article3 = new Article();
article3.setTitle("第3篇\n開發模式啟用及介面配置");
article3.setDescription("");
article3.setPicUrl("http://avatar.csdn.net/1/4/A/1_lyq8479.jpg");
article3.setUrl("http://blog.csdn.net/lyq8479/article/details/8944988");
articleList.add(article1);
articleList.add(article2);
articleList.add(article3);
newsMessage.setArticleCount(articleList.size());
newsMessage.setArticles(articleList);
respMessage = MessageUtil.newsMessageToXml(newsMessage);
}
// 多圖文訊息---首條訊息不含圖片
else if ("4".equals(content))
{
Article article1 = new Article();
article1.setTitle("微信公眾帳號開發教程Java版");
article1.setDescription("");
// 將圖片置為空
article1.setPicUrl("");
article1.setUrl("http://blog.csdn.net/lyq8479");
Article article2 = new Article();
article2.setTitle("第4篇\n訊息及訊息處理工具的封裝");
article2.setDescription("");
article2.setPicUrl("http://avatar.csdn.net/1/4/A/1_lyq8479.jpg");
article2.setUrl("http://blog.csdn.net/lyq8479/article/details/8949088");
Article article3 = new Article();
article3.setTitle("第5篇\n各種訊息的接收與響應");
article3.setDescription("");
article3.setPicUrl("http://avatar.csdn.net/1/4/A/1_lyq8479.jpg");
article3.setUrl("http://blog.csdn.net/lyq8479/article/details/8952173");
Article article4 = new Article();
article4.setTitle("第6篇\n文字訊息的內容長度限制揭祕");
article4.setDescription("");
article4.setPicUrl("http://avatar.csdn.net/1/4/A/1_lyq8479.jpg");
article4.setUrl("http://blog.csdn.net/lyq8479/article/details/8967824");
articleList.add(article1);
articleList.add(article2);
articleList.add(article3);
articleList.add(article4);
newsMessage.setArticleCount(articleList.size());
newsMessage.setArticles(articleList);
respMessage = MessageUtil.newsMessageToXml(newsMessage);
}
// 多圖文訊息---最後一條訊息不含圖片
else if ("5".equals(content))
{
Article article1 = new Article();
article1.setTitle("第7篇\n文字訊息中換行符的使用");
article1.setDescription("");
article1.setPicUrl("http://0.xiaoqrobot.duapp.com/images/avatar_liufeng.jpg");
article1.setUrl("http://blog.csdn.net/lyq8479/article/details/9141467");
Article article2 = new Article();
article2.setTitle("第8篇\n文字訊息中使用網頁超連結");
article2.setDescription("");
article2.setPicUrl("http://avatar.csdn.net/1/4/A/1_lyq8479.jpg");
article2.setUrl("http://blog.csdn.net/lyq8479/article/details/9157455");
Article article3 = new Article();
article3.setTitle("如果覺得文章對你有所幫助,請通過部落格留言或關注微信公眾帳號xiaoqrobot來支援柳峰!");
article3.setDescription("");
// 將圖片置為空
article3.setPicUrl("");
article3.setUrl("http://blog.csdn.net/lyq8479");
articleList.add(article1);
articleList.add(article2);
articleList.add(article3);
newsMessage.setArticleCount(articleList.size());
newsMessage.setArticles(articleList);
respMessage = MessageUtil.newsMessageToXml(newsMessage);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return respMessage;
}
/**
* emoji表情轉換(hex -> utf-16)
*
* @param hexEmoji
* @return
*/
public static String emoji(int hexEmoji) {
return String.valueOf(Character.toChars(hexEmoji));
}
}