当前位置: 首页>>代码示例>>PHP>>正文


PHP SaeTOAuthV2::getAccessToken方法代码示例

本文整理汇总了PHP中SaeTOAuthV2::getAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP SaeTOAuthV2::getAccessToken方法的具体用法?PHP SaeTOAuthV2::getAccessToken怎么用?PHP SaeTOAuthV2::getAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SaeTOAuthV2的用法示例。


在下文中一共展示了SaeTOAuthV2::getAccessToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: bindSina

 /**
  * sina绑定
  */
 function bindSina()
 {
     $code = $this->trimmed('code');
     if (empty($code)) {
         $this->clientError('cannot find sina code, oauth failed', $code);
         exit;
     }
     $keys = array();
     $keys['code'] = $code;
     $keys['redirect_uri'] = WB_CALLBACK_URL;
     try {
         $sinaOauth = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
         $token = $sinaOauth->getAccessToken('code', $keys);
     } catch (OAuthException $e) {
         $this->clientError("oauth failed {$e}", 400);
         exit;
     }
     $url = 'https://api.weibo.com/2/users/show.json?' . http_build_query(array('access_token' => $token['access_token'], 'uid' => $token['uid']));
     $user = json_decode(file_get_contents($url));
     if (array_key_exists("error", $user)) {
         $this->clientError($user, 400);
     }
     $userOption = array('via' => 'weibo', 'uid' => $user->id, 'screen_name' => $user->screen_name, 'name' => $user->name, 'location' => $user->location, 'description' => $user->description, 'image' => $user->profile_image_url, 'access_token' => $token->access_token, 'expire_at' => $token->expires, 'refresh_token' => $token->refresh_token);
     $this->bind_common($user->id, User::PLATFORM_TYPE_SINA, $userOption);
 }
开发者ID:jianoll,项目名称:SpeakEnglish_Server,代码行数:28,代码来源:apiaccountbindplatform.php

示例2: actionReturn

 function actionReturn()
 {
     $o = new \SaeTOAuthV2($this->app_key, $this->app_secret);
     if ($_REQUEST['code']) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         $keys['redirect_uri'] = $this->url;
         try {
             $token = $o->getAccessToken('code', $keys);
             $access_token = $token['access_token'];
             $c = new \SaeTClientV2($this->app_key, $this->app_secret, $access_token);
             $uid_get = $c->get_uid();
             $uid = $uid_get['uid'];
             $me = $c->show_user_by_id($uid);
             $me['name'] = $me['screen_name'];
             $me['options'] = array('url' => $me['profile_url']);
             $r = $this->member_get_third_set_user($me, $this->oauth_id, $access_token);
             flash('success', __('login success'));
             $this->redirect(return_url());
         } catch (OAuthException $e) {
             flash('error', __('login error'));
             $this->redirect(return_url());
         }
     }
     exit;
 }
开发者ID:rocketyang,项目名称:mincms,代码行数:26,代码来源:SinaController.php

示例3: callback

 function callback()
 {
     $o = new SaeTOAuthV2(c('weibo_akey'), c('weibo_skey'));
     if (isset($_REQUEST['code'])) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         $keys['redirect_uri'] = 'http://' . c('site_domain') . '/?c=weibo&a=callback';
         try {
             $token = $o->getAccessToken('code', $keys);
         } catch (OAuthException $e) {
         }
         $_SESSION['weibo_token'] = $token;
         // get user info
         $c = new SaeTClientV2(c('weibo_akey'), c('weibo_skey'), atoken());
         $info = $c->show_user_by_id(wbuid());
         if (strlen($info['name']) < 1) {
             return info_page('登入失败,请去吃点零食后重试');
         }
         $_SESSION['weibo_uid'] = $info['name'];
         $_SESSION['uname'] = $info['name'];
         $_SESSION['avatar'] = $info['profile_image_url'];
         //print_r( $_SESSION );
         header("Location: /?a=index");
     }
 }
开发者ID:oxmcvusd,项目名称:nowboard,代码行数:25,代码来源:weibo.class.php

