首页 > 后端开发 > php教程 > 微信公众平台-自定义菜单-PHP示范

微信公众平台-自定义菜单-PHP示范

WBOY
发布: 2016-06-13 12:29:55
原创
1234 人浏览过

微信公众平台-自定义菜单-PHP示例

1、创建自定义菜单

<?php //创建菜单
$access_token = "";
$url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$access_token;
$body='
 {
     "button":[
     {	
          "type":"click",
          "name":"按钮1",
          "key":"button1"
      },
      {
           "type":"click",
           "name":"按钮2",
           "key":"button2"
      },
      {
           "name":"菜1单",
           "sub_button":[
           {	
               "type":"view",
               "name":"测试oauth",
               "url":"http://www.icity365.net/uc/fn_system.php"
            },
            {
               "type":"view",
               "name":"爱城市",
               "url":"http://www.icity365.com/"
            },
            {
               "type":"click",
               "name":"按钮3",
               "key":"button3"
            }]
       }]
 }';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, 1 );//设置post请求
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$res = curl_exec($ch);
echo ($res);
curl_close($ch);

?>
登录后复制

?

2、查询菜单

?

<?php //查询当前菜单
$access_token = "";
$url = 'https://api.weixin.qq.com/cgi-bin/menu/get?access_token='.$access_token;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$res = curl_exec($ch);
echo ($res);
curl_close($ch);

?>
登录后复制

?

?

3、删除菜单

<?php //删除自定义菜单
$access_token = "";
$url = 'https://api.weixin.qq.com/cgi-bin/menu/delete?access_token='.$access_token;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$res = curl_exec($ch);
echo ($res);
curl_close($ch);

?>
登录后复制

?

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板