Sample processing and development of WeChat custom menu, WeChat custom sample _php Tutorial

Source: Internet
Author: User

Sample processing development for custom menus, custom examples


Customizing the creation of menus

<?phpdefine ("APPID", "Your APPID");d efine ("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);  Gets the contents of the file or gets the contents of the network request//echo $res; $result = Json_decode ($res, true);  Accept a JSON-formatted string and convert it to PHP variable $access_token = $result [' Access_token '];d efine ("Access_token", $access _token); Defines access_token as constants 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 ': ' Song of the Day ', ' 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, Curlopt_ssl_verifypeer, 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);//Interpreting whether there is an error in the execution, or sending a data error report. If (Curl_errno ($ch)) {echo ' Error '. Curl_error ($ch);//user checks for Curl module opening in PHP runtime.} Curl_close ($ch);p rint_r ($info); View the data returned after the post is submitted to the server.

Customizing the Fetch of menus

<?phpdefine ("APPID", "Your APPID");d efine ("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);  Gets the contents of the file or gets the content of the network request $result = Json_decode ($res, true);  Accept a JSON-formatted string and convert it to a 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;

Customizing the deletion of menus

<?phpdefine ("APPID", "Your APPID");d efine ("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);  Gets the contents of the file or gets the content of the network request $result = Json_decode ($res, true);  Accept a JSON-formatted string and convert it to a 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 mentioned is the whole content of this article, I hope that we can help you develop.

http://www.bkjia.com/PHPjc/985274.html www.bkjia.com true http://www.bkjia.com/PHPjc/985274.html techarticle Custom menu Processing development examples, custom sample custom menu creation Phpdefine ("APPID", "Your APPID");d efine ("Appsecret", "Your Appsecret"), $token _access_ ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.