破晓 发表于 2016-8-18 15:34:49

微信公众平台开发(十) 消息回复总结

来源:http://www.cnblogs.com/mchina/p/3364377.html<p></p><div><br></div><div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.8; font-size: 16px;"><strong><span style="line-height: 1.8; color: rgb(128, 0, 0);">一、简介</span></strong></span></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">微信公众平台提供了三种消息回复的格式,即文本回复、音乐回复和图文回复,在这一篇文章中,我们将对这三种消息回复的格式做一下简单讲解,然后封装成函数,以供读者使用。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.8; font-size: 16px;"><strong><span style="line-height: 1.8; color: rgb(128, 0, 0);">二、思路分析</span></strong></span></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">对于每一个POST请求,开发者在响应包中返回特定xml结构,对该消息进行响应(现支持回复文本、图文、语音、视频、音乐)。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.8; font-size: 16px;"><strong><span style="line-height: 1.8; color: rgb(128, 0, 0);">三、文本回复</span></strong></span></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">3.1 文本回复xml 结构</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"> <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">xml</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">ToUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">ToUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">FromUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">FromUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">CreateTime</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>12345678<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">CreateTime</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">MsgType</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">MsgType</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Content</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Content</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">xml</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">3.2 结构说明</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/18205001-3ee4bc601f044e9c8b277036e1d1105b.jpg" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">3.3 具体实施</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">针对上面给出的xml 结构,我们只需要在对应的位置填上内容,然后格式化输出就可以了。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/18211600-8673786ea2ba4ae6b8d88eca56a3a977.jpg" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><strong>说明:</strong></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">ToUserName 位置上填写的是$fromUsername = $postObj-&gt;FromUserName,就是把消息返回给发送信息过来的用户,即接收方账号。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">FromUserName 位置上填写的是$toUsername = $postObj-&gt;ToUserName,既是开发者微信号。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">这是官方的文本回复,只需实例化它的responseMsg() 方法就可以回复 “Welcome to wechat world!” 消息了。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">这里我们稍做修改,返回fromUsername 和toUsername 消息,便于读者理解以上的说明。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/18215040-3a4ce7b3ec4542e6806a5014c1b2ccc6.jpg" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">3.4 测试结果</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/18223152-a9d3b639f1d04bd8a4841484b3c8cf33.png" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">3.5 封装成可调用的函数</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">我们可以将上面的内容封装成函数,在需要回复文本的地方直接调用,方便简洁,responseText.func.inc.php&nbsp;代码如下。</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 0, 255);">function</span> _response_text(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$object</span>,<span style="line-height: 1.8; color: rgb(128, 0, 128);">$content</span><span style="line-height: 1.8;">){
    </span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$textTpl</span> = "<span style="line-height: 1.8;">&lt;xml&gt;
                &lt;ToUserName&gt;&lt;!]&gt;&lt;/ToUserName&gt;
                &lt;FromUserName&gt;&lt;!]&gt;&lt;/FromUserName&gt;
                &lt;CreateTime&gt;%s&lt;/CreateTime&gt;
                &lt;MsgType&gt;&lt;!]&gt;&lt;/MsgType&gt;
                &lt;Content&gt;&lt;!]&gt;&lt;/Content&gt;
                &lt;FuncFlag&gt;%d&lt;/FuncFlag&gt;
                &lt;/xml&gt;</span>"<span style="line-height: 1.8;">;
    </span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span> = <span style="line-height: 1.8; color: rgb(0, 128, 128);">sprintf</span>(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$textTpl</span>, <span style="line-height: 1.8; color: rgb(128, 0, 128);">$object</span>-&gt;FromUserName, <span style="line-height: 1.8; color: rgb(128, 0, 128);">$object</span>-&gt;ToUserName, <span style="line-height: 1.8; color: rgb(0, 128, 128);">time</span>(), <span style="line-height: 1.8; color: rgb(128, 0, 128);">$content</span>, <span style="line-height: 1.8; color: rgb(128, 0, 128);">$flag</span><span style="line-height: 1.8;">);
    </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">return</span> <span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span><span style="line-height: 1.8;">;
}</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">这样,只要传入$object 和$content,然后在需要回复文本的文件中引入该文件,然后调用 _response_text() 方法,就可以直接回复文本了。&nbsp;</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">3.6 测试代码</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">3.6.1 在主文件中引入回复文本的函数文件</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 0, 255);">require_once</span> 'responseText.func.inc.php';</pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">3.6.2 普通消息回复</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 0, 255);">public</span> <span style="line-height: 1.8; color: rgb(0, 0, 255);">function</span> handleText(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$postObj</span><span style="line-height: 1.8;">)
    {
      </span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$keyword</span> = <span style="line-height: 1.8; color: rgb(0, 128, 128);">trim</span>(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$postObj</span>-&gt;<span style="line-height: 1.8;">Content);

      </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">if</span>(!<span style="line-height: 1.8; color: rgb(0, 0, 255);">empty</span>( <span style="line-height: 1.8; color: rgb(128, 0, 128);">$keyword</span><span style="line-height: 1.8;"> ))
      {<br>            </span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$contentStr</span> = "微信公众平台-文本回复功能源代码"<span style="line-height: 1.8;">;
            </span><span style="line-height: 1.8; color: rgb(0, 128, 0);">//</span><span style="line-height: 1.8; color: rgb(0, 128, 0);">$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);</span>
            <span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span> = _response_text(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$postObj</span>,<span style="line-height: 1.8; color: rgb(128, 0, 128);">$contentStr</span><span style="line-height: 1.8;">);
            </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">echo</span> <span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span><span style="line-height: 1.8;">;
      }</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">else</span><span style="line-height: 1.8;">{
            </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">echo</span> "Input something..."<span style="line-height: 1.8;">;
      }
}</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.5;">3.6.3 关注时回复</span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 0, 255);">public</span> <span style="line-height: 1.8; color: rgb(0, 0, 255);">function</span> handleEvent(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$object</span><span style="line-height: 1.8;">)
    {
      </span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$contentStr</span> = ""<span style="line-height: 1.8;">;
      </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">switch</span> (<span style="line-height: 1.8; color: rgb(128, 0, 128);">$object</span>-&gt;<span style="line-height: 1.8;">Event)
      {
            </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">case</span> "subscribe":
                <span style="line-height: 1.8; color: rgb(128, 0, 128);">$contentStr</span> = "感谢您关注【卓锦苏州】"."\n"."微信号:zhuojinsz"<span style="line-height: 1.8;">;
                </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">break</span><span style="line-height: 1.8;">;
            </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">default</span> :
                <span style="line-height: 1.8; color: rgb(128, 0, 128);">$contentStr</span> = "Unknow Event: ".<span style="line-height: 1.8; color: rgb(128, 0, 128);">$object</span>-&gt;<span style="line-height: 1.8;">Event;
                </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">break</span><span style="line-height: 1.8;">;
      }
      </span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span> = _response_text(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$object</span>, <span style="line-height: 1.8; color: rgb(128, 0, 128);">$contentStr</span><span style="line-height: 1.8;">);
      </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">return</span> <span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span><span style="line-height: 1.8;">;
}</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">3.7 测试结果</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/18223214-6cb13f8eef0548b1b00c0df5501259e3.png" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">回复文本成功。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.8; color: rgb(128, 0, 0); font-size: 16px;"><strong>四、图文回复</strong></span></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.1 图文回复xml 结构</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"> <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">xml</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">ToUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">ToUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">FromUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">FromUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">CreateTime</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>12345678<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">CreateTime</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">MsgType</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">MsgType</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">ArticleCount</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>2<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">ArticleCount</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Articles</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">item</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Title</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Title</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Description</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Description</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">PicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">PicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Url</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Url</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">item</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">item</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Title</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Title</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Description</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Description</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">PicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">PicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Url</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Url</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">item</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Articles</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">xml</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span> </pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.2 结构说明</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/18223621-687996047cec44c6a4cf010241b772fb.jpg" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">类似文本回复的格式,只需要在相应的位置填上对应的内容就可以回复图文信息了。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.3 具体实施</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">图文回复可以是单图文,也可以是多图文,这里我们先以单图文的案例来引导读者,然后再引出多图文。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">我们将回复图文的xml 结构分解成为以下三个结构,图文头,图文体,图文尾,图文体就是图文回复时看到的标题,描述,图片URL和原文URL。</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;">$newsTplHead = "<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">xml</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
                <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">ToUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">ToUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
                <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">FromUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">FromUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
                <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">CreateTime</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>%s<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">CreateTime</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
                <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">MsgType</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">MsgType</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
                <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">ArticleCount</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>1<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">ArticleCount</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
                <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Articles</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8;">";