示例4: index

 /**
  * Index Page for this controller.
  *
  * Maps to the following URL
  * 		http://example.com/index.php/welcome
  * 	- or -  
  * 		http://example.com/index.php/welcome/index
  * 	- or -
  * Since this controller is set as the default controller in 
  * config/routes.php, it's displayed at http://example.com/
  *
  * So any other public methods not prefixed with an underscore will
  * map to /index.php/welcome/<method_name>
  * @see http://codeigniter.com/user_guide/general/urls.html
  */
 public function index()
 {
     $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY, null, null);
     if (isset($_REQUEST['code'])) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         $keys['redirect_uri'] = WB_CALLBACK_URL;
         try {
             $token = $o->getAccessToken('code', $keys);
             $data['token'] = $token;
         } catch (OAuthException $e) {
             echo $e;
         }
     }
     if (isset($token)) {
         $this->session->set_userdata($token);
         //设定Session,将$token写入session
         $this->input->set_cookie('weibojs_' . $o->client_id, http_build_query($token));
         //设定cookie
         $data['flag'] = 'Y';
     } else {
         $data['flag'] = 'N';
     }
     $data['o'] = $o;
     $this->load->view('celebritytop/callback_view', $data);
 }
开发者ID:yunsite,项目名称:sina-weobo,代码行数:41,代码来源:callback.php

示例5: weibocallback

 public function weibocallback($code)
 {
     $cfg = K::$system->config->get('connect');
     if (defined('IN_MOBILE')) {
         $mobile = K::$system->config->get('mobile');
         $callback = $mobile['url'] . '/' . K::M('helper/link')->mklink('passport:weibocallback');
     } else {
         $site = K::$system->config->get('site');
         $callback = $site['siteurl'] . '/' . K::M('helper/link')->mklink('passport:weibocallback');
     }
     if (empty($cfg['weibo_is_open'])) {
         $this->err->add('很抱歉网站管理员还未开启微博登录功能', 201);
         return false;
     }
     $keys = array();
     $keys['code'] = $code;
     $keys['redirect_uri'] = $callback;
     $o = new SaeTOAuthV2($cfg['weibo_app_id'], $cfg['weibo_app_key']);
     try {
         $token = $o->getAccessToken('code', $keys);
     } catch (OAuthException $e) {
         $this->err->add($e->getMessage(), 201);
         return false;
     }
     $c = new SaeTClientV2($cfg['weibo_app_id'], $cfg['weibo_app_key'], $token['access_token']);
     $ms = $c->home_timeline();
     // done
     $uid_get = $c->get_uid();
     $uid = $uid_get['uid'];
     $user_message = $c->show_user_by_id($uid);
     //根据ID获取用户等基本信息
     return $this->login($uid, $user_message);
 }
开发者ID:a195474368,项目名称:ejiawang,代码行数:33,代码来源:weibo.mdl.php

示例6: AuthCallback_sina

/**
 * 此函数,供Callback处调用,如果返回false,认证失败,否则返回以下哈希表:
 *   last_key  ->  callback得到的last_key
 *   oauth_token ->  上述lastkey中的oauth_token
 *   oauth_token_secret -> 上述lastkey中的oauth_token_secret
 *   user_id -> 用户ID
 *   user_name ->  用户昵称
 *   user_email -> 暂不提供
 */
function AuthCallback_sina()
{
    // 取得新浪Auth对象
    $sinaappkey = $_SESSION['sinaappkey'];
    $sinasecret = $_SESSION['sinasecret'];
    $o = new SaeTOAuthV2($sinaappkey, $sinasecret);
    if (isset($_REQUEST['code'])) {
        $keys = array();
        $keys['code'] = $_REQUEST['code'];
        $keys['redirect_uri'] = $_SESSION['wb_callback_url'];
        try {
            $last_key = $o->getAccessToken('code', $keys);
        } catch (OAuthException $e) {
        }
    }
    if ($last_key) {
        $rtn = array();
        $rtn['last_key'] = $last_key;
        $rtn['oauth_token'] = $keys['code'];
        $rtn['oauth_token_secret'] = $last_key['access_token'];
        $client = new SaeTClientV2($sinaappkey, $sinasecret, $last_key['access_token']);
        $uid_get = $client->get_uid();
        $rtn['user_id'] = $uid_get['uid'];
        $user_message = $client->show_user_by_id($rtn['user_id']);
        $rtn['user_name'] = $user_message['screen_name'];
        return $rtn;
    } else {
        return $last_key;
    }
}
开发者ID:apachesep,项目名称:joomla-weibo,代码行数:39,代码来源:weibo.sina.php

