闲话少说,直接上代码
<?php
header("Content-type: text/html; charset=utf-8");
define("ACCESS_TOKEN", "W7TYEIh20uoHuxMgVWt0uela1P3_lSeu3LsTjMDKrdu_14733EGBG8uSQ6crttzj-QXp1vCe_qhZ9dt0jl0A7YDxy4z6zUcK8EhO3BZoZi0HVWhAAANBC");
//创建菜单
function createMenu($data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".ACCESS_TOKEN);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
return curl_error($ch);
}
curl_close($ch);
return $tmpInfo;
}
//获取菜单
function getMenu(){
return file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=".ACCESS_TOKEN);
}
//删除菜单
function deleteMenu(){
return file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=".ACCESS_TOKEN);
}
$data = '{
"button":[
{
"type":"click",
"name":"首页1",
"key":"home"
},
{
"type":"click",
"name":"简5",
"key":"introduct"
},
{
"name":"laoban",
"sub_button":[
{
"type":"view",
"name":"weixin",
"url":"https://mp.weixin.qq.com/"
},
{
"type":"view",
"name":"baidu",
"url":"http://www.baidu.com"
}]
}]
}';
echo createMenu($data);
//echo getMenu();
//echo deleteMenu();
共同学习,写下你的评论
评论加载中...
作者其他优质文章