Пример #1
0
 public function checkUser()
 {
     if (empty($this->_douban_key) || empty($this->_douban_secret) || empty($_SESSION['douban']['request_token']['oauth_token']) || empty($_SESSION['douban']['request_token']['oauth_token_secret'])) {
         return false;
     }
     $client = new DoubanOAuth($this->_douban_key, $this->_douban_secret, $_SESSION['douban']['request_token']['oauth_token'], $_SESSION['douban']['request_token']['oauth_token_secret']);
     $access_token = $client->getAccessToken();
     if ($access_token['oauth_token']) {
         $_SESSION['douban']['access_token'] = $access_token;
         $_SESSION['open_platform_type'] = 'douban';
         return true;
     } else {
         return false;
     }
 }
 * @author cluries
 * @link http://cdbit.com
 * @version 1.0
 * @copyright 2012 http://cdbit.com All rights reserved
 * 
 * *********************************************************
 */
if (islocked('douban')) {
    display(_er('E_LOCKED', 'douban', 'douban'), 0);
}
if (empty($_REQUEST['oauth_token'])) {
    display(_er('E_404'), 0);
}
if ($_SESSION['douban_token'] != $_REQUEST['oauth_token']) {
    retry();
}
import('/library/OAuth.php');
import('/library/doubanoauth.php');
global $cfg_douban;
$o = new DoubanOAuth($cfg_douban['key'], $cfg_douban['secret'], $_SESSION['douban_token'], $_SESSION['douban_token_secret']);
$token = $o->getAccessToken();
if (!empty($token['oauth_token_secret']) && !empty($token['oauth_token'])) {
    Encryption::serializeToFile($token, tmpDir('douban.oauth'));
    lockit('douban');
    display('douban认证成功');
}
display('douban认证失败');
function retry()
{
    Header("Location:install.php?action=auth");
}
Пример #3
0
<?php

include "init.php";
//ROOT_URL./api.php?app=begin & account=douban
switch ($_GET['app']) {
    case "begin":
        $douban = new DoubanOAuth($douban_consumer_key, $douban_consumer_secret);
        $tok = $douban->getRequestToken();
        $url = $douban->getAuthorizeURL($tok['oauth_token']) . "&oauth_callback=";
        //$url .= $_SEVERAL[PHP_SELF]."?request_token=".$tok['oauth_token']."&request_token_secret=".$tok['oauth_token_secret'];
        $arr = array_merge($tok, array("url" => $url));
        $out = json_encode($arr);
        echo $out;
        break;
    case "access":
        $tok = $_GET["request_token"];
        $tok_s = $_GET["request_token_secret"];
        $douban = new DoubanOAuth($douban_consumer_key, $douban_consumer_secret, $tok, $tok_s);
        $access = $douban->getAccessToken();
        $out = json_encode($access);
        if (!check_user("douban", $access['douban_user_id'])) {
            add_user("douban", $access['douban_user_id']);
        }
        echo $out;
        break;
}
exit;
Пример #4
0
<?php

defined('IN_TS') or die('Access Denied.');
require 'DoubanOAuth.php';
require 'config.php';
$douban = new DoubanOAuth(array('key' => KEY, 'secret' => SECRET, 'redirect_url' => REDIRECT));
$result = $douban->getAccessToken($_GET['code']);
//print_r($result);exit;
$access_token = $result['access_token'];
$openid = $result['douban_user_id'];
//cookie10天
setcookie("douban_access_token", $access_token, time() + 3600 * 24 * 10);
setcookie("douban_openid", $openid, time() + 3600 * 24 * 10);
/*ThinkSAAS开始*/
if ($openid) {
    $strOpen = $new['pubs']->find('user_open', array('sitename' => 'douban', 'openid' => $openid));
    //10天更换一次access_token
    if (time() - 10 * 86400 > $strOpen['uptime']) {
        $new['pubs']->update('user_open', array('sitename' => 'douban', 'openid' => $openid), array('access_token' => $access_token, 'uptime' => time()));
    }
    if ($strOpen['userid']) {
        $userData = $new['pubs']->find('user_info', array('userid' => $strOpen['userid']), 'userid,username,path,face,isadmin,signin,uptime');
        //更新登录时间
        $new['pubs']->update('user_info', array('userid' => $strOpen['userid']), array('ip' => getIp(), 'uptime' => time()));
        $_SESSION['tsuser'] = $userData;
        header("Location: " . SITE_URL);
        exit;
    } else {
        //获取用户基本资料
        $arrUserInfo = $douban->get('user/~me');
        //print_r($arrUserInfo);exit;