where('expire','>',$time)->field('mobile')->value('user_id'); return $user?User::where('id',$user)->field($this->allowFields)->find()->toArray():false; } public function logout() { $adapter = new MysqlAdapter(); $adapter->logout(); } public static function getToken($token):int { $time=time(); return UserToken::where('token',$token)->where('expire','>',$time)->count(); } //登录 public function login(string $username, string $password) { $token= uuid(); $user=User::where('username',$username)->find(); if(!$user){ throw new \Exception('账号或密码错误'); } if($user->password!=md5(md5($password.$user->salt))){ throw new \Exception('账号或密码错误'); } if($user->status!='normal'){ throw new \Exception('账号已经被禁用'); } $adapter = new MysqlAdapter(); $token = $adapter->login($token,$user); $this->login_user=$adapter->userinfo(); return ['userinfo' => $this->login_user, 'token' => $token]; } public function loginByMobile(string $mobile, string $code) { // TODO: Implement loginByMobile() method. } public function updateToken(array $arr) { $usertoken=$this->adapter->getUserToken(); UserToken::where('id',$usertoken->id)->update($arr); } }