function bindSinaCallBack() { include_once SITE_PATH . '/addons/plugins/login/sina.class.php'; $sina = new sina(); $sina->checkUser(); if (!in_array($_SESSION['open_platform_type'], array('sina'))) { if ($this->isAjax()) { echo 0; exit; } else { $this->assign('jumpUrl', U('home/Account/bind') . '#sina'); $this->error(L('authorization_failed')); } } // 检查是否成功获取用户信息 $userinfo = $sina->userInfo(); if (!is_numeric($userinfo['id']) || !is_string($userinfo['uname'])) { $this->assign('jumpUrl', U('home/Account/bind') . '#sina'); $this->error(L('user_information_failed')); } $syncdata['uid'] = $this->mid; $syncdata['type_uid'] = $userinfo['id']; $syncdata['type'] = 'sina'; $syncdata['oauth_token'] = $_SESSION['sina']['access_token']['oauth_token']; $syncdata['oauth_token_secret'] = $_SESSION['sina']['access_token']['oauth_token_secret']; $syncdata['is_sync'] = '1'; if ($info = M('login')->where("type_uid={$userinfo['id']} AND type='sina'")->find()) { // 该新浪用户已在本站存在, 将其与当前用户关联(即原用户ID失效) M('login')->where("`login_id`={$info['login_id']}")->save($syncdata); } else { // 添加同步信息 M('login')->add($syncdata); } if (isset($_SESSION['weibo_bind_target_url'])) { $this->assign('jumpUrl', $_SESSION['weibo_bind_target_url']); unset($_SESSION['weibo_bind_target_url']); } else { $this->assign('jumpUrl', U('home/Account/bind') . '#sina'); } $this->success(L('bind_success')); }
private function _on_sina_logined() { include_once DOC_ROOT_PATH . 'Addons/plugins/login/sina.class.php'; $sina = new sina(); //检查是否已绑定帐号 $openid = $sina->get_openid(); $platformModel = M('user_platform'); $user = $platformModel->field('id,user_id')->where("`type`='sina' AND openid='{$openid}'")->find(); //已绑定 if ($user) { //从UC中获取资料并同步UC应用 $ucService = service('Uc'); $userService = service('User'); $_user = $ucService->get_user_info($user['user_id'], 1); if ($_user === null) { $platformModel->where("id='{$user['id']}'")->delete(); redirect(reUrl('User/bind?type=sina')); } $sina_u_info = $sina->userInfo(); $userService->after_logined(array('user_id' => $_user[0], 'nick' => $sina_u_info['screen_name'], 'avatar' => $sina_u_info['profile_image_url']), false); $_SESSION['login_type'] = '102'; $syncHtml = $ucService->build_synlogin($_user[0]); if (cookie('r_url')) { $this->assign('jumpUrl', cookie('r_url')); cookie('r_url', null); } else { $this->assign('jumpUrl', reUrl('User/index')); } $this->success('登陆成功' . $syncHtml); } else { redirect(reUrl('User/bind?type=sina')); } }