where(['id' => $userId])->findOrEmpty()->toArray(); $userInfo['has_password'] = empty($userInfo['password']) ? 0 : 1; unset($userInfo['password'], $userInfo['salt']); return $userInfo; } /** * 生成token * @access protected * @param int $id * @return string */ public static function buildToken(int $id = 0): string { return md5(Random::alpha(16) . $id . time()); } /** * 获取token * return string */ public static function getToken(): string { $token = request()->header('Authorization') ?: request()->header('token'); return $token ?? input('token', request()->cookie('token')) ?: 'undefined'; } /** * 校验token * @access protected * @param string $token * @return mixed * @throws InvalidArgumentException */ public static function checkToken(string $token): mixed { return Cache::get($token) ?? 0; } }