<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                引言: 上一章講到了消息的接收和發送,但是講的是最簡單的文本信息。 在微信中用的最多的信息還是圖文消息,本章就為大家講解下微信圖文消息是如何實現的。 包括單圖文和多圖文消息。 圖文消息的XML數據包結構: ~~~ <xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>12345678</CreateTime> <MsgType><![CDATA[news]]></MsgType> <ArticleCount>2</ArticleCount> <Articles> <item> <Title><![CDATA[title1]]></Title> <Description><![CDATA[description1]]></Description> <PicUrl><![CDATA[picurl]]></PicUrl> <Url><![CDATA[url]]></Url> </item> <item> <Title><![CDATA[title]]></Title> <Description><![CDATA[description]]></Description> <PicUrl><![CDATA[picurl]]></PicUrl> <Url><![CDATA[url]]></Url> </item> </Articles> </xml> ~~~ ? ? ![](https://box.kancloud.cn/2016-03-07_56dce484019f2.jpg) ? 從上面結構圖中可以看出要注意的幾點 1、圖文消息的條數最大限制為10, 2、多圖文中列表中的第一個為大圖,其余為小圖 注意:在多圖文模式下只有第一個可以顯示描述信息,其余的都不顯示 了解了圖文消息的結構后,要發送圖文消息就簡單了。 我們之前已經封裝過消息處理的代碼和圖文消息的實體類,這里就不啰嗦了,不知道的可以看上一章 [微信公眾平臺開發教程Java版(三) 消息接收和發送](# "微信公眾平臺開發教程Java版(三) 消息接收和發送") ? 下面我就上單圖文和多圖文消息的源代碼 ? ~~~ package com.ifp.weixin.biz.core.impl; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.log4j.Logger; import org.springframework.stereotype.Service; import com.ifp.weixin.biz.core.CoreService; import com.ifp.weixin.constant.Constant; import com.ifp.weixin.entity.Message.resp.Article; import com.ifp.weixin.entity.Message.resp.NewsMessage; import com.ifp.weixin.entity.Message.resp.TextMessage; import com.ifp.weixin.util.MessageUtil; @Service("coreService") public class CoreServiceImpl implements CoreService { public static Logger log = Logger.getLogger(CoreServiceImpl.class); @Override public String processRequest(HttpServletRequest request) { String respMessage = null; try { // xml請求解析 Map<String, String> requestMap = MessageUtil.parseXml(request); // 發送方帳號(open_id) String fromUserName = requestMap.get("FromUserName"); // 公眾帳號 String toUserName = requestMap.get("ToUserName"); // 消息類型 String msgType = requestMap.get("MsgType"); TextMessage textMessage = new TextMessage(); textMessage.setToUserName(fromUserName); textMessage.setFromUserName(toUserName); textMessage.setCreateTime(new Date().getTime()); textMessage.setMsgType(Constant.RESP_MESSAGE_TYPE_TEXT); textMessage.setFuncFlag(0); // 文本消息 if (msgType.equals(Constant.REQ_MESSAGE_TYPE_TEXT)) { // 接收用戶發送的文本消息內容 String content = requestMap.get("Content"); // 創建圖文消息 NewsMessage newsMessage = new NewsMessage(); newsMessage.setToUserName(fromUserName); newsMessage.setFromUserName(toUserName); newsMessage.setCreateTime(new Date().getTime()); newsMessage.setMsgType(Constant.RESP_MESSAGE_TYPE_NEWS); newsMessage.setFuncFlag(0); List<Article> articleList = new ArrayList<Article>(); // 單圖文消息 if ("1".equals(content)) { Article article = new Article(); article.setTitle("我是一條單圖文消息"); article.setDescription("我是描述信息,哈哈哈哈哈哈哈。。。"); article.setPicUrl("http://www.iteye.com/upload/logo/user/603624/2dc5ec35-073c-35e7-9b88-274d6b39d560.jpg"); article.setUrl("http://tuposky.iteye.com"); articleList.add(article); // 設置圖文消息個數 newsMessage.setArticleCount(articleList.size()); // 設置圖文消息包含的圖文集合 newsMessage.setArticles(articleList); // 將圖文消息對象轉換成xml字符串 respMessage = MessageUtil.newsMessageToXml(newsMessage); } // 多圖文消息 else if ("3".equals(content)) { Article article1 = new Article(); article1.setTitle("我是一條多圖文消息"); article1.setDescription(""); article1.setPicUrl("http://www.isic.cn/viewResourcesAction//logo/20130913/2013091314543416032.jpg"); article1.setUrl("http://tuposky.iteye.com/blog/2008583"); Article article2 = new Article(); article2.setTitle("微信公眾平臺開發教程Java版(二)接口配置 "); article2.setDescription(""); article2.setPicUrl("http://www.isic.cn/viewResourcesAction//logo/20131021/2013102111243367254.jpg"); article2.setUrl("http://tuposky.iteye.com/blog/2008655"); Article article3 = new Article(); article3.setTitle("微信公眾平臺開發教程Java版(三) 消息接收和發送"); article3.setDescription(""); article3.setPicUrl("http://www.isic.cn/viewResourcesAction//logo/20131021/2013102111291287031.jpg"); article3.setUrl("http://tuposky.iteye.com/blog/2017429"); 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; } } ~~~ ? 單個圖文和多圖文的處理方式其實是一樣的 單圖文的時候articleList 的size為1 多圖文的時候為多個。 ? 運行的效果截圖如下: 用戶發送1,單圖文消息 ![](https://box.kancloud.cn/2016-03-07_56dce48420510.png) ? 用戶發送3 多圖文消息 ![](https://box.kancloud.cn/2016-03-07_56dce48453468.png) ? ?Ps: 圖文消息中的圖片是可以引用外部資源的! ? ? ?可加我的微信公眾號一起討論 微信公眾號:andedaohang 或掃描二維碼 ![](https://box.kancloud.cn/2016-03-07_56dce482f16c7.jpg) ? ?轉載請注明出處:[http://blog.csdn.net/tuposky/article/details/40589319](http://blog.csdn.net/tuposky/article/details/40589319)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看