<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(biāo)題文檔</title>
</head>
<?php
// 替換為你自己的AppID和AppSecret
$appId = 'wxd95fca43ae595a61';
$appSecret = '872a95a04a7e1bd78e3f01020ac195f1';
// 獲取Access Token
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$appSecret}";
$response = file_get_contents($url);
$result = json_decode($response, true);
$accessToken = $result['access_token'];
// 創(chuàng)建底部菜單欄的JSON結(jié)構(gòu)
$menu = array(
? ? 'button' => array(
? ? ? ? array(
? ? ? ? ? ? 'name' => '故障查詢',
? ? ? ? ? ? 'sub_button' => array(
? ? ? ? ? ? ? ? array(
? ? ? ? ? ? ? ? ? ? 'type' => 'view',
? ? ? ? ? ? ? ? ? ? 'name' => '安川',
? ? ? ? ? ? ? ? ? ? 'url' => 'https://www.example.com/submenu1',
? ? ? ? ? ? ? ? ),
? ? ? ? ? ? ? ? array(
? ? ? ? ? ? ? ? ? ? 'type' => 'click',
? ? ? ? ? ? ? ? ? ? 'name' => '發(fā)那科',
? ? ? ? ? ? ? ? ? ? 'url' => 'https://www.example.com/submenu1',
? ? ? ? ? ? ? ? ),
? ? ? ? ? ? ),
? ? ? ? ),
? ? ? ? array(
? ? ? ? ? ? 'name' => '故障查詢',
? ? ? ? ? ? 'sub_button' => array(
? ? ? ? ? ? ? ? array(
? ? ? ? ? ? ? ? ? ? 'type' => 'view',
? ? ? ? ? ? ? ? ? ? 'name' => '安川',
? ? ? ? ? ? ? ? ? ? 'url' => 'https://www.example.com/submenu1',
? ? ? ? ? ? ? ? ),
? ? ? ? ? ? ? ? array(
? ? ? ? ? ? ? ? ? ? 'type' => 'click',
? ? ? ? ? ? ? ? ? ? 'name' => '發(fā)那科',
? ? ? ? ? ? ? ? ? ? 'url' => 'https://www.example.com/submenu1',
? ? ? ? ? ? ? ? ),
? ? ? ? ? ? ),
? ? ? ? ),
? ? ? ? array(
? ? ? ? ? ? 'name' => '故障查詢',
? ? ? ? ? ? 'sub_button' => array(
? ? ? ? ? ? ? ? array(
? ? ? ? ? ? ? ? ? ? 'type' => 'view',
? ? ? ? ? ? ? ? ? ? 'name' => '安川',
? ? ? ? ? ? ? ? ? ? 'url' => 'https://www.example.com/submenu1',
? ? ? ? ? ? ? ? ),
? ? ? ? ? ? ? ? array(
? ? ? ? ? ? ? ? ? ? 'type' => 'click',
? ? ? ? ? ? ? ? ? ? 'name' => '發(fā)那科',
? ? ? ? ? ? ? ? ? ? 'url' => 'https://www.example.com/submenu1',
? ? ? ? ? ? ? ? ),
? ? ? ? ? ? ),
? ? ? ? ),
? ? ),
);
// 將菜單結(jié)構(gòu)轉(zhuǎn)換為JSON字符串并進(jìn)行URL編碼
$data = json_encode($menu, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$data = urlencode($data);
// 發(fā)送請(qǐng)求創(chuàng)建底部菜單欄
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$accessToken}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, urldecode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// 檢查請(qǐng)求返回結(jié)果
$result = json_decode($response, true);
if ($result['errcode'] == 0) {
? ? echo '創(chuàng)建底部菜單欄成功';
} else {
? ? echo '創(chuàng)建底部菜單欄失?。? . $result['errmsg'];
}
?>
以上代碼運(yùn)行后,顯示成功,但不能創(chuàng)建微信公眾號(hào)底部菜單欄