<?php header("Content-type: text/html; charset=utf-8"); define("ACCESS_TOKEN", "my_token_key"); //创建菜单 function createMenu($data){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".ACCESS_TOKEN); 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); return $tmpInfo; } //获取菜单 function getMenu(){ return file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=".ACCESS_TOKEN); } //删除菜单 function deleteMenu(){ return file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=".ACCESS_TOKEN); } $data = '{ "button":[ { "type":"click", "name":"我的审核", "key":"my_audit_task" }, { "name":"我的资料", "sub_button":[ { "type":"click", "name":"我的基本信息", "key":"my_hr_msg" }, { "type":"click", "name":"我的认证资格", "key":"my_qualification" }, { "type":"click", "name":"我的专业代码", "key":"my_audit_code" }] }, { "type":"click", "name":"帮助", "key":"gggsoft_help" }] }'; echo createMenu($data); //echo getMenu(); //echo deleteMenu();