<?php session_start(); include_once './class/db.class.php'; require_once 'class/requires.php'; header('Content-Type: text/html; charset=utf-8'); //判断session是否设置,到授权页面 if (isset($_SESSION['access_token'])) { $oauth = new RenRenOauth(); try { $key = $oauth->getSessionKey($_SESSION['access_token']); } catch (Exception $e) { } if (isset($key)) { $_SESSION['key'] = $key; header("Location: home.php"); } else { header("Location: modular/logout.php"); } } else { header("Location: login.php"); }
if (WEB_TEST) { $_SESSION['id'] = 1; } //没$_SESSION['id'] 直接回到登陆处。 if (!isset($_SESSION['id'])) { header("Location: ./modular/login.php"); } //根据$_SESSION['id']读出用户信息 $db = new DB(); $sql = "SELECT * FROM " . DB_TABLE_PREFIX . "renren_user WHERE `w_id` = {$_SESSION['id']} LIMIT 0,1"; $result = $db->get_one($sql); if ($result && time() - $result['token_insert_time'] < EXPIRES_IN && !empty($result['access_token'])) { /***重定向到人人主页***/ $oauth = new RenRenOauth(); try { $key = $oauth->getSessionKey($result['access_token']); } catch (Exception $e) { } if (isset($key)) { $_SESSION['key'] = $key; header("Location: home.php"); } else { header("Location: modular/logout.php"); } } elseif ($result && time() - $result['token_insert_time'] < EXPIRES_IN * 2 && !empty($result['refresh_token'])) { /***重定向到refresh_token刷新token***/ header("Location: ./class/refresh_token.php"); } else { /***大于2个月没登陆,要到人人网重新授权***/ header("Location: ./modular/authorize.php"); // echo '很久没有登录';
<?php require_once '../../requires.php'; $oauth = new RenRenOauth(); $access_token = $_GET['access_token']; $key = $oauth->getSessionKey($access_token); var_dump($key); echo '<br/><br/>'; ?> <a href="../api/5_api.php?session_key=<?php echo $key['renren_token']['session_key']; ?>">Test Api</a>
} elseif ($_SESSION['wp_url_login'] == "renren") { $config = new stdClass(); $config->CALLBACK = $backurl; $config->APIKey = WEIBO_APP_KEY; $config->SecretKey = WEIBO_SECRET; class_exists('RenRenOauth') or (require dirname(__FILE__) . '/OAuth/renren.class.php'); $code = $_GET['code']; $oauth = new RenRenOauth(); $token = $oauth->getAccessToken($code); if (!$token['access_token']) { return var_dump($token); } $access_token = explode("|", $token['access_token']); $session_key = $access_token[1]; if (!$session_key) { $key = $oauth->getSessionKey($token['access_token']); if (!$key['renren_token']['session_key']) { return var_dump($key); } $session_key = $key['renren_token']['session_key']; $expires_in = $key['renren_token']['expires_in']; $get_session = true; } else { $expires_in = $token['expires_in']; } // return var_dump($result); $oauth_token = array('session_key' => $session_key, 'refresh_token' => $token['refresh_token'], 'expires_in' => BJTIMESTAMP + $expires_in); } } if (is_user_logged_in() && $_SESSION['sync_bind']) { // 同步绑定