8629f4a4ce
- Rename directories to lowercase: Controller→controller, Model→model, Service→service, Util→util, Bootstrap→bootstrap
- Update all namespaces from App\Xxx to app\xxx (webman convention)
- Update all import statements across the codebase
- Update route.php to use lowercase namespaces
- Remove unused CompanyFeishuApp model
- Comment out unimplemented controller routes
Following webman 2.x framework conventions:
- Models: app\model\{ClassName}
- Controllers: app\controller\{ClassName}
- Services: app\service\{ClassName}
- Utils: app\util\{ClassName}
- Middleware: app\middleware\{ClassName}
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
48 lines
981 B
PHP
48 lines
981 B
PHP
<?php
|
|
|
|
namespace app\util;
|
|
|
|
use Firebase\JWT\JWT;
|
|
use Firebase\JWT\Key;
|
|
use Exception;
|
|
|
|
class JwtUtil
|
|
{
|
|
private static string $secret = 'your-secret-key-change-in-production';
|
|
private static int $expire = 86400 * 7; // 7 days
|
|
|
|
/**
|
|
* 生成 Token
|
|
*/
|
|
public static function encode(array $data): string
|
|
{
|
|
$payload = array_merge($data, [
|
|
'iat' => time(),
|
|
'exp' => time() + self::$expire,
|
|
]);
|
|
|
|
return JWT::encode($payload, self::$secret, 'HS256');
|
|
}
|
|
|
|
/**
|
|
* 解析 Token
|
|
*/
|
|
public static function decode(string $token): ?array
|
|
{
|
|
try {
|
|
$decoded = JWT::decode($token, new Key(self::$secret, 'HS256'));
|
|
return (array) $decoded;
|
|
} catch (Exception $e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 验证 Token
|
|
*/
|
|
public static function verify(string $token): bool
|
|
{
|
|
return self::decode($token) !== null;
|
|
}
|
|
}
|