访问caidan方法生成菜单
public function access_token(){
$app = db('sxy_peizhi')->where('id',1)->find();
$appid = $app['appid'];
$secret = $app['appkey'];
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret;
$response = file_get_contents($url);
$json = json_decode($response, true);
return $json['access_token'];
}
//公众号自定义菜单创建
public function caidan()
{
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . $this->access_token();
$menu = [
'button' => [
[
'name' => '企业简介',
'sub_button' => [
[
'name' => '企业简介',
'type' => 'view',
'url' => 'https://mp.weixin.qq.com/s/fJzrdYwEeRXPav2sF_No2w'
],
[
'name' => '招商专区',
'type' => 'view',
'url' => 'https://mp.weixin.qq.com/s/jBPT7UIhYxGzltu7Ujgl_g'
],
[
'name' => '最新动态',
'type' => 'view',
'url' => 'http://mp.weixin.qq.com/mp/homepage?__biz=MzAxNzYwOTIwNA==&hid=7&sn=0cca9695a2a15047b05c8d92eb93e0ec&scene=18#wechat_redirect'
],
// 其他目的地二级菜单
]
],
[
'name' => '五大品牌',
'sub_button' => [
[
'name' => '魅芳华',
'type' => 'view',
'url' => 'http://mp.weixin.qq.com/mp/homepage?__biz=MzAxNzYwOTIwNA==&hid=13&sn=276d1633de585a8e4d9b24bf654168c9&scene=18#wechat_redirect'
],
[
'name' => '魅娇澜',
'type' => 'view',
'url' => 'http://mp.weixin.qq.com/mp/homepage?__biz=MzAxNzYwOTIwNA==&hid=14&sn=42a1289edecfe7b7f7cb32a4ef88e196&scene=18#wechat_redirect'
],
[
'name' => '魅诺诗',
'type' => 'view',
'url' => 'http://mp.weixin.qq.com/mp/homepage?__biz=MzAxNzYwOTIwNA==&hid=15&sn=b028923f9e9cb665491201936f80bffb&scene=18#wechat_redirect'
],
[
'name' => '魅无疆',
'type' => 'view',
'url' => 'http://mp.weixin.qq.com/mp/homepage?__biz=MzAxNzYwOTIwNA==&hid=16&sn=3010c97244da13de616fc3aee81726b7&scene=18#wechat_redirect'
],
[
'name' => '复大美诺',
'type' => 'view',
'url' => 'http://mp.weixin.qq.com/mp/homepage?__biz=MzAxNzYwOTIwNA==&hid=18&sn=0a351646e1055917a967537cd04e65ac&scene=18#wechat_redirect'
]
]
],
[
'name' => '五大品牌',
'sub_button' => [
[
'name' => '众欣美拼',
'type' => 'view',
'url' => 'http://mp.weixin.qq.com/mp/homepage?__biz=MzAxNzYwOTIwNA==&hid=9&sn=02360ec4350ba7746e7abe78a0190327&scene=18#wechat_redirect'
],
[
'name' => '美丽干货',
'type' => 'view',
'url' => 'http://mp.weixin.qq.com/mp/homepage?__biz=MzAxNzYwOTIwNA==&hid=10&sn=f76518dda6da0d26c8cb1086f5898adc&scene=18#wechat_redirect'
],
[
'name' => '人才培训',
'type' => 'view',
'url' => 'http://mp.weixin.qq.com/mp/homepage?__biz=MzAxNzYwOTIwNA==&hid=11&sn=19bb5cea6edd7e85b72ccac6d094a4ff&scene=18#wechat_redirect'
],
[
'name' => '招商帮扶',
'type' => 'view',
'url' => 'http://mp.weixin.qq.com/mp/homepage?__biz=MzAxNzYwOTIwNA==&hid=17&sn=376169e613ad16615097d755a66d6b05&scene=18#wechat_redirect'
],
[
'name' => '商学院',
'type' => 'view',
'url' => 'http://sxy.gzzhongxinguoji.com'
]
]
]
]
];
$options = [
'http' => [
'method' => 'POST',
'header' => 'Content-type: application/json',
'content' => json_encode($menu, JSON_UNESCAPED_UNICODE)
]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result) {
var_dump($result);
echo "菜单创建成功!";
} else {
echo "菜单创建失败!";
}
}