更新依赖、添加规则
This commit is contained in:
@@ -81,3 +81,5 @@ BASE_OLD_SHOP_API_URL=https://shop.xiaokang88.com
|
||||
|
||||
# 密钥
|
||||
ENCRYPT_KEY=3a8f9b2d7c1e4f8a9b2d7c1e4f8a9b2d7c1e4f8a9b2d7c1e4f8a9b2d7c1e4f8a
|
||||
# JWT HS256 密钥(至少 32 字符;生产环境务必改成随机长串)
|
||||
JWT_SECRET=nl_admin_jwt_secret_key_change_me_32b
|
||||
|
||||
@@ -6,13 +6,29 @@ use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* JWT 签发与解析服务
|
||||
* firebase/php-jwt 对 HS256 要求密钥至少 256 bit(32 字节),过短会抛 Provided key is too short
|
||||
*/
|
||||
class JWTService
|
||||
{
|
||||
private static mixed $_instance;
|
||||
private string $secretKey = 'cc_spa_jwt_secret_key'; // 请替换为你的密钥
|
||||
|
||||
private string $secretKey;
|
||||
private string $token;
|
||||
|
||||
/**
|
||||
* 构造时从配置读取密钥,并兜底保证满足 HS256 最小长度
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// 优先读环境变量 JWT_SECRET;长度不足时用 hash 派生,避免库直接报错
|
||||
$secret = (string) config('nl.jwt.secret', '');
|
||||
if (strlen($secret) < 32) {
|
||||
$secret = hash('sha256', $secret !== '' ? $secret : 'nl_admin_jwt_fallback_secret');
|
||||
}
|
||||
$this->secretKey = $secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实例
|
||||
* @return null|static
|
||||
|
||||
@@ -18,6 +18,12 @@ return [
|
||||
// 'over_time' => 0 //处方审核自动失效时间
|
||||
],
|
||||
],
|
||||
/*
|
||||
* JWT 配置(HS256 密钥至少 32 字节,否则 firebase/php-jwt 报 Provided key is too short)
|
||||
*/
|
||||
'jwt' => [
|
||||
'secret' => env('JWT_SECRET', 'nl_admin_jwt_secret_key_change_me_32b'),
|
||||
],
|
||||
/*
|
||||
* redis配置
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user