/**
* sina绑定
*/
function bindSina()
{
$code = $this->trimmed('code');
if (empty($code)) {
$this->clientError('cannot find sina code, oauth failed', $code);
exit;
}
$keys = array();
$keys['code'] = $code;
$keys['redirect_uri'] = WB_CALLBACK_URL;
try {
$sinaOauth = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
$token = $sinaOauth->getAccessToken('code', $keys);
} catch (OAuthException $e) {
$this->clientError("oauth failed {$e}", 400);
exit;
}
$url = 'https://api.weibo.com/2/users/show.json?' . http_build_query(array('access_token' => $token['access_token'], 'uid' => $token['uid']));
$user = json_decode(file_get_contents($url));
if (array_key_exists("error", $user)) {
$this->clientError($user, 400);
}
$userOption = array('via' => 'weibo', 'uid' => $user->id, 'screen_name' => $user->screen_name, 'name' => $user->name, 'location' => $user->location, 'description' => $user->description, 'image' => $user->profile_image_url, 'access_token' => $token->access_token, 'expire_at' => $token->expires, 'refresh_token' => $token->refresh_token);
$this->bind_common($user->id, User::PLATFORM_TYPE_SINA, $userOption);
}