重庆小潘seo博客

当前位置:首页 > 重庆网络营销 > 小潘杂谈 >

小潘杂谈

微信创建自定义目录的方法实例

时间:2020-09-14 12:30:07 作者:重庆seo小潘 来源:
本文主要和大家分享微信创建自定义目录的方法实例,希望能帮助到大家。//创建自定义菜单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_da

本文主要和大家分享微信创建自定义目录的方法实例,希望能帮助到大家。//创建自定义菜单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 );//请求的方式是postcurl_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_tokenif(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;}}以上就是微信创建自定义目录的方法实例的详细内容,更多请关注小潘博客其它相关文章!