示例7: sinalogin

 public function sinalogin()
 {
     $loginconfig = FS("Webconfig/loginconfig");
     define("WB_AKEY", $loginconfig['sina']['akey']);
     define("WB_SKEY", $loginconfig['sina']['skey']);
     define("WB_CALLBACK_URL", C('WEB_URL') . __APP__ . '/member/oauth/sinalogin');
     require C("APP_ROOT") . "Lib/Oauth/sina/saetv2.ex.class.php";
     $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
     if (isset($_REQUEST['code'])) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         $keys['redirect_uri'] = WB_CALLBACK_URL;
         try {
             $token = $o->getAccessToken('code', $keys);
         } catch (OAuthException $e) {
         }
     }
     if ($token) {
         $_SESSION['token'] = $token;
     } else {
         exit("出错,请重试");
     }
     $map['openid'] = text($token['uid']);
     //唯一ID
     $map['site'] = 'sina';
     $this->appCk($map, "@sina" . $map['openid'], 'sina');
     //nickname
 }
开发者ID:kinglong366,项目名称:p2p,代码行数:28,代码来源:OauthController.class.php

示例8: WB_callback

function WB_callback()
{
    $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
    if (isset($_REQUEST['code'])) {
        $keys = array();
        $keys['code'] = $_REQUEST['code'];
        //                $login_type = getvaluebykey('login_type');
        //                $userid = getvaluebykey('userid');
        //                print_r($userid);exit;
        //                $headpic = getvaluebykey('headpic');
        //                $emailnum  = getvaluebykey('emailnum');
        $keys['redirect_uri'] = WB_CALLBACK_URL;
        //.'?login_type='.$login_type.'_'.$userid.'_'.$headpic.'_'.$emailnum;
        try {
            $token = $o->getAccessToken('code', $keys);
            //print_r($token);
        } catch (OAuthException $e) {
        }
    }
    if ($token) {
        $_SESSION['token'] = $token;
        $c1 = new SaeTClientV2(WB_AKEY, WB_SKEY, $token['access_token']);
        $userinfo = $c1->show_user_by_id($token[uid]);
        setcookie('weibojs_' . $o->client_id, http_build_query($token));
        $cb_arr = array('access_token' => $token['access_token'], 'openid' => $token[uid], 'nick' => $userinfo['name']);
        return $cb_arr;
    }
}
开发者ID:yonglinchen,项目名称:shopping,代码行数:28,代码来源:callback.php

示例9: getWeiboUserInfo

    public static function getWeiboUserInfo()
    {
        if (!self::$_config) {
            self::$_config = (require_once WEIBO_PATH . 'config/config.php');
        }
        $o = new SaeTOAuthV2(self::$_config['WB_AKEY'], self::$_config['WB_SKEY']);
        if (isset($_REQUEST['code'])) {
            $keys = array();
            $keys['code'] = $_REQUEST['code'];
            $keys['redirect_uri'] = self::$_config['WB_CALLBACK_URL'];
            try {
                $token = $o->getAccessToken('code', $keys);
            } catch (OAuthException $e) {
            }
        }
        if ($token) {
            $_SESSION['token'] = $token;
            setcookie('weibojs_' . $o->client_id, http_build_query($token), '/');
            //把新浪微博的用户信息存起来
            self::createWeiboUser();
            //跳回登录前的页面
            self::callbackLast();
            ?>
			<?php 
        } else {
            ?>
			授权失败。
			<?php 
        }
    }
开发者ID:lughong,项目名称:test,代码行数:30,代码来源:WeiBoLogin.class.php

示例10: array

 function get_info()
 {
     if ($this->dx_auth->is_logged_in()) {
         echo "你已经登陆了";
     } else {
         $this->load->model('m_open');
         session_start();
         require_once APPPATH . 'libraries/weibo/config.php';
         require_once APPPATH . 'libraries/weibo/saetv2.ex.class.php';
         $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
         $o->set_debug(DEBUG_MODE);
         if (isset($_REQUEST['code'])) {
             $keys = array();
             // 验证state
             $state = $_REQUEST['state'];
             if (empty($state) || $state !== $_SESSION['weibo_state']) {
                 echo '非法请求!';
                 exit;
             }
             unset($_SESSION['weibo_state']);
             $keys['code'] = $_REQUEST['code'];
             $keys['redirect_uri'] = WB_CALLBACK_URL;
             try {
                 $token = $o->getAccessToken('code', $keys);
             } catch (OAuthException $e) {
             }
         }
         if ($token) {
             $_SESSION['token'] = $token;
             setcookie('weibojs_' . $o->client_id, http_build_query($token));
             //echo "success";
             $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
             $c->set_debug(DEBUG_MODE);
             $uid_get = $c->get_uid();
             $uid = $uid_get['uid'];
             if (!$uid) {
                 echo "error";
             }
             $user = $c->show_user_by_id($uid);
             //根据ID获取用户等基本信息
             //echo $user['screen_name'];
             if ($this->m_open->is_id($uid)) {
                 $this->m_open->login($uid);
                 //echo "登陆";
                 //echo $uid;
                 //$c->update( "坑爹的api终于调好了");
                 redirect('line');
             } else {
                 $this->m_open->register($user);
                 $this->m_open->create($user);
                 //echo $uid;
                 //echo "注册";
                 redirect('line');
             }
         } else {
             echo "fail";
         }
     }
 }
