365体育备用网址报道5.2.3创建菜单_365体育备用网址官网资讯

创建菜单的接口如下所示:
https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
创建菜单时,需要将菜单内容组织成如下结构,以POST的方式向微信服务器提交。

{
    "button": [
        {
            "name": "扫码", 
            "sub_button": [
                {
                    "type": "scancode_waitmsg", 
                    "name": "扫码带提示", 
                    "key": "rselfmenu_0_0"
                }, 
                {
                    "type": "scancode_push", 
                    "name": "扫码推事情", 
                    "key": "rselfmenu_0_1"
                }
            ]
        }, 
        {
            "name": "发图", 
            "sub_button": [
                {
                    "type": "pic_sysphoto", 
                    "name": "系统拍照发图", 
                    "key": "rselfmenu_1_0"
                }, 
                {
                    "type": "pic_photo_or_album", 
                    "name": "拍照或者相册发图", 
                    "key": "rselfmenu_1_1"
                }, 
                {
                    "type": "pic_weixin", 
                    "name": "微信相册发图", 
                    "key": "rselfmenu_1_2"
                }
            ]
        }, 
        {
            "name": "其余", 
            "sub_button": [
                {
                    "name": "发送地位", 
                    "type": "location_select", 
                    "key": "rselfmenu_2_0"
                }, 
                {
                    "type": "click", 
                    "name": "今日歌曲", 
                    "key": "V1001_TODAY_MUSIC"
                }, 
                {
                    "type": "view", 
                    "name": "搜索", 
                    "url": "http://www.soso.com/"
                }
            ]
        }
    ]
}

自定义菜单内容的参数说明如表5-3所示:

表5-3自定义菜单参数说明

给微信公众账号创建自定义菜单的代码实现如下所示:

$jsonmenu = '{
    "button": [
        {
            "name": "扫码", 
            "sub_button": [
                {
                    "type": "scancode_waitmsg", 
                    "name": "扫码带提示", 
                    "key": "rselfmenu_0_0"
                }, 
                {
                    "type": "scancode_push", 
                    "name": "扫码推事情", 
                    "key": "rselfmenu_0_1"
                }
            ]
        }, 
        {
            "name": "发图", 
            "sub_button": [
                {
                    "type": "pic_sysphoto", 
                    "name": "系统拍照发图", 
                    "key": "rselfmenu_1_0"
                }, 
                {
                    "type": "pic_photo_or_album", 
                    "name": "拍照或者相册发图", 
                    "key": "rselfmenu_1_1"
                }, 
                {
                    "type": "pic_weixin", 
                    "name": "微信相册发图", 
                    "key": "rselfmenu_1_2"
                }
            ]
        }, 
        {
            "name": "其余", 
            "sub_button": [
                {
                    "name": "发送地位", 
                    "type": "location_select", 
                    "key": "rselfmenu_2_0"
                }, 
                {
                    "type": "click", 
                    "name": "今日歌曲", 
                    "key": "V1001_TODAY_MUSIC"
                }, 
                {
                    "type": "view", 
                    "name": "搜索", 
                    "url": "http://www.soso.com/"
                }
            ]
        }
    ]
}
';

$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
$result = https_request($url, $jsonmenu);
var_dump($result);

function https_request($url,$data = null)
{
$curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
    curl_close($curl);
return $output;
}

正确时的返回JSON数据包如下:
{"errcode":0,"errmsg":"ok"}

失误时的返回JSON数据包如下(示例为无效菜单名长度):
{"errcode":40018,"errmsg":"invalid button name size"}

errcode为全局返回码。

------分隔线----------------------------

公布评论 (67人察看0条评论)
请自觉遵守互联网相关的政策法规,严禁公布色情、暴力、反动的言论。
用户名: 验证码: 点击我更换99电玩手机版下载安装
最新评论