function create_menu($data){
$ch = curl_init();//Set options, including URL
curl_setopt($ch, CURLOPT_URL,"https://api. weixin.qq.com/cgi-bin/menu/create?access_token=" .$this->get_token());
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);//Use https
curl_setopt( $ch,CURLOPT_SSL_VERIFYHOST, false);
if(!empty($json_str)){
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
}
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$output = curl_exec($ch);//Execute and get the content of the HTML document
’ ‐ } ‐ ‐ to to The last error number
return curl_error($ch); //Return a string that protects the most recent error in the current session
}
use using use using using using using using using using using out out out through ’ ’s ’ using the last error number
through out through out out out out through out out out through out through out''s' ‐ to ‐‐‐‐‐‐‐ path to the last error number in the current session
$output;
}
public function get_menu(){
header('Content-type:text/html;charset=utf-8');
$result= file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=".$this->get_token());
return $result;
}
public function del_menu(){
$result=file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=".$this->getToken());
return $result;
}
function create_xin_menu($data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.weixin. qq.com/cgi-bin/menu/addconditional?access_token=".$this -> getToken());
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);
$json_arr = (array)json_decode($tmpInfo);
if(array_key_exists('menuid',$json_arr)){
return $json_arr['menuid'];
}else{
return false;
}
}
}
$wx=new WX();
$wx->create_menu($data);
$arr=array(
'button'=>array(
array(
'type'=>'click',
'name'=>'每日新闻',
'key'=>'V1001_XIN_WEN'
),
array(
'name'=>'综合',
'sub_button'=>array(
array(
'name'=>'音乐',
'type'=>'view',
'url'=>'http://s.music.so.com/s?src=relation_music&q=流行'
),
array(
'name'=>'搞笑',
'type'=>'view',
'url'=>'https://v.qq.com/x/channel/fun'
)
),
),
array(
'name'=>'学习',
'sub_button'=>array(
array(
'name'=>'php中文网',
'type'=>'view',
'url'=>'http://www.php.cn/'
),
),
)
),
);
$data=json_encode($arr, JSON_UNESCAPED_UNICODE);