为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我的$res的值是null http_curl中所有参数都有值传过去

为什么我的$res的值是null http_curl中所有参数都有值传过去

PHP
12345654321 2016-10-28 18:06:13
 function http_curl($url,$type='get',$res='json',$arr=''){         // 1.初始化curl         $ch   = curl_init();         // $url     = "https://www.imooc.com/";         // 2.设置curl参数         curl_setopt($ch, CURLOPT_URL, $url);         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);         if($type=='post'){             curl_setopt($ch, CURLOPT_POST, 1);             curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);         }         // 3.采集         $output  = curl_exec($ch);         // 4.关闭         curl_close($ch);         if($res=="json"){             if(curl_error($ch)){                 return curl_error($ch);             }else{                 return json_decode($output,true);             }                      }           }       public function getWxAccessToken(){          if($_SESSION['access_token'] && $_SESSION['expire_time']>time()){             return $_SESSION['access_token'];         }else{             $appid = 'wx87597d10a4f61fc3';             $appsecret     = "bfcde589d19fd16c61d1142633f6872b";             $url ="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret;               $res = $this->http_curl($url,'get','json');             $access_token = $res['access_token'];             $_SESSION['access_token'] = $access_token;             $_SESSION['expire_time'] =time()+7000;             return $access_token;             var_dump($access_token);         }     }          public function definedItem(){         $access_token = $this->getWxAccessToken();          $url =" https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;         $postArr = array(             'button'=>array(                         array(                                  'name'=>urlencode('菜单一'),                                   'type'=>'click',                                   'key'=>'item1'                         ),//第一个一级菜单                         array(                                 'name'=>urlencode('菜单二'),                                 'sub_button'=>array(                                                 array(                                                     'name'=>urlencode('歌曲'),                                                    'type'=>'click',                                                    'key'=>'songs'                                                 ),                                                  array(                                                    'name'=>urlencode('百度'),                                                    'type'=>'view',                                                    'url'=>'http://wap.baidu.com/'                                                 ),                                                                                      ),                         ),//第二个一级菜单                         array(                             'type'=>'click',                             'name'=>'赞一下我们',                             'key'=>'V1001_GOOD'                         ),//第三个一级菜单             ),            );         $postJosn =urldecode(json_encode($postArr));         $res = $this->http_curl($url,'post','josn',$postJosn);         var_dump($res);     }
查看完整描述

4 回答

?
小苑Coder

TA贡献1条经验 获得超0个赞

你的请求地址前边肯定有个空格

查看完整回答
反对 回复 2016-11-16
?
12345654321

TA贡献1条经验 获得超0个赞

返回是null 但是菜单已经创建成功了 

查看完整回答
反对 回复 2016-10-31
?
慕田峪3555374

TA贡献137条经验 获得超18个赞

可能是你token过期了,菜单生成失败

查看完整回答
反对 回复 2016-10-30
  • 4 回答
  • 2 关注
  • 2493 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信