예제 #1
0
 public function userInfo()
 {
     if (empty($this->_douban_key) || empty($this->_douban_secret) || empty($_SESSION['douban']['access_token']['oauth_token']) || empty($_SESSION['douban']['access_token']['oauth_token_secret'])) {
         return false;
     }
     $client = new DoubanOAuth($this->_douban_key, $this->_douban_secret, $_SESSION['douban']['access_token']['oauth_token'], $_SESSION['douban']['access_token']['oauth_token_secret']);
     $res = $client->OAuthRequest('http://api.douban.com/people/%40me', array(), 'GET');
     $res = simplexml_load_string($res);
     $uid_and_icon = $this->__getUidAndIcon($res->link);
     $userInfo['id'] = $uid_and_icon['id'];
     $userInfo['uname'] = (string) $res->title;
     $userInfo['userface'] = $uid_and_icon['icon'];
     $userInfo['signature'] = (string) $res->content;
     $userInfo['location'] = (string) $res->children('http://www.douban.com/xmlns/')->location;
     return $userInfo;
 }
 * @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

require 'DoubanOAuth.php';
require 'config.php';
$douban = new DoubanOAuth();
$result = $douban->get('book/search', array('q' => $_GET['q']));
print_r($douban->http_code, $result);
예제 #5
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;
예제 #6
0
<?php

require 'DoubanOAuth.php';
require 'config.php';
$douban = new DoubanOAuth(array('key' => KEY, 'secret' => SECRET, 'redirect_url' => REDIRECT));
$url = $douban->getAuthorizeURL(SCOPE, STATE);
//echo '<a href="' . $url . '">使用豆瓣帐号登录</a>';
header('Location: ' . $url);
예제 #7
0
<?php

/*
 * API.php
 */
include "init.php";
//ROOT_URL./api.php?app=begin & account=douban
//$access_token = "d2a19c5dcafe6d3d77e4d51960fb47b7";
//$access_token_secret = "ff8a8ca4b8a411fe";
$access_token = $_POST['access_token'];
$access_token_secret = $_POST['access_token_secret'];
$douban = new DoubanOAuth($douban_consumer_key, $douban_consumer_secret, $access_token, $access_token_secret);
$doubanInfo = $douban->OAuthRequest('http://api.douban.com/people/%40me', array(), 'GET');
if ($doubanInfo == "no auth") {
    echo 'Wrong Auth';
    exit;
}
$doubanInfo = simplexml_load_string($doubanInfo);
//print_r($doubanInfo);
$douban_id = str_replace("http://api.douban.com/people/", "", $doubanInfo->id);
$uid = check_user("douban", $douban_id);
//echo $douban_id;
//echo $uid ;
if (!$uid) {
    exit;
}
$user = new User($uid);
switch ($_GET['app']) {
    case "myinfo":
        $out = json_encode($arr);
        echo $out;
예제 #8
0
function doubanJMP__()
{
    import('/library/OAuth.php');
    import('/library/doubanoauth.php');
    $type = 'douban';
    global $cfg_douban;
    $o = new DoubanOAuth($cfg_douban['key'], $cfg_douban['secret']);
    $token = $o->getRequestToken();
    $_SESSION['douban_token'] = $token['oauth_token'];
    $_SESSION['douban_token_secret'] = $token['oauth_token_secret'];
    $authorizeURL = $o->getAuthorizeURL($token, callbackUrl($type));
    header("Location:{$authorizeURL}");
}