关键字:微信公众平台 自定义菜单 扫一扫 发图片 发地理位置
作者:方倍工作室
原文:http://www.cnblogs.com/txw1958/p/weixin-menu-new-type.html
自定义菜单能够帮助公众号丰富界面,让用户更好更快地理解公众号的重要功能。微信增加了点击菜单后调起扫一扫(支持二维码/一维码)、发图片、发地理位置的能力,需开发实现。原有自定义菜单开发权限的公众号,均可获得以上能力。
在这篇微信公众平台开发教程中,我们将介绍如何在自定义菜单上开发扫一扫、发图片、发地理位置等功能。原有点击和跳转事件的开发,请参考微信公众平台开发(58)自定义菜单。
本文分为以下二个部分:
1. 扫码推送事件 scancode_push
用户点击按钮后,微信客户端将调起扫一扫工具,完成扫码操作后显示扫描结果(如果是URL,将进入URL),且会将扫码的结果传给开发者,开发者可以下发消息。
2. 扫码推送事件,且弹出“消息接收中”提示框 scancode_waitmsg
用户点击按钮后,微信客户端将调起扫一扫工具,完成扫码操作后,将扫码的结果传给开发者,同时收起扫一扫工具,然后弹出“消息接收中”提示框,随后可能会收到开发者下发的消息。
3. 弹出系统拍照发图 pic_sysphoto
用户点击按钮后,微信客户端将调起系统相机,完成拍照操作后,将拍摄的相片发送给开发者,并推送事件给开发者,同时收起系统相机,随后可能会收到开发者下发的消息。
4. 弹出拍照或者相册发图 pic_photo_or_album
用户点击按钮后,微信客户端将弹出选择器供用户选择“拍照”或者“从手机相册选择”。用户选择后即走其他两种流程。
5. 弹出微信相册发图器 pic_weixin
用户点击按钮后,微信客户端将调起微信相册,完成选择操作后,将选择的相片发送给开发者的服务器,并推送事件给开发者,同时收起相册,随后可能会收到开发者下发的消息。
6. 弹出地理位置选择器 location_select
用户点击按钮后,微信客户端将调起地理位置选择工具,完成选择操作后,将选择的地理位置发送给开发者的服务器,同时收起位置选择工具,随后可能会收到开发者下发的消息。
以上新增能力,均仅支持微信iPhone5.4.1以上版本,和Android5.4以上版本的微信用户,旧版本微信用户点击后将没有回应,开发者也不能正常接收到事件推送。
接口调用请求说明
http请求方式:POST(请使用https协议)
https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
按钮请求示例如下
<span>{ </span><span>"</span><span>button</span><span>"</span><span>: [ { </span><span>"</span><span>name</span><span>"</span>: <span>"</span><span>扫码</span><span>"</span><span>, </span><span>"</span><span>sub_button</span><span>"</span><span>: [ { </span><span>"</span><span>type</span><span>"</span>: <span>"</span><span>scancode_waitmsg</span><span>"</span><span>, </span><span>"</span><span>name</span><span>"</span>: <span>"</span><span>扫码带提示</span><span>"</span><span>, </span><span>"</span><span>key</span><span>"</span>: <span>"</span><span>rselfmenu_0_0</span><span>"</span><span>, </span><span>"</span><span>sub_button</span><span>"</span><span>: [ ] }, { </span><span>"</span><span>type</span><span>"</span>: <span>"</span><span>scancode_push</span><span>"</span><span>, </span><span>"</span><span>name</span><span>"</span>: <span>"</span><span>扫码推事件</span><span>"</span><span>, </span><span>"</span><span>key</span><span>"</span>: <span>"</span><span>rselfmenu_0_1</span><span>"</span><span>, </span><span>"</span><span>sub_button</span><span>"</span><span>: [ ] } ] }, { </span><span>"</span><span>name</span><span>"</span>: <span>"</span><span>发图</span><span>"</span><span>, </span><span>"</span><span>sub_button</span><span>"</span><span>: [ { </span><span>"</span><span>type</span><span>"</span>: <span>"</span><span>pic_sysphoto</span><span>"</span><span>, </span><span>"</span><span>name</span><span>"</span>: <span>"</span><span>系统拍照发图</span><span>"</span><span>, </span><span>"</span><span>key</span><span>"</span>: <span>"</span><span>rselfmenu_1_0</span><span>"</span><span>, </span><span>"</span><span>sub_button</span><span>"</span><span>: [ ] }, { </span><span>"</span><span>type</span><span>"</span>: <span>"</span><span>pic_photo_or_album</span><span>"</span><span>, </span><span>"</span><span>name</span><span>"</span>: <span>"</span><span>拍照或者相册发图</span><span>"</span><span>, </span><span>"</span><span>key</span><span>"</span>: <span>"</span><span>rselfmenu_1_1</span><span>"</span><span>, </span><span>"</span><span>sub_button</span><span>"</span><span>: [ ] }, { </span><span>"</span><span>type</span><span>"</span>: <span>"</span><span>pic_weixin</span><span>"</span><span>, </span><span>"</span><span>name</span><span>"</span>: <span>"</span><span>微信相册发图</span><span>"</span><span>, </span><span>"</span><span>key</span><span>"</span>: <span>"</span><span>rselfmenu_1_2</span><span>"</span><span>, </span><span>"</span><span>sub_button</span><span>"</span><span>: [ ] } ] }, { </span><span>"</span><span>name</span><span>"</span>: <span>"</span><span>发送位置</span><span>"</span><span>, </span><span>"</span><span>type</span><span>"</span>: <span>"</span><span>location_select</span><span>"</span><span>, </span><span>"</span><span>key</span><span>"</span>: <span>"</span><span>rselfmenu_2_0</span><span>"</span><span> } ] }</span>
参数说明
参数 | 是否必须 | 说明 |
---|---|---|
button | 是 | 一级菜单数组,个数应为1~3个 |
sub_button | 否 | 二级菜单数组,个数应为1~5个 |
type | 是 | 菜单的响应动作类型 |
name | 是 | 菜单标题,不超过16个字节,子菜单不超过40个字节 |
key | click等点击类型必须 | 菜单KEY值,用于消息接口推送,不超过128字节 |
url | view类型必须 | 网页链接,用户点击菜单可打开链接,不超过256字节 |
菜单具体的生成方法,与之前是一样的,先生成access token,再将菜单post内容提交给微信服务器,具体代码及方法可以参考 微信公众平台开发(58)自定义菜单。
生成后的效果如下如示:
响应菜单点击,则需要在接口文件中添加新的EventKey事件的响应,并回复相应的内容。
相关代码如下
<span> 1</span> <span>//</span><span>接收事件消息</span> <span> 2</span> <span>private</span> <span>function</span> receiveEvent(<span>$object</span><span>) </span><span> 3</span> <span> { </span><span> 4</span> <span>$content</span> = ""<span>; </span><span> 5</span> <span>switch</span> (<span>$object</span>-><span>Event) </span><span> 6</span> <span> { </span><span> 7</span> <span>case</span> "subscribe": <span> 8</span> <span>$content</span> = "欢迎关注方倍工作室 "<span>; </span><span> 9</span> <span>$content</span> .= (!<span>empty</span>(<span>$object</span>->EventKey))?("\n来自二维码场景 ".<span>str_replace</span>("qrscene_","",<span>$object</span>->EventKey)):""<span>; </span><span>10</span> <span>break</span><span>; </span><span>11</span> <span>case</span> "unsubscribe": <span>12</span> <span>$content</span> = "取消关注"<span>; </span><span>13</span> <span>break</span><span>; </span><span>14</span> <span>case</span> "CLICK": <span>15</span> <span>switch</span> (<span>$object</span>-><span>EventKey) </span><span>16</span> <span> { </span><span>17</span> <span>case</span> "COMPANY": <span>18</span> <span>$content</span> = <span>array</span><span>(); </span><span>19</span> <span>$content</span>[] = <span>array</span>("Title"=>"方倍工作室", "Description"=>"", "PicUrl"=>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958"<span>); </span><span>20</span> <span>break</span><span>; </span><span>21</span> <span>default</span>: <span>22</span> <span>$content</span> = "点击菜单:".<span>$object</span>-><span>EventKey; </span><span>23</span> <span>break</span><span>; </span><span>24</span> <span> } </span><span>25</span> <span>break</span><span>; </span><span>26</span> <span>case</span> "VIEW": <span>27</span> <span>$content</span> = "跳转链接 ".<span>$object</span>-><span>EventKey; </span><span>28</span> <span>break</span><span>; </span><span>29</span> <span>case</span> "SCAN": <span>30</span> <span>$content</span> = "扫描场景 ".<span>$object</span>-><span>EventKey; </span><span>31</span> <span>break</span><span>; </span><span>32</span> <span>case</span> "LOCATION": <span>33</span> <span>$content</span> = "上传位置:纬度 ".<span>$object</span>->Latitude.";经度 ".<span>$object</span>-><span>Longitude; </span><span>34</span> <span>break</span><span>; </span><span>35</span> <span>case</span> "scancode_waitmsg": <span>36</span> <span>$content</span> = "扫码带提示:类型 ".<span>$object</span>->ScanCodeInfo->ScanType." 结果:".<span>$object</span>->ScanCodeInfo-><span>ScanResult; </span><span>37</span> <span>break</span><span>; </span><span>38</span> <span>case</span> "scancode_push": <span>39</span> <span>$content</span> = "扫码推事件"<span>; </span><span>40</span> <span>break</span><span>; </span><span>41</span> <span>case</span> "pic_sysphoto": <span>42</span> <span>$content</span> = "系统拍照"<span>; </span><span>43</span> <span>break</span><span>; </span><span>44</span> <span>case</span> "pic_weixin": <span>45</span> <span>$content</span> = "相册发图:数量 ".<span>$object</span>->SendPicsInfo-><span>Count</span><span>; </span><span>46</span> <span>break</span><span>; </span><span>47</span> <span>case</span> "pic_photo_or_album": <span>48</span> <span>$content</span> = "拍照或者相册:数量 ".<span>$object</span>->SendPicsInfo-><span>Count</span><span>; </span><span>49</span> <span>break</span><span>; </span><span>50</span> <span>case</span> "location_select": <span>51</span> <span>$content</span> = "发送位置:标签 ".<span>$object</span>->SendLocationInfo-><span>Label; </span><span>52</span> <span>break</span><span>; </span><span>53</span> <span>default</span>: <span>54</span> <span>$content</span> = "receive a new event: ".<span>$object</span>->Event." \n技术支持 方倍工作室"<span>; </span><span>55</span> <span>break</span><span>; </span><span>56</span> <span> } </span><span>57</span> <span>58</span> <span>if</span>(<span>is_array</span>(<span>$content</span><span>)){ </span><span>59</span> <span>if</span> (<span>isset</span>(<span>$content</span>[0]['PicUrl'<span>])){ </span><span>60</span> <span>$result</span> = <span>$this</span>->transmitNews(<span>$object</span>, <span>$content</span><span>); </span><span>61</span> }<span>else</span> <span>if</span> (<span>isset</span>(<span>$content</span>['MusicUrl'<span>])){ </span><span>62</span> <span>$result</span> = <span>$this</span>->transmitMusic(<span>$object</span>, <span>$content</span><span>); </span><span>63</span> <span> } </span><span>64</span> }<span>else</span><span>{ </span><span>65</span> <span>$result</span> = <span>$this</span>->transmitText(<span>$object</span>, <span>$content</span><span>); </span><span>66</span> <span> } </span><span>67</span> <span>return</span> <span>$result</span><span>; </span><span>68</span> }
各项类型推送给后台的xml详解如下
scancode_waitmsg,回应该事件给用户,用户可收到消息
<span><</span><span>xml</span><span>></span> <span><</span><span>ToUserName</span><span>></span><span><![CDATA[</span><span>gh_82479813ed64</span><span>]]></span><span></</span><span>ToUserName</span><span>></span> <span><</span><span>FromUserName</span><span>></span><span><![CDATA[</span><span>ojpX_jig-gyi3_Q9fHXQ4rdHniQs</span><span>]]></span><span></</span><span>FromUserName</span><span>></span> <span><</span><span>CreateTime</span><span>></span>1412075435<span></</span><span>CreateTime</span><span>></span> <span><</span><span>MsgType</span><span>></span><span><![CDATA[</span><span>event</span><span>]]></span><span></</span><span>MsgType</span><span>></span> <span><</span><span>Event</span><span>></span><span><![CDATA[</span><span>scancode_waitmsg</span><span>]]></span><span></</span><span>Event</span><span>></span> <span><</span><span>EventKey</span><span>></span><span><![CDATA[</span><span>rselfmenu_0_0</span><span>]]></span><span></</span><span>EventKey</span><span>></span> <span><</span><span>ScanCodeInfo</span><span>></span> <span><</span><span>ScanType</span><span>></span><span><![CDATA[</span><span>qrcode</span><span>]]></span><span></</span><span>ScanType</span><span>></span> <span><</span><span>ScanResult</span><span>></span><span><![CDATA[</span><span>http://weixin.qq.com/r/pUNnf4HEX9wgrcUc9xa3</span><span>]]></span><span></</span><span>ScanResult</span><span>></span> <span><</span><span>EventKey</span><span>></span><span><![CDATA[</span><span>rselfmenu_0_0</span><span>]]></span><span></</span><span>EventKey</span><span>></span> <span></</span><span>ScanCodeInfo</span><span>></span> <span></</span><span>xml</span><span>></span>
scancode_push,回应该事件给用户,用户不能收到消息
<span><</span><span>xml</span><span>></span> <span><</span><span>ToUserName</span><span>></span><span><![CDATA[</span><span>gh_82479813ed64</span><span>]]></span><span></</span><span>ToUserName</span><span>></span> <span><</span><span>FromUserName</span><span>></span><span><![CDATA[</span><span>ojpX_jig-gyi3_Q9fHXQ4rdHniQs</span><span>]]></span><span></</span><span>FromUserName</span><span>></span> <span><</span><span>CreateTime</span><span>></span>1412075451<span></</span><span>CreateTime</span><span>></span> <span><</span><span>MsgType</span><span>></span><span><![CDATA[</span><span>event</span><span>]]></span><span></</span><span>MsgType</span><span>></span> <span><</span><span>Event</span><span>></span><span><![CDATA[</span><span>scancode_push</span><span>]]></span><span></</span><span>Event</span><span>></span> <span><</span><span>EventKey</span><span>></span><span><![CDATA[</span><span>rselfmenu_0_1</span><span>]]></span><span></</span><span>EventKey</span><span>></span> <span><</span><span>ScanCodeInfo</span><span>></span> <span><</span><span>ScanType</span><span>></span><span><![CDATA[</span><span>qrcode</span><span>]]></span><span></</span><span>ScanType</span><span>></span> <span><</span><span>ScanResult</span><span>></span><span><![CDATA[</span><span>http://weixin.qq.com/r/pUNnf4HEX9wgrcUc9xa3</span><span>]]></span><span></</span><span>ScanResult</span><span>></span> <span><</span><span>EventKey</span><span>></span><span><![CDATA[</span><span>rselfmenu_0_1</span><span>]]></span><span></</span><span>EventKey</span><span>></span> <span></</span><span>ScanCodeInfo</span><span>></span> <span></</span><span>xml</span><span>></span>
pic_weixin ,下面是一次推送3张相片时的数据
<span><</span><span>xml</span><span>></span> <span><</span><span>ToUserName</span><span>></span><span><![CDATA[</span><span>gh_82479813ed64</span><span>]]></span><span></</span><span>ToUserName</span><span>></span> <span><</span><span>FromUserName</span><span>></span><span><![CDATA[</span><span>ojpX_jig-gyi3_Q9fHXQ4rdHniQs</span><span>]]></span><span></</span><span>FromUserName</span><span>></span> <span><</span><span>CreateTime</span><span>></span>1412075552<span></</span><span>CreateTime</span><span>></span> <span><</span><span>MsgType</span><span>></span><span><![CDATA[</span><span>event</span><span>]]></span><span></</span><span>MsgType</span><span>></span> <span><</span><span>Event</span><span>></span><span><![CDATA[</span><span>pic_weixin</span><span>]]></span><span></</span><span>Event</span><span>></span> <span><</span><span>EventKey</span><span>></span><span><![CDATA[</span><span>rselfmenu_1_2</span><span>]]></span><span></</span><span>EventKey</span><span>></span> <span><</span><span>SendPicsInfo</span><span>></span> <span><</span><span>Count</span><span>></span>3<span></</span><span>Count</span><span>></span> <span><</span><span>PicList</span><span>></span> <span><</span><span>item</span><span>></span> <span><</span><span>PicMd5Sum</span><span>></span><span><![CDATA[</span><span>a6ab74b73a298f49f6fc66f41f88d3c7</span><span>]]></span><span></</span><span>PicMd5Sum</span><span>></span> <span></</span><span>item</span><span>></span> <span><</span><span>item</span><span>></span> <span><</span><span>PicMd5Sum</span><span>></span><span><![CDATA[</span><span>5b9aea2b3683c5c21aaf3629739cafd9</span><span>]]></span><span></</span><span>PicMd5Sum</span><span>></span> <span></</span><span>item</span><span>></span> <span><</span><span>item</span><span>></span> <span><</span><span>PicMd5Sum</span><span>></span><span><![CDATA[</span><span>2325ff3f39705ac987d3e0660906791d</span><span>]]></span><span></</span><span>PicMd5Sum</span><span>></span> <span></</span><span>item</span><span>></span> <span></</span><span>PicList</span><span>></span> <span><</span><span>EventKey</span><span>></span><span><![CDATA[</span><span>rselfmenu_1_2</span><span>]]></span><span></</span><span>EventKey</span><span>></span> <span></</span><span>SendPicsInfo</span><span>></span> <span></</span><span>xml</span><span>></span>
回应上述消息,用户收不到,但微信会继续推送3个图片消息给接口
<span><</span><span>xml</span><span>></span> <span><</span><span>ToUserName</span><span>></span><span><![CDATA[</span><span>gh_82479813ed64</span><span>]]></span><span></</span><span>ToUserName</span><span>></span> <span><</span><span>FromUserName</span><span>></span><span><![CDATA[</span><span>ojpX_jig-gyi3_Q9fHXQ4rdHniQs</span><span>]]></span><span></</span><span>FromUserName</span><span>></span> <span><</span><span>CreateTime</span><span>></span>1412075562<span></</span><span>CreateTime</span><span>></span> <span><</span><span>MsgType</span><span>></span><span><![CDATA[</span><span>image</span><span>]]></span><span></</span><span>MsgType</span><span>></span> <span><</span><span>PicUrl</span><span>></span><span><![CDATA[</span><span>http://mmbiz.qpic.cn/mmbiz/qOTIrRtMKFxZQo3cQ6vYxmfteo0fw2Y00MuuFS6OjlNvTkx0nBQJibjjafQMf4dCtJwyMeP5e3SQCuJpcoJdb8Q/0</span><span>]]></span><span></</span><span>PicUrl</span><span>></span> <span><</span><span>MsgId</span><span>></span>6064818358471506877<span></</span><span>MsgId</span><span>></span> <span><</span><span>MediaId</span><span>></span><span><![CDATA[</span><span>AM8Gbiu7S2vTIMS2l9zNCWiMCpeM8wccmKdFxmstHiuAybCbB-08dTQJN40cCIBD</span><span>]]></span><span></</span><span>MediaId</span><span>></span> <span></</span><span>xml</span><span>></span>
<span><</span><span>xml</span><span>></span> <span><</span><span>ToUserName</span><span>></span><span><![CDATA[</span><span>gh_82479813ed64</span><span>]]></span><span></</span><span>ToUserName</span><span>></span> <span><</span><span>FromUserName</span><span>></span><span><![CDATA[</span><span>ojpX_jig-gyi3_Q9fHXQ4rdHniQs</span><span>]]></span><span></</span><span>FromUserName</span><span>></span> <span><</span><span>CreateTime</span><span>></span>1412075564<span></</span><span>CreateTime</span><span>></span> <span><</span><span>MsgType</span><span>></span><span><![CDATA[</span><span>image</span><span>]]></span><span></</span><span>MsgType</span><span>></span> <span><</span><span>PicUrl</span><span>></span><span><![CDATA[</span><span>http://mmbiz.qpic.cn/mmbiz/qOTIrRtMKFxZQo3cQ6vYxmfteo0fw2Y0ellMniarWto4zL0pWKhr6a0FSARDeXprSgd0JmgU0YQo2iagGsYc1iaLA/0</span><span>]]></span><span></</span><span>PicUrl</span><span>></span> <span><</span><span>MsgId</span><span>></span>6064818367061441471<span></</span><span>MsgId</span><span>></span> <span><</span><span>MediaId</span><span>></span><span><![CDATA[</span><span>2CJKZ2mft-5hWEkVcVmnKwyvp3y59Uzv7YdpBsnGIyTlkMNb0ytU4oimTgimBGyP</span><span>]]></span><span></</span><span>MediaId</span><span>></span> <span></</span><span>xml</span><span>></span>
<span><</span><span>xml</span><span>></span> <span><</span><span>ToUserName</span><span>></span><span><![CDATA[</span><span>gh_82479813ed64</span><span>]]></span><span></</span><span>ToUserName</span><span>></span> <span><</span><span>FromUserName</span><span>></span><span><![CDATA[</span><span>ojpX_jig-gyi3_Q9fHXQ4rdHniQs</span><span>]]></span><span></</span><span>FromUserName</span><span>></span> <span><</span><span>CreateTime</span><span>></span>1412075567<span></</span><span>CreateTime</span><span>></span> <span><</span><span>MsgType</span><span>></span><span><![CDATA[</span><span>image</span><span>]]></span><span></</span><span>MsgType</span><span>></span> <span><</span><span>PicUrl</span><span>></span><span><![CDATA[</span><span>http://mmbiz.qpic.cn/mmbiz/qOTIrRtMKFxZQo3cQ6vYxmfteo0fw2Y0mwQoENttnmYAz0VTicY3xkO0lhn9mE5r3FB4cF04kia50riajcjY1qvzA/0</span><span>]]></span><span></</span><span>PicUrl</span><span>></span> <span><</span><span>MsgId</span><span>></span>6064818379946343361<span></</span><span>MsgId</span><span>></span> <span><</span><span>MediaId</span><span>></span><span><![CDATA[</span><span>VICm1-y8w_MmdpcLYWP0u12HVXrWdhm3c3tdq1PTsbiFFgH6YOcmmIEbZ27z-Qcl</span><span>]]></span><span></</span><span>MediaId</span><span>></span> <span></</span><span>xml</span><span>></span>
上述多个图片消息,后台收到都能进行单独回应,用户可以收到响应消息。
pic_photo_or_album,方式和pic_weixin 一样,先推送菜单事件,再推送图片消息
<span><</span><span>xml</span><span>></span> <span><</span><span>ToUserName</span><span>></span><span><![CDATA[</span><span>gh_82479813ed64</span><span>]]></span><span></</span><span>ToUserName</span><span>></span> <span><</span><span>FromUserName</span><span>></span><span><![CDATA[</span><span>ojpX_jig-gyi3_Q9fHXQ4rdHniQs</span><span>]]></span><span></</span><span>FromUserName</span><span>></span> <span><</span><span>CreateTime</span><span>></span>1412075614<span></</span><span>CreateTime</span><span>></span> <span><</span><span>MsgType</span><span>></span><span><![CDATA[</span><span>event</span><span>]]></span><span></</span><span>MsgType</span><span>></span> <span><</span><span>Event</span><span>></span><span><![CDATA[</span><span>pic_photo_or_album</span><span>]]></span><span></</span><span>Event</span><span>></span> <span><</span><span>EventKey</span><span>></span><span><![CDATA[</span><span>rselfmenu_1_1</span><span>]]></span><span></</span><span>EventKey</span><span>></span> <span><</span><span>SendPicsInfo</span><span>></span> <span><</span><span>Count</span><span>></span>1<span></</span><span>Count</span><span>></span> <span><</span><span>PicList</span><span>></span> <span><</span><span>item</span><span>></span> <span><</span><span>PicMd5Sum</span><span>></span><span><![CDATA[</span><span>58f4989164b2a432889e64fa81632152</span><span>]]></span><span></</span><span>PicMd5Sum</span><span>></span> <span></</span><span>item</span><span>></span> <span></</span><span>PicList</span><span>></span> <span><</span><span>EventKey</span><span>></span><span><![CDATA[</span><span>rselfmenu_1_1</span><span>]]></span><span></</span><span>EventKey</span><span>></span> <span></</span><span>SendPicsInfo</span><span>></span> <span></</span><span>xml</span><span>></span>
<span><</span><span>xml</span><span>></span> <span><</span><span>ToUserName</span><span>></span><span><![CDATA[</span><span>gh_82479813ed64</span><span>]]></span><span></</span><span>ToUserName</span><span>></span> <span><</span><span>FromUserName</span><span>></span><span><![CDATA[</span><span>ojpX_jig-gyi3_Q9fHXQ4rdHniQs</span><span>]]></span><span></</span><span>FromUserName</span><span>></span> <span><</span><span>CreateTime</span><span>></span>1412075618<span></</span><span>CreateTime</span><span>></span> <span><</span><span>MsgType</span><span>></span><span><![CDATA[</span><span>image</span><span>]]></span><span></</span><span>MsgType</span><span>></span> <span><</span><span>PicUrl</span><span>></span><span><![CDATA[</span><span>http://mmbiz.qpic.cn/mmbiz/qOTIrRtMKFxZQo3cQ6vYxmfteo0fw2Y0fwSdF54rribCj9zqDG0wVDsiasKuUC8gskbuZmX43a1hs9esySIvmrqA/0</span><span>]]></span><span></</span><span>PicUrl</span><span>></span> <span><</span><span>MsgId</span><span>></span>6064818598989675467<span></</span><span>MsgId</span><span>></span> <span><</span><span>MediaId</span><span>></span><span><![CDATA[</span><span>Jh7Bsjaodmz-Dc_Hdz_wRzY3RiFxNvA4JHpUWRNRCIgps19ANsDFIOYOUV1dIVYV</span><span>]]></span><span></</span><span>MediaId</span><span>></span> <span></</span><span>xml</span><span>></span>
pic_sysphoto 这个后台其实收不到该菜单的消息,点击它后,调用的是手机里面的照相机功能,而照相以后再发过来时,就收到的是一个图片消息了
<span><</span><span>xml</span><span>></span> <span><</span><span>ToUserName</span><span>></span><span><![CDATA[</span><span>gh_82479813ed64</span><span>]]></span><span></</span><span>ToUserName</span><span>></span> <span><</span><span>FromUserName</span><span>></span><span><![CDATA[</span><span>ojpX_jig-gyi3_Q9fHXQ4rdHniQs</span><span>]]></span><span></</span><span>FromUserName</span><span>></span> <span><</span><span>CreateTime</span><span>></span>1412135923<span></</span><span>CreateTime</span><span>></span> <span><</span><span>MsgType</span><span>></span><span><![CDATA[</span><span>image</span><span>]]></span><span></</span><span>MsgType</span><span>></span> <span><</span><span>PicUrl</span><span>></span><span><![CDATA[</span><span>http://mmbiz.qpic.cn/mmbiz/qOTIrRtMKFxGzYCchrNiczZ9aCd1fgCEWbicHGvmaz1d7VZOSMqoLB4RL69rK2Fos6fSM4FJRkLtiajpe32ibkicw1A/0</span><span>]]></span><span></</span><span>PicUrl</span><span>></span> <span><</span><span>MsgId</span><span>></span>6065077606992462276<span></</span><span>MsgId</span><span>></span> <span><</span><span>MediaId</span><span>></span><span><![CDATA[</span><span>PqRRUPLhMc27EG5F4cCtTozBsin7SY8kPRRuAF-CwPl5MzR5ewE5oji0FhGTDl6_</span><span>]]></span><span></</span><span>MediaId</span><span>></span> <span></</span><span>xml</span><span>></span>
location_select 将会调起发送位置功能,菜单的响应用户收不到,在用户发送位置之后,会再推送一个地理位置消息功能给用户
<span><</span><span>xml</span><span>></span> <span><</span><span>ToUserName</span><span>></span><span><![CDATA[</span><span>gh_82479813ed64</span><span>]]></span><span></</span><span>ToUserName</span><span>></span> <span><</span><span>FromUserName</span><span>></span><span><![CDATA[</span><span>ojpX_jig-gyi3_Q9fHXQ4rdHniQs</span><span>]]></span><span></</span><span>FromUserName</span><span>></span> <span><</span><span>CreateTime</span><span>></span>1412075681<span></</span><span>CreateTime</span><span>></span> <span><</span><span>MsgType</span><span>></span><span><![CDATA[</span><span>event</span><span>]]></span><span></</span><span>MsgType</span><span>></span> <span><</span><span>Event</span><span>></span><span><![CDATA[</span><span>location_select</span><span>]]></span><span></</span><span>Event</span><span>></span> <span><</span><span>EventKey</span><span>></span><span><![CDATA[</span><span>rselfmenu_2_0</span><span>]]></span><span></</span><span>EventKey</span><span>></span> <span><</span><span>SendLocationInfo</span><span>></span> <span><</span><span>Location_X</span><span>></span><span><![CDATA[</span><span>22.538145</span><span>]]></span><span></</span><span>Location_X</span><span>></span> <span><</span><span>Location_Y</span><span>></span><span><![CDATA[</span><span>113.952298</span><span>]]></span><span></</span><span>Location_Y</span><span>></span> <span><</span><span>Scale</span><span>></span><span><![CDATA[</span><span>13</span><span>]]></span><span></</span><span>Scale</span><span>></span> <span><</span><span>Label</span><span>></span><span><![CDATA[</span><span>深圳市南山区高新南一道9号</span><span>]]></span><span></</span><span>Label</span><span>></span> <span><</span><span>Poiname</span><span>></span><span><![CDATA[]]></span><span></</span><span>Poiname</span><span>></span> <span><</span><span>EventKey</span><span>></span><span><![CDATA[</span><span>rselfmenu_2_0</span><span>]]></span><span></</span><span>EventKey</span><span>></span> <span></</span><span>SendLocationInfo</span><span>></span> <span></</span><span>xml</span><span>></span>
<span><</span><span>xml</span><span>></span> <span><</span><span>ToUserName</span><span>></span><span><![CDATA[</span><span>gh_82479813ed64</span><span>]]></span><span></</span><span>ToUserName</span><span>></span> <span><</span><span>FromUserName</span><span>></span><span><![CDATA[</span><span>ojpX_jig-gyi3_Q9fHXQ4rdHniQs</span><span>]]></span><span></</span><span>FromUserName</span><span>></span> <span><</span><span>CreateTime</span><span>></span>1412075681<span></</span><span>CreateTime</span><span>></span> <span><</span><span>MsgType</span><span>></span><span><![CDATA[</span><span>location</span><span>]]></span><span></</span><span>MsgType</span><span>></span> <span><</span><span>Location_X</span><span>></span>22.538145<span></</span><span>Location_X</span><span>></span> <span><</span><span>Location_Y</span><span>></span>113.952298<span></</span><span>Location_Y</span><span>></span> <span><</span><span>Scale</span><span>></span>13<span></</span><span>Scale</span><span>></span> <span><</span><span>Label</span><span>></span><span><![CDATA[</span><span>深圳市南山区高新南一道9号飞亚达科技大厦方倍工作室</span><span>]]></span><span></</span><span>Label</span><span>></span> <span><</span><span>MsgId</span><span>></span>6064818869572615123<span></</span><span>MsgId</span><span>></span> <span></</span><span>xml</span><span>></span>
4.1 产品二维码检测真伪
使用scancode_waitmsg事件,可以获得扫描结果,再与现有结果进行比对,从而可以达到检测二维码真实性的功能。
一个检测代码如下所示:
<span>1</span> <span>case</span> "scancode_waitmsg": <span>2</span> <span>if</span> (<span>$object</span>->ScanCodeInfo->ScanResult == "http://mm.wanggou.com/item/jd2.shtml?sku=11447844"<span>){ </span><span>3</span> <span>$content</span> = <span>array</span><span>(); </span><span>4</span> <span>$content</span>[] = <span>array</span>("Title"=>"该产品检测结果为正品", "Description"=>"书名:微信公众平台开发最佳实践\n定价:¥69.00\n作者:方倍工作室\n\n点击“查看全文”,使用微信支付在线购买", "PicUrl"=>"http://images.cnitblog.com/i/340216/201404/301756448922305.jpg", "Url" =>"http://mm.wanggou.com/item/jd2.shtml?sku=11447844"<span>); </span><span>5</span> }<span>else</span><span>{ </span><span>6</span> <span>$content</span> = "扫码带提示:类型 ".<span>$object</span>->ScanCodeInfo->ScanType." 结果:".<span>$object</span>->ScanCodeInfo-><span>ScanResult; </span><span>7</span> <span> } </span><span>8</span> <span>break</span>;
当用户使用scancode_waitmsg菜单扫描以下二维码时,将出现检测结果,结果为真时,还可以再进一步,让用户进入购买
4.2 快递进度查询
基于上面同样的原理,可以实现扫描快递条形码,就查询快递进度的功能。
一个快递的单号如下
扫描以后,返回结果为
扫码带提示:类型 qrcode/CODE_39 结果:762480955342
正确识别了其中的快递单号
4.3 导航/附近/地图
location_select事件比之前的直接发送地理位置消息更少了一步,比如下面的
微信推出自定义菜单,让很多人大抱期望,但我认为这不是公众账号必要具备的,现在形式大于实用,大部分用户其实已经习惯了通过输入来获取内容,实在没有必要太执着于自定义菜单的使用,服务好才是根本。 最近微信悄悄推出了自定义菜单内测,又一次吸引了无数人的眼球,不管是谁19号这天都在干那么几件事,一是填写表格申请内测,二是研究自定义菜单接口文档,三是写自定义菜单的各种分析文章,四是托各种关系想早点拿到内测资格。 Ztalk也不能免俗的拿了公司资料去申请,但因为是自媒体估计是拿不到的,会有点失望,但静下心
...展开
微信推出自定义菜单,让很多人大抱期望,但我认为这不是公众账号必要具备的,现在形式大于实用,大部分用户其实已经习惯了通过输入来获取内容,实在没有必要太执着于自定义菜单的使用,服务好才是根本。 最近微信悄悄推出了自定义菜单内测,又一次吸引了无数人的眼球,不管是谁19号这天都在干那么几件事,一是填写表格申请内测,二是研究自定义菜单接口文档,三是写自定义菜单的各种分析文章,四是托各种关系想早点拿到内测资格。 Ztalk也不能免俗的拿了公司资料去申请,但因为是自媒体估计是拿不到的,会有点失望,但静下心来想清楚就不郁闷了。其实就算拿到了这个接口又如何,公众账号真的很需要自定义菜单吗?自定义菜单到底是个什么?朋友们订阅“ZTalk”的本质到底是什么? 自定义菜单到底是什么? 大部分人对自定义菜单抱着很大的期望,觉得只要是官方推出来的新东西肯定就是强大的营销神器,但实际上它只是一个聚焦功能的快捷键而已,并不是所有人都需要。 记得有篇文章曾经提过,微信公众账号的用户服务获取路径太长,用户得先找到公众账号进入,然后点击某篇文章或者通过查询获得文章后点击,进入微信的文章模板,再点击阅读原文才能最终到达服务,也就是用户可能要经过三到四步甚至更多才有可能得到想要的。那么有了自定义菜单当然可以缩短这个流程,对于一些企业来说可以把需要突出展示的内容直接放到在菜单上。 比如一个电商卖家,可以设置一个菜单栏放置新品上市,再设置一个菜单栏放置团购优惠,用户点击后直接进入购买页面,还可以设置一个菜单栏放置产品类目直达每个商品分类。 比如一个连锁酒店,可以设置一个菜单放置最新优惠活动,再设置一个菜单放置酒店介绍房间展示,再设置一个菜单栏用作地理位置发送,查询附近酒店。 比如一个百货商店,可以设置一个菜单放最新打折促销,再设置一个菜单放置楼层柜台商品介绍,再设置一个菜单用作店址、电话等信息服务和会员服务。 自定义菜单主要作用是让用户降低信息获取的学习成本,让企业的公众账号表现的更加直观,信息传递更加简便,事实上有了这个菜单你就可以把微信公众账号当做一个网站来看待,用户可以像浏览网页一样的使用。 自定义菜单不是公众账号的必备功能 首先,没这个自定义菜单以前,公众账号已经能够很好的完成这些功能。通过设计一个友好清晰带有引导交互的欢迎词和使用帮助,利用关键字回复把相对应的内容以文字或者多图文形式展现给用户,现在有了自定义菜单无非是把关注欢迎词里那一堆交互引导给替代了,当然未来自定义菜单会有新的接口,但就目前来说仅仅是链接指向用处不大,当然对于游戏或者电商类的H5页面会用处很大。 其次自定义菜单会覆盖公众账号的输入框,当用户需要通过输入文字或者语音进行交互时,还要点击按钮进行切换,反而会多了一步,因此对于一些重点在内容浏览信息查询的公众账号自定义菜单有用,而重点在用户互动和服务的公众账号还不如不要。 最后自定义菜单目前需要通过接口开发才能使用,本来这个菜单会做成后台......余下全文>>
从目前的情况来看,服务号和订阅号在认证之后都可以申请自己的自定义菜单,不过有些高级的开发功能只能在服务号上体现出来,订阅号目前还不能实现。