$newsTplBody = "</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">item</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
                <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Title</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Title</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
                <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Description</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Description</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
                <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">PicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">PicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
                <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Url</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Url</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
                <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">item</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8;">";
$newsTplFoot = "</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Articles</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
                <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">FuncFlag</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>0<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">FuncFlag</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
                <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">xml</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>";</pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">接下来,我们对三段结构分别插入对应内容:</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">A. $newsTplHead</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;">$header = sprintf($newsTplHead, $object-&gt;FromUserName, $object-&gt;ToUserName, time());</pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">B. $newsTplBody</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8;">$title = $newsContent['title'];
$desc = $newsContent['description'];
$picUrl = $newsContent['picUrl'];
$url = $newsContent['url'];
$body = sprintf($newsTplBody, $title, $desc, $picUrl, $url);</span></pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><strong>说明:</strong>$newsContent 是从主文件传入函数的图文数组。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">C. $newsTplFoot</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8;">$FuncFlag = 0;
$footer = sprintf($newsTplFoot, $FuncFlag);</span></pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">然后将三段进行拼接返回就可以回复单条图文了。</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;">return $header.$body.$footer;</pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">将以上内容写到一个函数里,命名为&nbsp;_response_news() 函数,以供下面调用测试。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.4 测试代码</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.4.1 在主文件中引入回复图文的函数文件</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 0, 255);">require_once</span> 'responseNews.func.inc.php';</pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.4.2 创建数组并传入</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">在主文件中,只需要向 _response_news() 函数中传入一个数组和$postObj 即可。</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(128, 0, 128);">$record</span>=<span style="line-height: 1.8; color: rgb(0, 0, 255);">array</span><span style="line-height: 1.8;">(
    </span>'title' =&gt;'山塘街',
    'description' =&gt;'山塘街东起阊门渡僧桥,西至苏州名胜虎丘山的望山桥,长约七里,所以苏州俗语说“七里山塘到虎丘”...',
    'picUrl' =&gt; 'http://thinkshare.duapp.com/images/suzhou.jpg',
    'url' =&gt;'http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NDM0NTEyMg==&amp;appmsgid=10000046&amp;itemidx=1&amp;sign=9e7707d5615907d483df33ee449b378d#wechat_redirect'<span style="line-height: 1.8;">
);

