Before 5.0, the custom menu was used as an internal test qualification and only a few public accounts had a menu. Therefore, many enterprises did not hesitate to purchase the menu. Nowadays, a large number of accounts are switching from subscription numbers to service numbers, and many of them go through custom menus. Today, we will give a brief look at the processing of custom menus.
Create a custom menu
<? Phpdefine ("APPID", "your appid"); define ("APPSECRET", "your appsecret"); $ token_access_url =" https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= ". APPID. "& secret = ". APPSECRET; $ res = file_get_contents ($ token_access_url); // get the file content or obtain the content of the network request // echo $ res; $ result = json_decode ($ res, true ); // accept a JSON string and convert it to the PHP variable $ access_token = $ result ['Access _ token']; define ("ACCESS_TOKEN", $ access_token ); // define access_token as a constant for ease of use. $ make_menu_url =" https://api.weixin.qq.com/cgi-bin/menu/create?access_token= ". ACCESS_TOKEN; $ menuData = '{"button": [{"type": "click", "name": "Today's Song", "key": "V1001_TODAY_MUSIC "}, {"name": "menu", "sub_button": [{"type": "view", "name": "Search", "url ":" http://www.soso.com/ "},{" Type ":" view "," name ":" video "," url ":" http://v.qq.com/ "},{" Type ":" click "," name ":" Like Us "," key ":" V1001_GOOD "}]} '; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ make_menu_url); curl_setopt ($ ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt ($ ch, success, FALSE ); curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1 ;. net clr 1.1.4322) "); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ ch, CURLOPT_AUTOREFERER, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ menuData ); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, TRUE); $ info = curl_exec ($ ch); // if an error occurs during execution, a data error report is sent. if (curl_errno ($ ch) {echo 'error '. curl_error ($ ch); // check whether the curl module is enabled in the php runtime environment .} curl_close ($ ch); print_r ($ info); // view the data returned after the post is submitted to the server.
Custom menu acquisition
<? Phpdefine ("APPID", "your appid"); define ("APPSECRET", "your appsecret"); $ token_access_url = "https://api.weixin.qq.com/cgi-bin/token? Grant_type = client_credential & appid = ". APPID. "& secret = ". APPSECRET; $ res = file_get_contents ($ token_access_url); // get the file content or get the content of the network request $ result = json_decode ($ res, true ); // accept a JSON string and convert it to the PHP variable $ access_token = $ result ['Access _ token']; $ make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/get? Access_token = ". $ access_token; $ menu_json = file_get_contents ($ make_menu_url); echo $ menu_json;
Delete a custom menu
<? Phpdefine ("APPID", "your appid"); define ("APPSECRET", "your appsecret"); $ token_access_url = "https://api.weixin.qq.com/cgi-bin/token? Grant_type = client_credential & appid = ". APPID. "& secret = ". APPSECRET; $ res = file_get_contents ($ token_access_url); // get the file content or get the content of the network request $ result = json_decode ($ res, true ); // accept a JSON string and convert it to the PHP variable $ access_token = $ result ['Access _ token']; $ make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/delete? Access_token = ". $ access_token; $ menu_json = file_get_contents ($ make_menu_url); echo $ menu_json;
The above is all the content of this article, and I hope it will help you with development.