This commit is contained in:
2020-09-11 20:06:06 +08:00
parent 8795608259
commit 955171e180
5 changed files with 14 additions and 82 deletions
+12 -27
View File
@@ -64,9 +64,6 @@ kIHG5j+Qga2CgXqI2Y5URXGz5XlsNbMNFUrnWcbpqEbW5O6/BgHLLSDEyQgwbygN
mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY= mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
-----END RSA PRIVATE KEY-----'; -----END RSA PRIVATE KEY-----';
/** @var Jwt */
private static $instance;
/** /**
* @throws ConfigException * @throws ConfigException
@@ -106,16 +103,6 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
$this->private = $privateKey; $this->private = $privateKey;
} }
/**
* @return Jwt
*/
private static function getInstance()
{
if (!(static::$instance instanceof Jwt)) {
static::$instance = new Jwt();
}
return static::$instance;
}
/** /**
* @param int|string $unionId * @param int|string $unionId
@@ -272,7 +259,7 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
* @return string * @return string
* @throws Exception * @throws Exception
*/ */
private function authKey($_source, $token) private function authKey(string $_source, string $token)
{ {
$source = $this->getSource(); $source = $this->getSource();
if (!empty($_source)) $source = $_source; if (!empty($_source)) $source = $_source;
@@ -297,7 +284,7 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
* *
* @return string * @return string
*/ */
private function token($user, $param = [], $requestTime = NULL) private function token(int $user, $param = [], $requestTime = NULL)
{ {
$str = ''; $str = '';
@@ -319,7 +306,7 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
* @return mixed * @return mixed
* 将字符串替换成指定格式 * 将字符串替换成指定格式
*/ */
private function preg($str) private function preg(string $str)
{ {
$preg = '/(\w{10})(\w{3})(\w{4})(\w{9})(\w{6})/'; $preg = '/(\w{10})(\w{3})(\w{4})(\w{9})(\w{6})/';
return preg_replace($preg, '$1-$2-$3-$4-$5', $str); return preg_replace($preg, '$1-$2-$3-$4-$5', $str);
@@ -328,9 +315,9 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
/** /**
* @param int $user * @param int $user
* @return string[] * @return string[]
* @throws * @throws Exception
*/ */
public function clear($user) public function clear(int $user)
{ {
$this->user = $user; $this->user = $user;
$redis = $this->getRedis(); $redis = $this->getRedis();
@@ -353,9 +340,9 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
* @param array $data * @param array $data
* @param int $user * @param int $user
* @return bool * @return bool
* @throws * @throws AuthException
*/ */
public function check($data, $user) public function check(array $data, int $user)
{ {
$this->data = $data; $this->data = $data;
$this->user = $user; $this->user = $user;
@@ -382,16 +369,13 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
$this->data = request()->headers->getHeaders(); $this->data = request()->headers->getHeaders();
$model = $this->getUserModel(); $model = $this->getUserModel();
if (empty($model)) { if (empty($model)) {
return '授权信息已过期!'; throw new AuthException('授权信息已过期!');
// throw new AuthException('授权信息已过期!');
} }
if (!isset($model['user'])) { if (!isset($model['user'])) {
return '授权信息错误!'; throw new AuthException('授权信息错误!');
// throw new AuthException('授权信息错误!');
} }
if (!$this->check($this->data, $model['user'])) { if (!$this->check($this->data, $model['user'])) {
return '授权信息不合法!'; throw new AuthException('授权信息不合法!');
// throw new AuthException('授权信息不合法!');
} }
$this->expireRefresh(); $this->expireRefresh();
@@ -400,11 +384,12 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
/** /**
* @param array $header * @param array $header
* @return false|mixed
* @throws Exception * @throws Exception
*/ */
public static function checkAuth(array $header = []) public static function checkAuth(array $header = [])
{ {
$instance = static::getInstance(); $instance = Snowflake::app()->getJwt();
if (empty($header)) { if (empty($header)) {
$header = request()->headers->getHeaders(); $header = request()->headers->getHeaders();
} }
-29
View File
@@ -1,29 +0,0 @@
<?php
namespace Snowflake\Process;
use Exception;
use Snowflake\Snowflake;
use Swoole\Timer;
/**
* Class Logfilemonitoring
*/
class Leafleting extends Process
{
/**
* @param \Swoole\Process $process
* @return mixed|void
* @throws Exception
*/
public function onHandler(\Swoole\Process $process)
{
Timer::tick(1000, function () use ($process) {
var_dump($process->read());
});
}
}
-12
View File
@@ -1,12 +0,0 @@
<?php
namespace Snowflake\Process;
use Snowflake\Abstracts\Component;
abstract class System extends Component implements ISystem
{
}
-13
View File
@@ -1,13 +0,0 @@
<?php
use Snowflake\Process\Leafleting;
use Snowflake\Process\ServerInotify;
return [
'processes' => [
'Leafleting' => Leafleting::class,
'inotify' => ServerInotify::class,
]
];
+2 -1
View File
@@ -26,7 +26,8 @@
"ext-xml": "*", "ext-xml": "*",
"ext-memcached": "*", "ext-memcached": "*",
"ext-inotify": "*", "ext-inotify": "*",
"ext-curl": "*" "ext-curl": "*",
"ext-openssl": "*"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {