DiverseYouthNightSchool/application/manystoreapi/controller/Token.php

44 lines
1.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\manystoreapi\controller;
use app\common\controller\ManystoreApiBase;
use fast\Random;
/**
* 机构API后台Token接口
*/
class Token extends ManystoreApiBase
{
protected $noNeedLogin = [];
protected $noNeedRight = '*';
/**
* 检测Token是否过期
*
*/
public function check()
{
$token = $this->auth->getToken();
// $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']]);
}
/**
* 刷新Token
*
*/
public function refresh()
{
//删除源Token
$token = $this->auth->getToken();
\app\common\library\Token::init($this->auth->init_data)->delete($token);
//创建新Token
$token = Random::uuid();
\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']]);
}
}