2025-01-16 18:00:46 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\manystoreapi\controller;
|
|
|
|
|
|
2025-01-17 13:59:57 +08:00
|
|
|
|
use app\common\controller\ManystoreApiBase;
|
2025-01-16 18:00:46 +08:00
|
|
|
|
use fast\Random;
|
|
|
|
|
|
|
|
|
|
/**
|
2025-01-17 13:59:57 +08:00
|
|
|
|
* 机构API后台:Token接口
|
2025-01-16 18:00:46 +08:00
|
|
|
|
*/
|
2025-01-17 13:59:57 +08:00
|
|
|
|
class Token extends ManystoreApiBase
|
2025-01-16 18:00:46 +08:00
|
|
|
|
{
|
|
|
|
|
protected $noNeedLogin = [];
|
|
|
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检测Token是否过期
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function check()
|
|
|
|
|
{
|
|
|
|
|
$token = $this->auth->getToken();
|
2025-01-17 13:59:57 +08:00
|
|
|
|
// $tokenInfo = \app\common\library\Token::get($token);
|
|
|
|
|
$tokenInfo = \app\common\library\Token::init($this->auth->init_data)->get($token);
|
|
|
|
|
$this->apisuccess('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]);
|
2025-01-16 18:00:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 刷新Token
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function refresh()
|
|
|
|
|
{
|
|
|
|
|
//删除源Token
|
|
|
|
|
$token = $this->auth->getToken();
|
2025-01-17 13:59:57 +08:00
|
|
|
|
\app\common\library\Token::init($this->auth->init_data)->delete($token);
|
2025-01-16 18:00:46 +08:00
|
|
|
|
//创建新Token
|
|
|
|
|
$token = Random::uuid();
|
2025-01-17 13:59:57 +08:00
|
|
|
|
\app\common\library\Token::init($this->auth->init_data)->set($token, $this->auth->id, 2592000);
|
|
|
|
|
$tokenInfo = \app\common\library\Token::init($this->auth->init_data)->get($token);
|
|
|
|
|
$this->apisuccess('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]);
|
2025-01-16 18:00:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|