/** * 获得OAuth 对象 * @return OpenSDK_OAuth_Client */ protected static function getOAuth() { if (null === self::$oauth) { self::$oauth = new OpenSDK_OAuth_Client(self::$_appsecret, self::$_debug); $secret = self::getParam(self::OAUTH_TOKEN_SECRET); if ($secret) { self::$oauth->setTokenSecret($secret); } } return self::$oauth; }
$exit = true; } else { if (isset($_GET['oauth_token'])) { //从Callback返回时 if (OpenSDK_163_Weibo::getAccessToken()) { $uinfo = OpenSDK_163_Weibo::call('users/show'); echo '从Opent返回并获得授权。你的微博帐号信息为:<br />'; echo 'Access token: ', OpenSDK_163_Weibo::getParam(OpenSDK_163_Weibo::ACCESS_TOKEN), '<br />'; echo 'oauth_token_secret: ', OpenSDK_163_Weibo::getParam(OpenSDK_163_Weibo::OAUTH_TOKEN_SECRET), '<br />'; echo '你的微博帐号信息为:<br /><pre>'; var_dump($uinfo); } else { echo '获得Access Tokn 失败'; } $exit = true; } else { if (isset($_GET['go_oauth'])) { $callback = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; $request_token = OpenSDK_163_Weibo::getRequestToken($callback); !$request_token && exit('获取request_token失败,请检查网络或者appkey和appsecret是否正确'); $url = OpenSDK_163_Weibo::getAuthorizeURL($request_token, $callback); header('Location: ' . $url); } else { echo '网易微博OAuth1.0接口演示<a href="?go_oauth">点击去授权</a>'; } } } } if ($exit) { echo '<a href="?exit">退出再来一次</a>'; }