首页
IT
登录
6mi
u
盘
搜
搜 索
IT
自定义菜单
自定义菜单
xiaoxiao
2021-03-25
110
<?php
/**
* Created by PhpStorm.
* User: machenike
* Date: 2017/3/10
* Time: 14:11
*/
header(
"content-type:text/html;charset=utf-8"
)
;
//定义全局变量 ACCESS_TOKEN
define(
"ACCESS_TOKEN"
,
"你获取的ACCESS_TOKEN"
)
;
//创建菜单
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": [
{
"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": "pic_sysphoto",
"name": "系统拍照发图",
"key": "rselfmenu_1_0",
"sub_button": [ ]
},
{
"type": "pic_photo_or_album",
"name": "拍照或者相册发图",
"key": "rselfmenu_1_1",
"sub_button": [ ]
},
{
"type": "pic_weixin",
"name": "微信相册发图",
"key": "rselfmenu_1_2",
"sub_button": [ ]
}
]
},
{
"name":"音乐",
"sub_button":[
{
"type":"view",
"name":"网易云音乐",
"url":"http://music.163.com/"
},
{
"type":"view",
"name":"酷狗音乐",
"url":"http://www.kugou.com/"
},
{
"type":"view",
"name":"虾米音乐",
"url":"http://www.xiami.com/"
},
{
"type":"view",
"name":"QQ音乐",
"url":"https://y.qq.com/"
},
{
"type":"view",
"name":"我的博客",
"url":"http://blog.csdn.net/lxcboke"
}]
}
]
}'
;
//创建自定义菜单
echo
createMenu
(
$data
)
;
//删除菜单
//echo deleteMenu();
//查询公众号菜单
//echo getMenu();
转载请注明原文地址: https://ju.6miu.com/read-21666.html
技术
最新回复
(
0
)