diff --git a/app/Models/UserDevice.php b/app/Models/UserDevice.php index 6586503a3..f61c8d1aa 100644 --- a/app/Models/UserDevice.php +++ b/app/Models/UserDevice.php @@ -210,7 +210,7 @@ class UserDevice extends AbstractModel $row = self::whereHash($hash)->first(); if ($row) { // 判断是否过期 - if (Carbon::parse($row->expired_at)->isPast()) { + if ($row->expired_at && Carbon::parse($row->expired_at)->isPast()) { self::forget($row); return null; } @@ -237,11 +237,11 @@ class UserDevice extends AbstractModel if (empty($token)) { $token = Doo::userToken(); $userid = Doo::userId(); - $expiredAt = Doo::userExpiredAt() ?: null; + $expiredAt = Doo::userExpiredAt(); } else { $info = Doo::tokenDecode($token); $userid = $info['userid'] ?? 0; - $expiredAt = $info['expired_at'] ?? null; + $expiredAt = $info['expired_at']; } $deviceData = [ 'detail' => Base::array2json(self::getDeviceInfo($_SERVER['HTTP_USER_AGENT'] ?? '')), diff --git a/app/Module/Doo.php b/app/Module/Doo.php index 0cff79b00..ea5547bfd 100644 --- a/app/Module/Doo.php +++ b/app/Module/Doo.php @@ -181,12 +181,12 @@ class Doo /** * token过期时间(来自请求的token) - * @return string + * @return string|null */ - public static function userExpiredAt(): string + public static function userExpiredAt(): ?string { $expiredAt = self::string(self::doo()->userExpiredAt()); - return $expiredAt === 'forever' ? '' : $expiredAt; + return $expiredAt === 'forever' ? null : $expiredAt; } /** @@ -263,7 +263,9 @@ class Doo */ public static function tokenDecode($token): array { - return Base::json2array(self::string(self::doo()->tokenDecode($token))); + $array = Base::json2array(self::string(self::doo()->tokenDecode($token))); + $array['expired_at'] = $array['expired_at'] === 'forever' ? null : $array['expired_at']; + return $array; } /**