JSON
{
"button": [
{
"name": "线路查询",
"type": "click",
"key": "线路查询"
},
{
"name": "热门推荐",
"type": "click",
"key": "热门推荐"
},
{
"name": "服务网点",
"sub_button": [
{
"type": "click",
"name": "扬州直营店",
"key": "扬州直营店"
},
{
"type": "click",
"name": "江都直营店",
"key": "江都直营店"
}
]
}
]
}PHP代码$url='http://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$json->access_token;
$ret=$this->api_notice_increment($url,$data);
$json=json_decode($ret);
dump($json->errcode);exit;function api_notice_increment($url, $data){
$ch = curl_init();//初始化curl
$header = "Accept-Charset: utf-8";
//$header = "Content-type: text/xml";//定义content-type为xml
curl_setopt($ch, CURLOPT_URL, $url);//设置链接
//curl_setopt($ch, CURLOPT_POST, 1);//设置为POST方式
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
//curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//设置HTTP头
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);//POST数据
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//设置是否返回信息 $tmpInfo = curl_exec($ch);
return $tmpInfo;
}以上代码总是返回45010,和上面测试成功的对比,应该没有问题。
{
"button": [
{
"name": "线路查询",
"type": "click",
"key": "线路查询"
},
{
"name": "热门推荐",
"type": "click",
"key": "热门推荐"
},
{
"name": "服务网点",
"sub_button": [
{
"type": "click",
"name": "扬州直营店",
"key": "扬州直营店"
},
{
"type": "click",
"name": "江都直营店",
"key": "江都直营店"
}
]
}
]
}PHP代码$url='http://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$json->access_token;
$ret=$this->api_notice_increment($url,$data);
$json=json_decode($ret);
dump($json->errcode);exit;function api_notice_increment($url, $data){
$ch = curl_init();//初始化curl
$header = "Accept-Charset: utf-8";
//$header = "Content-type: text/xml";//定义content-type为xml
curl_setopt($ch, CURLOPT_URL, $url);//设置链接
//curl_setopt($ch, CURLOPT_POST, 1);//设置为POST方式
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
//curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//设置HTTP头
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);//POST数据
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//设置是否返回信息 $tmpInfo = curl_exec($ch);
return $tmpInfo;
}以上代码总是返回45010,和上面测试成功的对比,应该没有问题。
-----------------------------------------
$ret=$this->api_notice_increment($url,$data);这边的$data 是表示前面的那个json格式的字符串吗?貌似还要用引号包起来哦