Пример #1
0
 public function run()
 {
     require_once Yii::getPathOfAlias('ext') . "/OAuth/renren/RennClient.php";
     $config = OAuth::getConf('renren');
     $rennClient = new RennClient($config['app_key'], $config['app_secret']);
     // 生成state并存入SESSION,以供CALLBACK时验证使用
     $state = uniqid('renren_', true);
     Yii::app()->session['renren_state'] = $state;
     // 取得认证授权的url
     $code_url = $rennClient->getAuthorizeURL($config['callback'], 'code', $state);
     $this->controller->redirect($code_url);
 }
Пример #2
0
 public function run()
 {
     require_once Yii::getPathOfAlias('ext') . "/OAuth/renren/rennclient/RennClient.php";
     $config = OAuth::getConf('renren');
     $rennClient = new RennClient($config['app_key'], $config['app_secret']);
     // 处理code -- 根据code来获得token
     if (isset($_REQUEST['code'])) {
         // 验证state,防止伪造请求跨站攻击
         $state = $_REQUEST['state'];
         if (empty($state) || $state !== Yii::app()->session['renren_state']) {
             throw new CHttpException(500, 'Error: Illegal Request');
         }
         unset(Yii::app()->session['renren_state']);
         // 获得code
         $code = $_REQUEST['code'];
         $redirect_uri = $config['callback'];
         try {
             // 根据code来获得token
             $token = $rennClient->authWithAuthorizationCode($code, $redirect_uri);
         } catch (RennException $e) {
             throw new CHttpException(500, 'Error:' . $e->getMessage());
         }
     } else {
         throw new CHttpException(500, 'Auth Failed');
     }
     if ($token) {
         // 获得保存的token
         $rennClient->authWithStoredToken();
         // 获得用户接口
         $user_service = $rennClient->getUserService();
         // 获得用户信息
         $user = $user_service->getUser(null);
         if (!$user) {
             throw new CHttpException('500', Yii::t('common', 'Login Failed') . '(get userinfo failed)');
         }
         // 获取accessToken
         $access_token = $token->accessToken;
         $openid = $user['id'];
         //查看是否已绑定
         $bind = OAuthRenren::model()->findByPk($openid);
         //数据
         $data = array('type' => 'renren', 'access_token' => $access_token, 'openid' => $openid, 'uid' => $bind ? $bind->uid : 0, 'username' => $user['name'], 'avatar' => $user['avatar'][1]['url']);
         //绑定注册
         $this->controller->bind_register($bind, $data);
     } else {
         $this->controller->message('error', Yii::t('common', 'Login Failed') . '(renren_x_0000)', $this->createUrl('user/login'));
     }
 }
Пример #3
0
 /**
  * Identical to the parent constructor, except that
  * we start a PHP session to store the user ID and
  * access token if during the course of execution
  * we discover them.
  *
  * @param Array $config the application configuration.
  * @see RennClient::__construct in RennClient.php
  */
 public function __construct($clientId, $clientSecret)
 {
     if (!session_id()) {
         session_start();
     }
     parent::__construct($clientId, $clientSecret);
 }
Пример #4
0
 public static function oauthRoute($type)
 {
     global $kekezu, $weibo_list;
     require S_ROOT . "include/oauth/config.php";
     if ($type === 'sina') {
         require S_ROOT . "include/oauth/sina/saetv2.ex.class.php";
         $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
         $code_url = $o->getAuthorizeURL(WB_CALLBACK_URL);
     }
     if ($type === 'qq') {
         require S_ROOT . "include/oauth/qq/qqConnectAPI.php";
         $qqConnectAPI = new QC();
         $qqConnectAPI->qq_login();
         die;
     }
     if ($type === 'ten') {
         require S_ROOT . "include/oauth/ten/Tencent.php";
         OAuth::init(TEN_AKEY, TEN_SKEY);
         Tencent::$debug = false;
         $code_url = OAuth::getAuthorizeURL(TEN_CALLBACK_URL);
     }
     if ($type === 'renren') {
         require S_ROOT . "include/oauth/renren/rennclient/RennClient.php";
         $rennClient = new RennClient(APP_KEY, APP_SECRET);
         $state = uniqid('renren_', true);
         $_SESSION['renren_state'] = $state;
         $code_url = $rennClient->getAuthorizeURL(CALLBACK_URL, 'code', $state);
     }
     if ($type === 'douban') {
         require S_ROOT . 'include/oauth/douban/douban.php';
         $douBan = new doubanPHP(DB_APIKEY, DB_SECRET);
         $code_url = $douBan->login_url(DB_CALLBACK_URL, DB_SCOPE);
     }
     header("location:" . $code_url);
 }
Пример #5
0
<?php

session_start();
include_once 'config.php';
include_once '../rennclient/RennClient.php';
$renn_client = new RennClient(APP_KEY, APP_SECRET);
$renn_client->setDebug(DEBUG_MODE);
// 获得保存的token
$renn_client->authWithStoredToken();
// 获得用户接口
$user_service = $renn_client->getUserService();
// 获得指定用户
$user = $user_service->get(431695399);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>人人api2 demo</title>
</head>

<body>
	<!-- 用户头像 -->
	<img src="<?php 
echo $user['avatar'][1]['url'];
?>
" title="头像" alt="头像"
		border="0" />
	<br />
	<!-- 用户名 -->
<?php 
Пример #6
0
<?php

session_start();
include_once 'config.php';
include_once '../rennclient/RennClient.php';
// include_once ('renrenoauth/oauth2-client.class.php');
// include_once ('renrenoauth/renn-client.class.php');
$rennClient = new RennClient(APP_KEY, APP_SECRET);
$rennClient->setDebug(DEBUG_MODE);
// 生成state并存入SESSION,以供CALLBACK时验证使用
$state = uniqid('renren_', true);
$_SESSION['renren_state'] = $state;
// 得认证授权的url
$code_url = $rennClient->getAuthorizeURL(CALLBACK_URL, 'code', $state);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>人人 PHP SDK Demo</title>
</head>

<body>
	<!-- 打开认证授权的页面 -->
	<p>
		<a href="<?php 
echo $code_url;
?>
"><img
			src="http://s.xnimg.cn/imgpro/v6/logo.png?f=home" title="点击进入授权页面"
			alt="点击进入授权页面" border="0" /></a>
Пример #7
0
<?php

session_start();
include_once 'config.php';
include_once '../rennclient/RennClient.php';
$rennClient = new RennClient(APP_KEY, APP_SECRET);
$rennClient->setDebug(DEBUG_MODE);
// 处理code -- 根据code来获得token
if (isset($_REQUEST['code'])) {
    $keys = array();
    // 验证state,防止伪造请求跨站攻击
    $state = $_REQUEST['state'];
    if (empty($state) || $state !== $_SESSION['renren_state']) {
        echo '非法请求!';
        exit;
    }
    unset($_SESSION['renren_state']);
    // 获得code
    $keys['code'] = $_REQUEST['code'];
    $keys['redirect_uri'] = CALLBACK_URL;
    try {
        // 根据code来获得token
        $token = $rennClient->getTokenFromTokenEndpoint('code', $keys);
    } catch (RennException $e) {
        var_dump($e);
    }
}
if ($token) {
    print_r($token);
    ?>
授权完成,