/** * QQ登录 * * - 首次绑定时,会自动创建新用户 * - 当逻辑有冲突,或者数据库写入失败时,以异常返回 */ public function qq() { $rs = array('code' => 0, 'info' => array(), 'msg' => ''); $domain = new Domain_User_User_Login_Qq(); $isFirstBind = $domain->isFirstBind($this->openId); $userId = 0; if ($isFirstBind) { $userId = Domain_User_User_Generator::createUserForQq($this->openId, $this->nickname, $this->avatar); if ($userId <= 0) { //异常1:用户创建失败 DI()->logger->error('failed to create qq user', array('openId' => $this->openId)); throw new PhalApi_Exception_InternalServerError(T('failed to create qq user')); } $id = $domain->bindUser($userId, $this->openId, $this->token, $this->expiresIn); if ($id <= 0) { //异常2:绑定新浪微博失败 DI()->logger->error('failed to bind user with qq', array('userid' => $userid, 'openId' => $this->openId)); throw new PhalApi_Exception_InternalServerError(T('failed to bind user with qq')); } } else { $userId = $domain->getUserIdByQqOpenId($this->openId); } if ($userId <= 0) { //异常3:新浪用户不存在 DI()->logger->error('qq user not found', array('userid' => $userid, 'openId' => $this->openId)); throw new PhalApi_Exception_InternalServerError(T('qq user not found')); } $token = Domain_User_User_Session::generate($userId); $rs['info']['user_id'] = $userId; $rs['info']['token'] = $token; $rs['info']['is_new'] = $isFirstBind ? 1 : 0; return $rs; }
/** * 心跳 * * - 自动续期 */ public static function heatbeat() { self_renewalTo($_SERVER['REQUEST_TIME'] + Domain_User_User_Session::getMaxExpireTime()); }