Compare commits

..

6 Commits

Author SHA1 Message Date
as2252258 c095b69f67 改名 2021-07-09 10:41:31 +08:00
as2252258 4c8c5ac239 改名 2021-07-09 10:36:45 +08:00
as2252258 cfc847133e 改名 2021-07-09 10:34:27 +08:00
as2252258 30b430f1cf 改名 2021-07-08 19:16:27 +08:00
as2252258 516c7612a5 改名 2021-07-08 18:02:21 +08:00
as2252258 3bb3d5a1d7 改名 2021-07-08 17:36:28 +08:00
5 changed files with 401 additions and 371 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ abstract class HttpService extends Component
* @param string $category * @param string $category
* @throws Exception * @throws Exception
*/ */
protected function write($message, $category = 'app') protected function write($message, string $category = 'app')
{ {
$logger = Snowflake::app()->getLogger(); $logger = Snowflake::app()->getLogger();
$logger->write($message, $category); $logger->write($message, $category);
+3 -1
View File
@@ -35,7 +35,6 @@ use function Co\run;
* @package Snowflake * @package Snowflake
* *
* @property-read Config $config * @property-read Config $config
* @property-read WchatProviders $wchat
*/ */
class Application extends BaseApplication class Application extends BaseApplication
{ {
@@ -62,6 +61,9 @@ class Application extends BaseApplication
} }
/** /**
* @param Closure|array $closure * @param Closure|array $closure
* @return $this * @return $this
+22 -2
View File
@@ -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
* *
+9 -1
View File
@@ -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']);
} }
+1 -1
View File
@@ -42,7 +42,7 @@ abstract class Process extends \Swoole\Process implements SProcess
fire(Event::SERVER_WORKER_START); fire(Event::SERVER_WORKER_START);
if (Snowflake::getPlatform()->isLinux()) { if (Snowflake::getPlatform()->isLinux()) {
swoole_set_process_name($this->getProcessName()); name($this->pid, $this->getProcessName());
} }
if (method_exists($this, 'before')) { if (method_exists($this, 'before')) {
$this->before($process); $this->before($process);