/** * 获得OAuth 对象 * @return OpenSDK_OAuth_Client */ protected static function getOAuth() { if (null === self::$oauth) { self::$oauth = new OpenSDK_OAuth_QQSNSClient(self::$_appsecret, self::$_debug); $secret = self::getParam(self::OAUTH_TOKEN_SECRET); if ($secret) { self::$oauth->setTokenSecret($secret); } } return self::$oauth; }
} else { if (isset($_GET['oauth_token']) && isset($_GET['oauth_vericode'])) { //从Callback返回时 if (OpenSDK_Tencent_SNS::getAccessToken($_GET['oauth_vericode'])) { $uinfo = OpenSDK_Tencent_SNS::call('user/get_user_info'); echo '从Opent返回并获得授权。你的QQ空间帐号信息为:<br />'; echo 'Access token: ', OpenSDK_Tencent_SNS::getParam(OpenSDK_Tencent_SNS::ACCESS_TOKEN), '<br />'; echo 'oauth_token_secret: ', OpenSDK_Tencent_SNS::getParam(OpenSDK_Tencent_SNS::OAUTH_TOKEN_SECRET), '<br />'; echo 'openid: ', OpenSDK_Tencent_SNS::getParam(OpenSDK_Tencent_SNS::OAUTH_OPENID), '<br />'; echo '你的QQ空间帐号信息为:<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_Tencent_SNS::getRequestToken(); !$request_token && exit('获取request_token失败,请检查网络或者appkey和appsecret是否正确'); $url = OpenSDK_Tencent_SNS::getAuthorizeURL($request_token, $callback); header('Location: ' . $url); } else { echo '腾讯QQ登陆OAuth1.0接口演示<a href="?go_oauth">点击去授权</a>'; } } } } if ($exit) { echo '<a href="?exit">退出再来一次</a>'; }