开发者ID:bullda,项目名称:CI_weibo_login,代码行数:59,代码来源:open.php

示例11: callback

 /**
  * 授权回调地址
  */
 public function callback()
 {
     if (empty($_GET['code'])) {
         throw new Typecho_Exception(_t('无效请求!'));
     }
     //跳转
     if (!class_exists('SaeTOAuthV2')) {
         require_once './saetv2.ex.class.php';
     }
     $saeto_client = new SaeTOAuthV2($this->config->client_id, $this->config->client_secret);
     //取access_token
     $access_token = $saeto_client->getAccessToken('code', array('code' => trim($_GET['code']), 'redirect_uri' => $this->config->callback_url));
     if (empty($access_token) || !is_array($access_token) || empty($access_token['uid'])) {
         throw new Typecho_Exception(_t('获取access_token失败,请返回重新授权!'));
     }
     $table = $this->db->getPrefix() . self::$tableName;
     $query = $this->db->query("SELECT * FROM {$table} WHERE openid='{$access_token['uid']}' AND plateform='sina'");
     $users_oauth = $this->db->fetchRow($query);
     if (!empty($users_oauth['uid'])) {
         //该新浪帐号已经绑定了用户
         if (Typecho_Widget::widget('Widget_User')->hasLogin()) {
             /** 直接返回 */
             $this->response->redirect(Typecho_Widget::widget('Widget_Options')->index);
         } else {
             //让其直接登陆
             $this->setUserLogin($users_oauth['uid']);
             if (!Typecho_Widget::widget('Widget_User')->pass('contributor', true)) {
                 /** 不允许普通用户直接跳转后台 */
                 $this->response->redirect(Typecho_Widget::widget('Widget_Options')->profileUrl);
             } else {
                 $this->response->redirect(Typecho_Widget::widget('Widget_Options')->adminUrl);
             }
         }
         exit;
     }
     //该新浪帐号未绑定过
     /** 如果已经登录 */
     if (Typecho_Widget::widget('Widget_User')->hasLogin()) {
         /** 直接绑定 */
         $cookieUid = Typecho_Cookie::get('__typecho_uid');
         $this->bindOauthUser($cookieUid, $access_token['uid'], 'sina', $access_token['expires_in']);
         $this->response->redirect(Typecho_Widget::widget('Widget_Options')->index);
     } else {
         //取用户信息
         $saetc_client = new SaeTClientV2($this->config->client_id, $this->config->client_secret, $access_token['access_token']);
         $weibo_user = $saetc_client->show_user_by_id($access_token['uid']);
         //创建用户
         $uid = $this->registerFromWeiboUser($weibo_user);
         if (!$uid) {
             throw new Typecho_Exception(_t('创建帐号失败,请联系管理员!'));
         }
         $this->setUserLogin($uid);
         $this->bindOauthUser($uid, $access_token['uid'], 'sina', $access_token['expires_in']);
         $this->response->redirect(Typecho_Widget::widget('Widget_Options')->profileUrl);
     }
     //构造用户帐号
     exit;
 }
开发者ID:duxiangfei,项目名称:plugins,代码行数:61,代码来源:AuthorizeAction.php

示例12: getLoginTokens

 /**
  * 获取accessToken
  * code  用户点击同意按钮后 会生成
  * redirect_uri  回调url
  */
 public static function getLoginTokens($paramArr)
 {
     $options = array('code' => '', 'redirect_uri' => '');
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     if (!$code || !$redirect_uri) {
         return false;
     }
     $loginObj = new SaeTOAuthV2(self::$WB_AKEY, self::$WB_SKEY);
     $tokens = $loginObj->getAccessToken('code', array('code' => $code, 'redirect_uri' => $redirect_uri, 'refresh_token' => ''));
     return $tokens;
 }
开发者ID:hongbo819,项目名称:APILJL,代码行数:19,代码来源:Sina.php

