public function checkUser()
{
if ($_REQUEST['code'] && $_REQUEST['state'] == $_SESSION['state']) {
$token_url = 'https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=' . QZONE_KEY . '&code=' . $_REQUEST['code'] . '&client_secret=' . QZONE_SECRET . '&redirect_uri=' . $this->getCallback('qzone', $callbackurl);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $token_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if (strpos($response, 'callback') !== false) {
$lpos = strpos($response, '(');
$rpos = strrpos($response, ')');
$response = substr($response, $lpos + 1, $rpos - $lpos - 1);
$msg = json_decode($response);
if (isset($msg->error)) {
return false;
//echo "<h3>error:</h3>" . $msg->error;
//echo "<h3>msg :</h3>" . $msg->error_description;
//exit;
}
}
$params = array();
parse_str($response, $params);
$access_token = $params['access_token'];
$graph_url = 'https://graph.qq.com/oauth2.0/me?access_token=' . $access_token;
curl_setopt($ch, CURLOPT_URL, $graph_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if (strpos($response, 'callback') !== false) {
$lpos = strpos($response, '(');
$rpos = strrpos($response, ')');
$response = substr($response, $lpos + 1, $rpos - $lpos - 1);
}
$user = json_decode($response);
if (isset($user->error)) {
echo '<h3>error:</h3>' . $user->error;
echo '<h3>msg :</h3>' . $user->error_description;
exit;
} else {
$_SESSION['qzone']['access_token']['oauth_token'] = $access_token;
$_SESSION['qzone']['access_token']['oauth_token_secret'] = $user->openid;
$_SESSION['qzone']['isSync'] = 1;
$_SESSION['qzone']['openid'] = $user->openid;
//$_SESSION['qzone']['uid'] = $user->openid;
//$_SESSION['qzone']['uname'] = $res['user']['name'];
$_SESSION['open_platform_type'] = 'qzone';
}
} else {
return false;
}
return true;
}