我想学习token的使用方式,求大神指教,最好有全部代码(在什么地方调用,怎么调用

解决方案 »

  1.   

    可以参考微信公众平台的接口token
    http://mp.weixin.qq.com/wiki/14/9f9c82c1af308e3b14ba9b973f99a8ba.html
      

  2.   

    //返回微信token例子
        public function getWeixinAcessToken(){
            if(session('access_token')&&session('expire_time')>time()){
                return session('access_token');
            }else {
                $appid=' ';
                $appsecret=' ';
                $url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret;
                $result=$this->http_curl($url,'get','json');
                $access_token=$result['access_token'];
                session('access_token',$access_token);
                session('expire_time',time()+7000);
                return $access_token;
            }
        }    public function http_curl($url,$type='get',$result='json',$array=''){
            $ch=curl_init();
            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, $array);
            }
            $output=curl_exec($ch);
            curl_close($ch);
            if ($result=='json'){
                return json_decode($output,true);
            }
        }