1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 The |
<?php define ("APPID", "Your APPID"); Define ("Appsecret", "Your appsec RET "); $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//echo $res; $result = Json_decode ($res, true); Accepts a JSON-formatted string and converts it to a PHP variable $access _token = $result [' Access_token ']; Define ("Access_token", $access _token); Define 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 ': ' 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 ":" Praise 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); //interpretation of errors in the implementation process, there is a data error report sent. if (Curl_errno ($ch)) {echo ' Error '. Curl_error ($ch);//user checks the Curl module in the PHP operating environment.} Curl_close ($ch); Print_r ($info); View the data returned after post is submitted to the micro-trust server. |