概述
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);
//执行并获取HTML文档内容
$output = curl_exec($curl);
//释放curl句柄
curl_close($curl);
return $output;
}
//获取token
function get_token(){
$appid = "wxfd4478db3b0b2ca0";
$secret = "614a0092bc7e44642b7cd3108c1e0e89";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
$json = https_request($url);
$arr = json_decode($json, true);
return $arr['access_token'];
}
$jsonmenu = '
{
"button": [
{
"name": "扫码",
"sub_button": [
{
"type": "scancode_waitmsg",
"name": "扫码带提示",
"key": "rselfmenu_0_0",
"sub_button": [ ]
},
{
"type": "scancode_push",
"name": "扫码推事件",
"key": "rselfmenu_0_1",
"sub_button": [ ]
}
]
},
{
"name": "菜单",
"sub_button": [
{
"type": "view",
"name": "搜索",
"url": "http://www.soso.com/"
},
{
"type": "view",
"name": "视频",
"url": "http://v.qq.com/"
},
{
"type": "click",
"name": "随便回",
"key": "V1001_GOOD"
},
{
"type": "click",
"name": "每日歌曲",
"key": "V1001_TODAY_MUSIC"
}
]
}
]
}
';
$access_token = get_token();
$menuurl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$access_token}";
echo "sada";
$result = https_request($menuurl, $jsonmenu);
var_dump($result);
?>
最后
以上就是文艺小刺猬为你收集整理的php 微信开发 菜单,微信公众号开发实现菜单php代码的全部内容,希望文章能够帮你解决php 微信开发 菜单,微信公众号开发实现菜单php代码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复