微信创建自定义目录的方法实例
本文主要和大家分享微信创建自定义目录的方法实例,希望能帮助到大家。//创建自定义菜单 private function create_menu($access_token){ //echo $access_token;exit; $url="https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token; $post_data='{ "button":[ { "name":"PHP", "sub_button":[ { "type":"view", "name":"ThinkPHP", "url":"http://wap.phplee.com" }, { "type":"view", "name":"微信", "url":"http://wap.phplee.com/" } ] }, { "name":"运维", "sub_button":[ { "type":"view", "name":"Linux", "url":"http://wap.phplee.com" }, { "type":"view", "name":"MySQL", "url":"http://wap.phplee.com" } ] }, { "name":"APP", "sub_button":[ { "type":"view", "name":"Android", "url":"http://wap.phplee.com/" }, { "type":"view", "name":"IOS", "url":"http://wap.phplee.com/" }] }] }'; $header [] = "content-type: application/json; charset=UTF-8"; $ch = curl_init (); curl_setopt ( $ch, CURLOPT_URL, $url ); //请求的方式是post curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST" ); // 禁用后cURL将终止从服务端进行验证 curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); //不检查证书 curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); //发送头部字段 curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header ); //告诉对方 自己的浏览器型号 curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)' ); //即表示自动进行跳转抓取(如果URL发生了302重定向)继续抓取 curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 ); //自动重定向开启 curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 ); //发送的post参数 curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_data); //得到的结果不显示在屏幕上,作为变量结果储存 curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true ); $res = curl_exec ( $ch ); //如果运行错误,返回一个错误号 $flat = curl_errno ( $ch ); if ($flat) { $data = curl_error ( $ch ); } curl_close ( $ch ); //拿到了返回结果后json格式转化为可以使用的数组格式 $res = json_decode ( $res, true ); if($res['errcode']==0){ return true; }else{ return false; } } 使用: //微信测试 public function Index() { //获取access_token if(S('access_token')){ $access_token=S('access_token'); }else{ $access_token=$this->get_access_token(); S('access_token',$access_token); } //echo $access_token;exit; //创建菜单 $result=$this->create_menu($access_token); if($result===false){ echo '创建菜单失败';exit; }else{ echo '创建菜单成功';exit; } } 以上就是微信创建自定义目录的方法实例的详细内容,更多请关注php中文网其它相关文章! |
- 上一篇:微信如何获取openid
- 下一篇:微信如何验证所有者