菜单创建的方法为POST
curl "https://m.api.weibo.com/2/messages/menu/create.json?access_token=ACCESS_TOKEN" -d 'menus={ }'
基本和微信类似,写的有点莫名其妙, access_token就是接口验证获得的。菜单也是两类,view和click
<?php
//创建菜单
$secret="*****";
$url = "https://m.api.weibo.com/2/messages/menu/create.json?access_token={$secret}";
$post='{
"button": [
{
"type": "view",
"name": "粉丝平台教程",
"url": "http://xx.html"
},
{
"type": "view",
"name": "百度",
"url": "http://www.baidu.cn"
},
{
"type": "click",
"name": "联系方式",
"key": "phone"
}
]
}';
$b="menus={$post}";
$ch = curl_init();//新建curl
curl_setopt($ch, CURLOPT_URL, $url);//url
curl_setopt($ch, CURLOPT_POST, 1); //post
curl_setopt($ch, CURLOPT_POSTFIELDS, $b);//post内容
curl_exec($ch); //输出
curl_close($ch);
?>
<?php
//删除菜单
$secret="*";
$url = "https://m.api.weibo.com/2/messages/menu/delete.json";
$ch = curl_init();//新建curl
$post="access_token={$secret}";
curl_setopt($ch, CURLOPT_URL, $url);//url
curl_setopt($ch, CURLOPT_POST, 1); //post
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);//post内容
curl_exec($ch); //输出
curl_close($ch);
?>
菜单click事件对于event和key,可使用$key=$postObj->data->key;读取