Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c095b69f67 | |||
| 4c8c5ac239 | |||
| cfc847133e | |||
| 30b430f1cf |
+22
-2
@@ -5,11 +5,12 @@ namespace Snowflake\Jwt;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use HttpServer\Http\HttpHeaders;
|
use HttpServer\Http\HttpHeaders;
|
||||||
use Snowflake\Cache\Redis;
|
use Snowflake\Abstracts\Component;
|
||||||
use Snowflake\Abstracts\Config;
|
use Snowflake\Abstracts\Config;
|
||||||
|
use Snowflake\Cache\Redis;
|
||||||
|
use Snowflake\Core\Json;
|
||||||
use Snowflake\Core\Str;
|
use Snowflake\Core\Str;
|
||||||
use Snowflake\Exception\AuthException;
|
use Snowflake\Exception\AuthException;
|
||||||
use Snowflake\Abstracts\Component;
|
|
||||||
use Snowflake\Exception\ConfigException;
|
use Snowflake\Exception\ConfigException;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
|
|
||||||
@@ -222,6 +223,25 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
|
|||||||
return $this->create($this->user, $headers);
|
return $this->create($this->user, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $headers
|
||||||
|
* @return mixed
|
||||||
|
* @throws AuthException
|
||||||
|
*/
|
||||||
|
public function getTokenUser(array $headers = []): int
|
||||||
|
{
|
||||||
|
$this->data = $headers;
|
||||||
|
if (!openssl_public_decrypt(base64_decode($headers['refresh']), $data, $this->public)) {
|
||||||
|
throw new AuthException('信息解码失败.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = Json::decode($data, true);
|
||||||
|
|
||||||
|
return (int)$data['user'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $param
|
* @param array $param
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -81,6 +81,11 @@ class ClientsPool extends Component
|
|||||||
{
|
{
|
||||||
if (env('state') == 'exit') {
|
if (env('state') == 'exit') {
|
||||||
Timer::clear($this->creates);
|
Timer::clear($this->creates);
|
||||||
|
foreach (static::$_connections as $channel) {
|
||||||
|
$this->flush($channel, 0);
|
||||||
|
$channel->close();
|
||||||
|
}
|
||||||
|
static::$_connections = [];
|
||||||
$this->creates = -1;
|
$this->creates = -1;
|
||||||
} else {
|
} else {
|
||||||
$this->heartbeat_flush();
|
$this->heartbeat_flush();
|
||||||
@@ -131,7 +136,6 @@ class ClientsPool extends Component
|
|||||||
public function flush($channel, $retain_number)
|
public function flush($channel, $retain_number)
|
||||||
{
|
{
|
||||||
$this->pop($channel, $retain_number);
|
$this->pop($channel, $retain_number);
|
||||||
static::$_connections = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -180,12 +184,16 @@ class ClientsPool extends Component
|
|||||||
* @param $name
|
* @param $name
|
||||||
* @return Channel
|
* @return Channel
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function getChannel($name): Channel
|
private function getChannel($name): Channel
|
||||||
{
|
{
|
||||||
if (!isset(static::$_connections[$name])) {
|
if (!isset(static::$_connections[$name])) {
|
||||||
static::$_connections[$name] = new Channel(Config::get('databases.pool.max', 10));
|
static::$_connections[$name] = new Channel(Config::get('databases.pool.max', 10));
|
||||||
}
|
}
|
||||||
|
if (static::$_connections[$name]->errCode == SWOOLE_CHANNEL_CLOSED){
|
||||||
|
throw new Exception('Channel is Close.');
|
||||||
|
}
|
||||||
if ($this->creates === -1) {
|
if ($this->creates === -1) {
|
||||||
$this->creates = Timer::tick(60000, [$this, 'Heartbeat_detection']);
|
$this->creates = Timer::tick(60000, [$this, 'Heartbeat_detection']);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user