Implementing the PHP code for the custom menu interface in WeChat public number enterprise

Source: Internet
Author: User
This article mainly introduces the PHP implementation of the public enterprise number custom menu interface, combined with examples of PHP custom menu class and interface related operation skills, the need for friends can refer to the following

The example of this article describes the PHP implementation of the public number of enterprise custom menu interface. Share to everyone for your reference, as follows:


Define (AppId, "wx666cae44xxxxxx2");//define APPID, you need to apply the custom menu on the public platform will get define (Appsecret, "d77026a714d443a01d0229xxxxxxxx ");//define Appsecret, you need to get the include (" menu.php ") after applying the custom menu on the public platform,//Introduce class $wechatobj = new Wechat ();//Instantiate class $creatmenu = $ Wechatobj->creatmenu ();//Create Menu

Class (menu.php) code


<?class wechat{Private Function Getaccesstoken ()//Get Access_token {$url = "Https://api.weixin.qq.com/cgi-bin/token ? grant_type=client_credential&appid= ". AppId. " &secret= ". Appsecret; $data = Getcurl ($url);//Get HTTPS content through custom function Getcurl $RESULTARR = Json_decode ($data, true);//turn to array return $RESULTARR [" Access_token "];//get Access_token} public Function Creatmenu ()//Create menu {$accessToken = $this->getaccesstoken ();//        Get Access_token $menuPostString = ' {//construct post to the server's menu Structure "button": [{"Name": "Product description", "Sub_button": [{        "Type": "View", "name": "Distribution Type a", "url": "Http://www.yourwebname.com/fenxiao/jianjie/soft.html"}, {        "Type": "View", "name": "Distribution Type B", "url": "Http://www.yourwebname.com/fenxiaob/jianjie/soft.html"},{        "Type": "View", "name": "Ground-up wholesale", "url": "Http://www.yourwebname.com/dijie/jianjie/soft.html"},{ "Type": "View", "name": "Thin Group", "url": "Http://www.yourwebname.com/zutuan/jianJie/soft.html "},{" type ":" View "," name ":" Direct Guest site "," url ":" Http://www.yourwebname.com/tripal/jianji         E/soft.html "}]}, {" name ":" Request Trial "," Sub_button ": [{" Type ":" click "," Name ":" Distribution Type a ", "Key": "Fxa"}, {"Type": "click", "Name": "Distribution Type B", "Key": "FXB"}, {"        Type ":" click "," Name ":" Ground to wholesale "," Key ":" DJ "}, {" Type ":" click "," Name ":" Compact Group ",       "Key": "Zutuan"}, {"Type": "click", "Name": "Direct Guest Site", "Key": "Zhike"}]}, { "Name": "Bo-line", "Sub_button": [{"Type": "View", "Name": "Enterprise Introduction", "url": "Http://www.yourw Ebname.com/about.html "}, {" Type ":" View "," name ":" Company News "," url ":" Http://www.yourwebname.com /news/company/"}, {" Type ":" View "," name ":" Contact Us "," url ":" Http://www.yourwebname.com/contac   T.html "}] }    ] }'; $MENUPOSTURL = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=". $accessToken; URL of//post $menu = Datapost ($menuPostString, $MENUPOSTURL);//Post the menu structure to the server}}function Getcurl ($url) {//get https content $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, curlopt_returntransfer,1);//output Content curl_setopt ($ch, Curlopt_ssl_verifypeer, false); curl_setopt ($ch, Curlopt_ssl_verifyhost, false); $result = curl_exec ($ch); Curl_close ($ch); return $result;} function Datapost ($post _string, $url) {//post Way to submit data $context = Array (' http ' = = Array (' method ' = ' "post", ' header ') = = "user-agent:mozilla/5.0 (Windows; U Windows NT 6.0; En-us) \ r \ n Accept: */* ", ' content ' = $post _string)); $stream _context = stream_context_create ($context); $data = file_get_contents ($url, FALSE, $stream _context); return $data;}? >

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.