This article mainly introduces the PHP version of the public number of custom menu, has a certain reference value, now share to everyone, the need for friends can refer to
<?php//id key $appid = "wx5502a933452cecf0"; $appsecret = "c7fd97ec7ce4ec3c5f2766b89d97512c"; $url = "https:// api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= $appid &secret= $appsecret "; $output = Https_request ($url); $jsoninfo = Json_decode ($output, true); Returns an array
7200var_dump ($jsoninfo);
$access _token = $jsoninfo ["Access_token"];//d defines the format of the menu $jsonmenu = ' {' button ': [{' name ': ' See Popular Science ', "Sub_button": [{"Type": "View", "name": "Expert lecture hall", "url": "Http://m.h Ao123.com/a/tianqi "}, {" Type ":" View "," name ":" Sterile "," URL ":" Http://m.hao123.com/a/tianqi "}, {" Type ":" View "," name ":" IVF ", "url": "Http://m.hao123.com/a/tianqi"}]}, {"name": "Ask Doctor", "Sub_ Button ": [{" Type ":" View "," name ":" Portal "," url ":" http://m.hao123.com/ A/tianqi "}]}, {" name ":" Find Service "," Sub_button ": [{ "Type": "View", "name": "Mall Entry", "url": "Http://m.hao123.com/a/tianqi" }, { "Type": "View", "name": "Overseas Doctor", "url": "Http://m.hao123.com/a/tianqi"}, {"Type": "View", "name": "Hospital Recommendation", "url": "Http://m.hao123.com/a/tianqi" }]}]} '; $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=". $access _token; $resu lt = https_request ($url, $jsonmenu);
Var_dump ($result); function https_request ($url, $data = null) { $curl = Curl_init (); curl_setopt ($curl, Curlopt_url, $url); curl_setopt ($curl, Curlopt_ssl_verifypeer, FALSE); curl_setopt ($curl, Curlopt_ssl_verifyhost, FALSE); if (!empty ($data)) { curl_setopt ($curl, Curlopt_post, 1); curl_setopt ($curl, Curlopt_postfields, $data); } curl_setopt ($curl, Curlopt_returntransfer, 1); $output = curl_exec ($curl); Curl_close ($curl); return $output;}? >
Array (2) { ["Access_token"]=> String (156) "5_wfmite_skjx6zyy4jivg6ayjjuamh2qnxatrsrxvrkmgoqxpgihlkhxnb4ah6atrjvodea_ Oeoncr1oob0alyyw7uhibuqcvg2p0h-6ksabxnbnyxherlbf49z-pac_z7gp2p-pqaey-gr_zmpcdadawzm " [" expires_in "]=& gt; Int (7200)}string (+) "{" Errcode ": 0," errmsg ":" OK "}" generated by the number of groups, I follow the document step-by-step write rough, can run directly