</span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span> = _response_news(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$postObj</span>,<span style="line-height: 1.8; color: rgb(128, 0, 128);">$record</span><span style="line-height: 1.8;">);
</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">echo</span> <span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span>;</pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.5;">4.5 测试结果</span></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.5;"><img src="http://images.cnitblog.com/blog/370046/201310/18231509-ad717c36131247ceaf06062520a23631.png" alt="" style="border: 0px; max-width: 900px;"></span></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">点击进入查看</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/18231524-fdcefeddc19c4a3bac5e666faf437985.png" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">单图文回复测试成功。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.6 多图文回复</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">有了上面的引导,读者应该能够想到回复多图文的思路了,就是将多维数组中的值循环放到相应的位置,然后拼接起来就可以了,下面进行讲解。&nbsp;</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.6.1 获取图文条数</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(128, 0, 128);">$bodyCount</span> = <span style="line-height: 1.8; color: rgb(0, 128, 128);">count</span>(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$newsContent</span>);</pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.5;">4.6.2 判断图文条数</span></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.5;">因为微信限制了回复的图文消息数为10条以内,所以需要判断图文条数,如果小于10条,则图文数等于原来的图文数,如果大于等于10条,则强制限制为10条。</span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(128, 0, 128);">$bodyCount</span> = <span style="line-height: 1.8; color: rgb(128, 0, 128);">$bodyCount</span> &lt; 10 ? <span style="line-height: 1.8; color: rgb(128, 0, 128);">$bodyCount</span> : 10;</pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.6.3 组织图文体</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">图文头和图文尾和上面单图文一样,不再赘述,主要是图文体的组织。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">用foreach 循环出数组的内容并赋予图文体,并进行拼接:</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 0, 255);">foreach</span>(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$newsContent</span> <span style="line-height: 1.8; color: rgb(0, 0, 255);">as</span> <span style="line-height: 1.8; color: rgb(128, 0, 128);">$key</span> =&gt; <span style="line-height: 1.8; color: rgb(128, 0, 128);">$value</span><span style="line-height: 1.8;">){
    </span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$body</span> .= <span style="line-height: 1.8; color: rgb(0, 128, 128);">sprintf</span>(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$newsTplBody</span>, <span style="line-height: 1.8; color: rgb(128, 0, 128);">$value</span>['title'], <span style="line-height: 1.8; color: rgb(128, 0, 128);">$value</span>['description'], <span style="line-height: 1.8; color: rgb(128, 0, 128);">$value</span>['picUrl'], <span style="line-height: 1.8; color: rgb(128, 0, 128);">$value</span>['url'<span style="line-height: 1.8;">]);
}</span></pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><strong>说明:</strong>$newsContent 是从主文件传入函数的图文数组。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.6.4&nbsp;拼接并返回</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 0, 255);">return</span> <span style="line-height: 1.8; color: rgb(128, 0, 128);">$header</span>.<span style="line-height: 1.8; color: rgb(128, 0, 128);">$body</span>.<span style="line-height: 1.8; color: rgb(128, 0, 128);">$footer</span>;</pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">将以上内容写到一个函数里,命名为 _response_multiNews() 函数,以供下面调用测试。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.7 测试多图文</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.7.1 在主文件中引入回复多图文的函数文件</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 0, 255);">require_once</span> 'responseMultiNews.func.inc.php';</pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.7.2&nbsp;创建多维数组并传入</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(128, 0, 128);">$record</span>=<span style="line-height: 1.8; color: rgb(0, 0, 255);">array</span><span style="line-height: 1.8;">(
    </span>'title' =&gt;'观前街',
    'description' =&gt;'观前街位于江苏苏州市区,是成街于清朝时期的百年商业老街,街上老店名店云集,名声远播海内外...',
    'picUrl' =&gt; 'http://joythink.duapp.com/images/suzhou.jpg',
    'url' =&gt;'http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NDM0NTEyMg==&amp;appmsgid=10000052&amp;itemidx=1&amp;sign=90518631fd3e85dd1fde7f77c04e44d5#wechat_redirect'<span style="line-height: 1.8;">
);

