我這個自定義菜單為什么出不來,問題出在哪里?
<?php
//獲取access_token
$appid = "wxd1afb15b09cb207c";
$appsecret = "eb698c2649371785bf6905a981532439";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$jsoninfo = json_decode($output, true);
$access_token = $jsoninfo["access_token"];
//創建自定義菜單
$jsonmenu = '{
? ? ? "button":[
? ? ? {
? ? ? ? ? ?"name":"快遞寄件",
? ? ? ? ? ?"sub_button":[
? ? ? ? ? ? {
? ? ? ? ? ? ? ?"type":"view",
? ? ? ? ? ? ? ?"name":"打印快遞單",
? ? ? ? ? ? ? ?"url":"https://www.baidu.com"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? ?"type":"view",
? ? ? ? ? ? ? ?"name":"上門取件",
? ? ? ? ? ? ? ?"url":"http://m.hao123.com/a/tianqi"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? ?"type":"click",
? ? ? ? ? ? ? ?"name":"公司簡介",
? ? ? ? ? ? ? ?"key":"company"
? ? ? ? ? ? }]
? ? ? ?},
? ? ? ?{
? ? ? ? ? ?"name":"會員訂單",
? ? ? ? ? ?"sub_button":[
? ? ? ? ? ? {
? ? ? ? ? ? ? ?"type":"view",
? ? ? ? ? ? ? ?"name":"登錄/注冊",
? ? ? ? ? ? ? ?"url":"http://m.hao123.com/a/tianqi"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? ?"type":"view",
? ? ? ? ? ? ? ?"name":"我的訂單",
? ? ? ? ? ? ? ?"url":"http://m.hao123.com/a/tianqi"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? ?"type":"click",
? ? ? ? ? ? ? ?"name":"關于我們",
? ? ? ? ? ? ? ?"key":"游戲"
? ? ? ? ? ? }]
? ? ? ?},
? ? ? ?{
? ? ? ? ? ?"name":"用戶互動",
? ? ? ? ? ?"sub_button":[
? ? ? ? ? ? {
? ? ? ? ? ? ? ?"type":"view",
? ? ? ? ? ? ? ?"name":"粉絲社區",
? ? ? ? ? ? ? ?"url":"http://m.hao123.com/a/tianqi"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? ?"type":"view",
? ? ? ? ? ? ? ?"name":"歷史消息",
? ? ? ? ? ? ? ?"url":"http://m.hao123.com/a/tianqi"
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? ?"type":"view",
? ? ? ? ? ? ? ?"name":"意見反饋",
? ? ? ? ? ? ? ?"url":"http://m.hao123.com/a/tianqi"
? ? ? ? ? ? }]
? ? ? ?}]
}';
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
$result = https_request($url, $jsonmenu);
var_dump($result);
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);
? ? $output = curl_exec($curl);
? ? curl_close($curl);
? ? return $output;
}
?>
2016-12-28
url要用單引號~