123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace app\api\controller;
- class AuthBase extends ApiBase
- {
- public $userId = 0;
- public $username = '';
- public $accessToken = '';
- public function initialize()
- {
- parent::initialize();
- $this->accessToken = $this->request->header('access-token');
- if (!$this->accessToken || !$this->isLogin()) {
- return $this->show(config('status.not_login'), '没有登录');
- }
- }
-
- public function isLogin(): bool
- {
- $userInfo = cache(config('redis.token_pre') . $this->accessToken);
- if (!$userInfo) {
- return false;
- }
- if (!empty($userInfo['id']) && !empty($userInfo['username'])) {
- $this->userId = $userInfo['id'];
- $this->username = $userInfo['username'];
- return true;
- }
- return false;
- }
- }
|