php 微信公众号开发之 三 自定义菜单

appid 
"; $appsecret = "
appsecret 
"; $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); //返回 一个数组 //[html] view plain copy//7200 var_dump($jsoninfo); //[html] view plain copy$access_token = $jsoninfo["access_token"]; //d定义菜单的格式 $jsonmenu='{ "button":[ { "type":"view", "name":"目录1", "url":"http://wx.test.com/i.php" }, { "type":"view", "name":"目录2", "url":"http://wx.test.com/i.php" }, { "type":"view", "name":"目录3", "url":"http://wx.test.com/i.php" }] }'; $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token; $result = https_request($url, $jsonmenu); //[html] view plain copyvar_dump($result); function https_request($url,$data = null){ $curl = curl_init(); //$data=iconv('GB2312','UTF-8',$data);$encode = mb_detect_encoding($data, array('ASCII','UTF-8','GB2312','GBK','BIG5')); if ($encode!='UTF-8'){$data=iconv('GB2312','UTF-8',$data);} echo $data; curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/json", "Content-Type: text/xml; charset=utf-8")); 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; } echo '成功'; ?>

你可能感兴趣的:(PHP基础技术)