继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

二十八章 创建微信自定义菜单

手记佰篇
关注TA
已关注
手记 60
粉丝 58
获赞 272

闲话少说,直接上代码
<?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();

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP