1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace app\common\token;
- use think\facade\Config;
- abstract class Driver
- {
-
- protected $handler = null;
-
- protected $options = [];
-
- abstract function set(string $token, string $type, array $userinfo, int $expire = 0): bool;
-
- abstract function get(string $token, bool $expirationException = true): array;
-
- abstract function check(string $token, string $type, array $userinfo, bool $expirationException = true): bool;
-
- abstract function delete(string $token): bool;
-
- abstract function clear(string $type, int $user_id): bool;
-
- public function handler(): ?object
- {
- return $this->handler;
- }
-
- protected function getEncryptedToken(string $token): string
- {
- $config = Config::get('token');
- return hash_hmac($config['algo'], $token, $config['key']);
- }
-
- protected function getExpiredIn(int $expiretime): int
- {
- return $expiretime ? max(0, $expiretime - time()) : 365 * 86400;
- }
- }
|