Token.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use fast\Random;
  5. /**
  6. * Token接口
  7. */
  8. class Token extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = '*';
  12. public function __construct(){
  13. $this->error('投票活动结束了');
  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
  32. $token = $this->auth->getToken();
  33. \app\common\library\Token::delete($token);
  34. //创建新Token
  35. $token = Random::uuid();
  36. \app\common\library\Token::set($token, $this->auth->id, 2592000);
  37. $tokenInfo = \app\common\library\Token::get($token);
  38. $this->success('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]);
  39. }
  40. }