微信开发第四篇:自定义菜单

官方文档:
https://mp.weixin.qq.com/wiki/10/0234e39a2025342c17a7d23595c6b40a.html

Select Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//通过浏览器访问这个方法,来生成菜单
public function makeMenu()
{  
    $url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$this->getAccessToken();
    $data = '{
         "button":[
         {  
              "type":"click",
              "name":"今日歌曲",
              "key":"V1001_TODAY_MUSIC"
          },
          {
               "name":"菜单",
               "sub_button":[
               {    
                   "type":"view",
                   "name":"搜索",
                   "url":"http://www.soso.com/"
                },
                {
                   "type":"view",
                   "name":"博客",
                   "url":"http://www.webjust.org"
                },
                {
                   "type":"click",
                   "name":"赞一下我们",
                   "key":"V1001_GOOD"
                }]
           }]
     }';

    $res = $this->curlHttp($url, $data);
    dump($res);
}

最终效果:
微信自定菜单

curlHttp的函数封装见另外一篇文章:curlHttp

获取Token:微信开发第三篇:获取access token

源码:https://github.com/webjust/wechat_beiginner