示例13: getUserInfo

 public function getUserInfo($request_args)
 {
     is_null($request_args['code']) && exit;
     $oauth = new SaeTOAuthV2($this->setting['app_key'], $this->setting['app_secret']);
     $keys = array('code' => $request_args['code'], 'redirect_uri' => $this->redirect_uri);
     $token = $oauth->getAccessToken('code', $keys);
     $client = new SaeTClientV2($this->setting['app_key'], $this->setting['app_secret'], $token['access_token']);
     $user = $client->show_user_by_id($token['uid']);
     $result['keyid'] = $user['id'];
     $result['keyname'] = $user['name'];
     $result['keyavatar_small'] = $user['profile_image_url'];
     $result['keyavatar_big'] = $user['avatar_large'];
     $result['bind_info'] = $token;
     return $result;
 }
开发者ID:kid2682,项目名称:SMZDM,代码行数:15,代码来源:sina.php

示例14: weibocallback

 /**
  *微博回调
  *@author winter
  *@version 2015年11月20日19:52:33
  */
 public function weibocallback()
 {
     include_once './libweibo/config.php';
     include_once './libweibo/saetv2.ex.class.php';
     $o = new \SaeTOAuthV2(WB_AKEY, WB_SKEY);
     if (isset($_REQUEST['code'])) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         $keys['redirect_uri'] = WB_CALLBACK_URL;
         try {
             $token = $o->getAccessToken('code', $keys);
         } catch (OAuthException $e) {
         }
     }
     if ($token) {
         //授权完成
         $_SESSION['token'] = $token;
         setcookie('weibojs_' . $o->client_id, http_build_query($token));
         $c = new \SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
         //$ms  = $c->home_timeline(); // done
         $uid_get = $c->get_uid();
         $uid = $uid_get['uid'];
         $user_message = $c->show_user_by_id($uid);
         //根据ID获取用户等基本信息
         if ($user_message) {
             $user = M('user');
             $list = $user->where("wbuid = '" . $uid . "'  and status = 1")->find();
             //echo $user->getlastsql();die();
             if (!$list) {
                 session('uinfo', $user_message);
                 session('sign', array('name' => '微博账号', 'code' => 2));
                 echo "<script>window.close();window.opener.location.href='" . U('User/threepartlogin') . "'</script>";
                 exit;
             }
             session('userid', $list['id']);
             session('username', $list['nickname']);
             session('userphone', $list['mobile']);
             session('userimg', $list['headpic']);
             echo "<script>window.close();window.opener.location.reload()</script>";
             exit;
         } else {
             $this->error('登陆失败');
         }
     } else {
         //授权失败
         $this->error('登陆失败');
     }
 }
开发者ID:songxiaoxiao,项目名称:zyw,代码行数:53,代码来源:LoginController.class.php

示例15: wbcallback

 public function wbcallback()
 {
     Vendor('Weibo.saetv2#ex#class');
     $o = new \SaeTOAuthV2(C('weibo.wb_akey'), C('weibo.wb_skey'));
     if (isset($_REQUEST['code'])) {
         $keys = array();
         $keys['code'] = $this->_request('code');
         $keys['redirect_uri'] = C('weibo.wb_callback_url');
         try {
             $token = $o->getAccessToken('code', $keys);
         } catch (OAuthException $e) {
         }
     }
     if ($token) {
         // 获取用户信息
         $c = new SaeTClientV2(C('weibo.wb_akey'), C('weibo.wb_skey'), $token['access_token']);
         // $ms  = $c->home_timeline(); // done
         $uid_get = $c->get_uid();
         $uid = $uid_get['uid'];
         $uinfo = $c->show_user_by_id($uid);
         //根据ID获取用户等基本信息
         // 查询是否已经绑定
         $this->user_model = D('user');
         $user = $this->user_model->field('id,email,password')->where(array('wb_token' => $token['access_token'], 'wb_openid' => $uid))->find();
         // echo $this->user_model->getLastSql();
         if ($user['id'] > 0) {
             // 登录用户
             if ($this->user_model->login($user['id'], $user['email'], $user['password'])) {
                 //TODO:跳转到登录前页面
                 $this->success('登录成功!', session('rebackurl'));
             } else {
                 $this->error($model->getError());
             }
         } else {
             session('avatar', $uinfo['avatar_hd']);
             session('openid', $uinfo['id']);
             session('token', $token['access_token']);
             session('uname', $uinfo['screen_name']);
             session('oatype', 'wb_');
             //print_r($uinfo);
             $this->redirect('join');
         }
     } else {
         $this->error('授权失败。');
     }
 }
开发者ID:kjzwj,项目名称:jcms,代码行数:46,代码来源:oauthAction.class.php


注:本文中的SaeTOAuthV2::getAccessToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。