Token.php 986 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. /**
  5. * Token接口
  6. */
  7. class Token extends Api
  8. {
  9. protected $noNeedLogin = [];
  10. protected $noNeedRight = '*';
  11. public function _initialize()
  12. {
  13. parent::_initialize();
  14. }
  15. /**
  16. * 检测Token是否过期
  17. *
  18. */
  19. public function check()
  20. {
  21. $token = $this->auth->getToken();
  22. $tokenInfo = \app\common\library\Token::get($token);
  23. $this->success('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]);
  24. }
  25. /**
  26. * 刷新Token
  27. *
  28. */
  29. public function refresh()
  30. {
  31. $token = $this->auth->getToken();
  32. $tokenInfo = \app\common\library\Token::get($token);
  33. $tokenInfo->expiretime = time() + 2592000;
  34. $tokenInfo->save();
  35. $this->success('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]);
  36. }
  37. }