改名
This commit is contained in:
@@ -12,7 +12,7 @@ use Kiri\Kiri;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Server\Constrict\ResponseInterface;
|
||||
use Http\Constrict\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Class CoreMiddleware
|
||||
|
||||
+12
-5
@@ -8,8 +8,10 @@ use Exception;
|
||||
use Http\Constrict\RequestInterface;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Kiri\Cache\Redis;
|
||||
use Kiri\Core\Json;
|
||||
use Kiri\Exception\ConfigException;
|
||||
use Kiri\Kiri;
|
||||
|
||||
|
||||
/**
|
||||
@@ -80,7 +82,13 @@ class Jwt extends Component
|
||||
if (!isset($this->data['source'])) {
|
||||
$this->data['source'] = 'browser';
|
||||
}
|
||||
return $this->createEncrypt($unionId);
|
||||
$token = $this->createEncrypt($unionId);
|
||||
if ($this->oos) {
|
||||
$redis = Kiri::getDi()->get(Redis::class);
|
||||
$redis->set('_jwt:token:' . $unionId, $token);
|
||||
$redis->expire('_jwt:token:' . $unionId, $this->timeout);
|
||||
}
|
||||
return $token;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,14 +97,13 @@ class Jwt extends Component
|
||||
*/
|
||||
private function jwtHeader(): string
|
||||
{
|
||||
$string = openssl_encrypt(
|
||||
json_encode(['type' => 'openssl', 'encrypt' => $this->encrypt]),
|
||||
return openssl_encrypt(
|
||||
json_encode(['type' => 'openssl', 'encrypt' => $this->encrypt], JSON_UNESCAPED_UNICODE),
|
||||
$this->encrypt,
|
||||
$this->key,
|
||||
0,
|
||||
$this->iv
|
||||
);
|
||||
return str_replace('=', '', $string);
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +114,7 @@ class Jwt extends Component
|
||||
*/
|
||||
private function jwtBody($unionId): string
|
||||
{
|
||||
$json = json_encode(['unionId' => $unionId, 'createTime' => time(), 'expire_at' => time() + $this->timeout]);
|
||||
$json = json_encode(['unionId' => $unionId, 'createTime' => time(), 'expire_at' => time() + $this->timeout], JSON_UNESCAPED_UNICODE);
|
||||
openssl_private_encrypt($json, $encode, $this->private);
|
||||
return base64_encode($encode);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,12 @@ trait JwtHelper
|
||||
private string $iv = '';
|
||||
|
||||
|
||||
private string $iss = 'jwt.service';
|
||||
|
||||
|
||||
private bool $oos = false;
|
||||
|
||||
|
||||
private ?string $public = '-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6BuML3gtLGde7QKNuNST
|
||||
UCB9gdHC7XIpOc7Wx2I64Esj3UxWHTgp3URj0ge8zpy7A3FfBdppR7d1nwoD6Xad
|
||||
@@ -70,7 +76,37 @@ kIHG5j+Qga2CgXqI2Y5URXGz5XlsNbMNFUrnWcbpqEbW5O6/BgHLLSDEyQgwbygN
|
||||
mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
|
||||
-----END RSA PRIVATE KEY-----';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getIss(): string
|
||||
{
|
||||
return $this->iss;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $iss
|
||||
*/
|
||||
public function setIss(string $iss): void
|
||||
{
|
||||
$this->iss = $iss;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isOos(): bool
|
||||
{
|
||||
return $this->oos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $oos
|
||||
*/
|
||||
public function setOos(bool $oos): void
|
||||
{
|
||||
$this->oos = $oos;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user