</span>......

<span style="line-height: 1.8; color: rgb(128, 0, 128);">$record</span>=<span style="line-height: 1.8; color: rgb(0, 0, 255);">array</span><span style="line-height: 1.8;">(
    </span>'title' =&gt;'平江路',
    'description' =&gt;'平江路位于苏州古城东北,是一条傍河的小路,北接拙政园,南眺双塔,全长1606米,是苏州一条历史攸久的经典水巷。宋元时候苏州又名平江,以此名路...',
    'picUrl' =&gt; 'http://joythink.duapp.com/images/suzhouScenic/pingjianglu.jpg',
    'url' =&gt;'http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NDM0NTEyMg==&amp;appmsgid=10000056&amp;itemidx=1&amp;sign=ef18a26ce78c247f3071fb553484d97a#wechat_redirect'<span style="line-height: 1.8;">
);

</span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span> = _response_multiNews(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$postObj</span>,<span style="line-height: 1.8; color: rgb(128, 0, 128);">$record</span><span style="line-height: 1.8;">);
</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">echo</span> <span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span>;</pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">4.8 测试多图文结果</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/19000912-7941e955bea3452b9487954fd7fc3d99.png" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">点击进入查看</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/19000939-98c257b3e807402da7e439941156cb54.png" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">测试多图文成功。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.8; font-size: 16px;"><strong><span style="line-height: 1.8; color: rgb(128, 0, 0);">五、音乐回复</span></strong></span></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">微信还提供了一种消息回复的格式,即音乐回复,下面我们编写程序测试一下。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.8; color: rgb(128, 0, 0);"><strong>注意:</strong></span>由于音乐版权的问题,现在很少有回复音乐的API,开放的API 查询出来的音乐信息也有很多是不正确的。所以在这里,我们上传几首音乐到自己的服务器空间测试。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">本地文件:</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/19172252-7d9708fd4d754f27990b09a05ebbd034.jpg" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">测试是否能够正常播放:</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/19172319-6b07e225577c47cb88849c81328fa62d.jpg" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">5.1 音乐回复xml 结构</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"> <span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">xml</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">ToUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">ToUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">FromUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">FromUserName</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">CreateTime</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>12345678<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">CreateTime</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">MsgType</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">MsgType</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Music</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Title</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Title</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Description</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Description</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">MusicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">MusicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">HQMusicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">HQMusicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Music</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">xml</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">5.2 结构说明</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/19170733-5888f6cfa67c4eba97de622f89420a05.jpg" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">5.3 具体实施</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">我们先做一个固定的歌曲回复来引导读者,然后再引出更高级别的歌曲查询回复。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">5.3.1 在xml 结构的相应位置插入相应数据</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Music</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Title</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Title</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Description</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Description</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">MusicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">MusicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">HQMusicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;!]&gt;</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">HQMusicUrl</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">&lt;/</span><span style="line-height: 1.8; color: rgb(128, 0, 0);">Music</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">&gt;</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">5.3.2 测试代码</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span> = _response_music(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$postObj</span>,<span style="line-height: 1.8; color: rgb(128, 0, 128);">$keyword</span><span style="line-height: 1.8;">);
</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">echo</span> <span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span>;                  </pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">5.3.3 测试结果</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/19194634-0ffd26cbae434cbeac67ec836118d8eb.png" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">5.4 模拟点歌</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">有了上面的简单案例引导,读者应该可以想到模拟点歌的具体实现了吧,下面就来简单介绍一下。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><strong>思路:</strong>将歌曲代码和对应的歌曲名存入数据库,用户输入歌曲名,在数据库中找到歌曲名对应的歌曲编号,然后就可以生成MusicUrl 回复用户了。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">5.4.1 创建数据库</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/19195554-473a6a1e5f294f25bd5d448ca556877d.jpg" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">建表语句及数据文件:</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 0, 255);">CREATE</span> <span style="line-height: 1.8; color: rgb(0, 0, 255);">TABLE</span> <span style="line-height: 1.8; color: rgb(0, 0, 255);">IF</span> <span style="line-height: 1.8; color: rgb(128, 128, 128);">NOT</span> <span style="line-height: 1.8; color: rgb(128, 128, 128);">EXISTS</span><span style="line-height: 1.8;"> `tbl_music` (
`music_id` </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">int</span>(<span style="line-height: 1.8; color: rgb(128, 0, 0); font-weight: bold;">11</span>) <span style="line-height: 1.8; color: rgb(128, 128, 128);">NOT</span> <span style="line-height: 1.8; color: rgb(0, 0, 255);">NULL</span><span style="line-height: 1.8;">,
`music_name` </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">varchar</span>(<span style="line-height: 1.8; color: rgb(128, 0, 0); font-weight: bold;">40</span>) <span style="line-height: 1.8; color: rgb(128, 128, 128);">NOT</span> <span style="line-height: 1.8; color: rgb(0, 0, 255);">NULL</span><span style="line-height: 1.8;">,
`music_singer` </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">varchar</span>(<span style="line-height: 1.8; color: rgb(128, 0, 0); font-weight: bold;">40</span>) <span style="line-height: 1.8; color: rgb(128, 128, 128);">NOT</span> <span style="line-height: 1.8; color: rgb(0, 0, 255);">NULL</span><span style="line-height: 1.8;">,
`music_lrc` </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">text</span> <span style="line-height: 1.8; color: rgb(128, 128, 128);">NOT</span> <span style="line-height: 1.8; color: rgb(0, 0, 255);">NULL</span><span style="line-height: 1.8;">,
</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">PRIMARY</span> <span style="line-height: 1.8; color: rgb(0, 0, 255);">KEY</span><span style="line-height: 1.8;"> (`music_id`)
) ENGINE</span><span style="line-height: 1.8; color: rgb(128, 128, 128);">=</span>MyISAM <span style="line-height: 1.8; color: rgb(0, 0, 255);">DEFAULT</span> CHARSET<span style="line-height: 1.8; color: rgb(128, 128, 128);">=</span><span style="line-height: 1.8;">utf8;

</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">INSERT</span> <span style="line-height: 1.8; color: rgb(0, 0, 255);">INTO</span> `tbl_music` (`music_id`, `music_name`, `music_singer`, `music_lrc`) <span style="line-height: 1.8; color: rgb(0, 0, 255);">VALUES</span><span style="line-height: 1.8;">
(</span><span style="line-height: 1.8; color: rgb(128, 0, 0); font-weight: bold;">10001</span>, <span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">Far Away From Home</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span>, <span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">Groove Coverage</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span>, <span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">far away from home</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8;">),
(</span><span style="line-height: 1.8; color: rgb(128, 0, 0); font-weight: bold;">10002</span>, <span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">The Dawn</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span>, <span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">Dreamtale</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span>, <span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">the dawn</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8;">),
(</span><span style="line-height: 1.8; color: rgb(128, 0, 0); font-weight: bold;">20002</span>, <span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">董小姐</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span>, <span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">宋冬野</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span>, <span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">董小姐</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8;">),
(</span><span style="line-height: 1.8; color: rgb(128, 0, 0); font-weight: bold;">20001</span>, <span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">左边</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span>, <span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">杨丞琳</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span>, <span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">左边</span><span style="line-height: 1.8; color: rgb(255, 0, 0);">'</span>);</pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">5.4.2 _response_music() 函数编写</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">A. 引入数据库操作文件</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 0, 255);">require_once</span>('mysql_bae.func.php');</pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">B. 数据库操作及数据处理</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(128, 0, 128);">$query</span> = "SELECT * FROM tbl_music WHERE music_name LIKE '%<span style="line-height: 1.8; color: rgb(128, 0, 128);">$musicKeyword</span>%'"<span style="line-height: 1.8;">;
</span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$result</span> = _select_data(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$query</span><span style="line-height: 1.8;">);
</span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$rows</span> = <span style="line-height: 1.8; color: rgb(0, 128, 128);">mysql_fetch_array</span>(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$result</span>,<span style="line-height: 1.8;"> MYSQL_ASSOC);

</span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$music_id</span> = <span style="line-height: 1.8; color: rgb(128, 0, 128);">$rows</span>;</pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><strong>注:</strong>&nbsp;$musicKeyword 为从主文件传入的歌曲名关键字,这里使用模糊查询,只取第一条数据。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">C. 判断是否查询到</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 0, 255);">if</span>(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$music_id</span> &lt;&gt; ''<span style="line-height: 1.8;">)
{
    </span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$music_name</span> = <span style="line-height: 1.8; color: rgb(128, 0, 128);">$rows</span><span style="line-height: 1.8;">;
    </span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$music_singer</span> = <span style="line-height: 1.8; color: rgb(128, 0, 128);">$rows</span><span style="line-height: 1.8;">;
    </span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$musicUrl</span> = "http://thinkshare.duapp.com/music/".<span style="line-height: 1.8; color: rgb(128, 0, 128);">$music_id</span>.".mp3"<span style="line-height: 1.8;">;
    </span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$HQmusicUrl</span> = "http://thinkshare.duapp.com/music/".<span style="line-height: 1.8; color: rgb(128, 0, 128);">$music_id</span>.".mp3"<span style="line-height: 1.8;">;

    </span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span> = <span style="line-height: 1.8; color: rgb(0, 128, 128);">sprintf</span>(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$musicTpl</span>, <span style="line-height: 1.8; color: rgb(128, 0, 128);">$object</span>-&gt;FromUserName, <span style="line-height: 1.8; color: rgb(128, 0, 128);">$object</span>-&gt;ToUserName, <span style="line-height: 1.8; color: rgb(0, 128, 128);">time</span>(), <span style="line-height: 1.8; color: rgb(128, 0, 128);">$music_name</span>, <span style="line-height: 1.8; color: rgb(128, 0, 128);">$music_singer</span>, <span style="line-height: 1.8; color: rgb(128, 0, 128);">$musicUrl</span>, <span style="line-height: 1.8; color: rgb(128, 0, 128);">$HQmusicUrl</span><span style="line-height: 1.8;">);
    </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">return</span> <span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span><span style="line-height: 1.8;">;
}</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">else</span><span style="line-height: 1.8;">{
    </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">return</span> ""<span style="line-height: 1.8;">;   
}</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><strong>说明:</strong>如果查询到歌曲信息,按照xml 结构返回数据;如果未查询到,则返回空,用于主文件判断。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">将以上代码封装成&nbsp;_response_music() 函数并保存为responseMusic.func.inc.php 文件供主文件调用。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">5.4.3 测试代码</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">A. 引入回复音乐和回复文本的函数文件</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 128, 0);">//</span><span style="line-height: 1.8; color: rgb(0, 128, 0);">引入回复音乐的函数文件</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">require_once</span> 'responseMusic.func.inc.php'<span style="line-height: 1.8;">;
</span><span style="line-height: 1.8; color: rgb(0, 128, 0);">//</span><span style="line-height: 1.8; color: rgb(0, 128, 0);">引入回复文本的函数文件</span>
<span style="line-height: 1.8; color: rgb(0, 0, 255);">require_once</span> 'responseText.func.inc.php';</pre></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">B. 调用</p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important; background-color: rgb(245, 245, 245);"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div><pre style="white-space: pre-wrap; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.8; color: rgb(0, 0, 255);">if</span>(!<span style="line-height: 1.8; color: rgb(0, 0, 255);">empty</span>( <span style="line-height: 1.8; color: rgb(128, 0, 128);">$keyword</span><span style="line-height: 1.8;"> ))
{
    </span><span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span> = _response_music(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$postObj</span>,<span style="line-height: 1.8; color: rgb(128, 0, 128);">$keyword</span><span style="line-height: 1.8;">);
    </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">if</span>(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span> &lt;&gt; ''<span style="line-height: 1.8;">)
    {
      </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">echo</span> <span style="line-height: 1.8; color: rgb(128, 0, 128);">$resultStr</span><span style="line-height: 1.8;">;
    }</span><span style="line-height: 1.8; color: rgb(0, 0, 255);">else</span><span style="line-height: 1.8;">
    {
      </span><span style="line-height: 1.8; color: rgb(0, 0, 255);">echo</span> _response_text(<span style="line-height: 1.8; color: rgb(128, 0, 128);">$postObj</span>,"未查询到【".<span style="line-height: 1.8; color: rgb(128, 0, 128);">$keyword</span>."】的歌曲信息!"<span style="line-height: 1.8;">);   
    }
   
}</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.8;"><a title="复制代码" style="color: rgb(0, 0, 0); border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 900px;"></a></span></div></div><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><strong>说明:</strong>如果查询到歌曲信息,则返回所得信息,如果未查询到,则调用 _response_text() 函数返回文本信息。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">5.5 模拟点歌测试</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/19201432-6f1458831aa14f289ee14be2d581b290.png" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">回复音乐测试成功。&nbsp;</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.8; color: rgb(128, 0, 0); font-size: 16px;"><strong>六、完整代码获取</strong></span></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.8;">请访问&nbsp;<a href="http://pan.baidu.com/s/1c0s3Jby" target="_blank" style="text-decoration: none; color: rgb(0, 0, 0); border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: rgb(51, 51, 51);"><span style="line-height: 1.8; color: rgb(128, 0, 0);"><strong>乐思乐享</strong></span></a>&nbsp;官方论坛</span></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.8;"><strong>URL</strong>:</span><a href="http://pan.baidu.com/s/1c0s3Jby" target="_blank" style="text-decoration: none; color: rgb(0, 0, 0); border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: rgb(51, 51, 51);">http://pan.baidu.com/s/1c0s3Jby</a></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.8; color: rgb(128, 0, 0); font-size: 16px;"><strong>七、关注</strong></span></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">请关注<span style="line-height: 1.8;">&nbsp;</span><span style="line-height: 1.8; color: rgb(128, 0, 0);"><strong>卓锦苏州</strong>&nbsp;</span>微信公众帐号,<span style="line-height: 1.8; color: rgb(128, 0, 0);"><strong>卓锦苏州</strong></span>&nbsp;基于BAE 平台开发,针对于主流的微信功能进行开发测试。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">您可以关注&nbsp;<span style="line-height: 1.8; color: rgb(128, 0, 0);"><strong>卓锦苏州</strong>&nbsp;</span>公众帐号进行功能测试,以及获取新的应用开发。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">1. 登录微信客户端,通讯录 -&gt; 添加朋友 -&gt; 查找公众号 -&gt;<span style="line-height: 1.8;">&nbsp;<span style="line-height: 1.8; color: rgb(128, 0, 0);"><strong>zhuojinsz</strong></span></span>,查找并关注。</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">2. 扫描二维码:</p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/07160054-359dcfa75fd34464bc6d8d8224a700f5.jpg" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.8;"><strong>卓锦苏州</strong></span><span style="line-height: 1.8;"><span style="line-height: 1.8;">&nbsp;</span>功能列表:</span></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><img src="http://images.cnitblog.com/blog/370046/201310/07160044-e2bf032c27f94f778132cb4a9e06431a.png" alt="" style="border: 0px; max-width: 900px;"></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;">&nbsp;</p><hr style="color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.8; color: rgb(128, 0, 0);"><strong>David Camp</strong></span></p><p style="margin: 10px auto; color: rgb(51, 51, 51); font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px;"><span style="line-height: 1.8; color: rgb(128, 0, 0);"><strong><strong><strong>我们永远相信,分享是一种美德 |&nbsp;</strong></strong>We Believe, Great People Share Knowledge...</strong></span></p></div>
页: [1]
查看完整版本: 微信公众平台开发(十) 消息回复总结