8d78e18267
- Frontend: React 18 + TypeScript + Vite + Ant Design Mobile - Backend: PHP 8.5 + Webman 2.x + MySQL + Redis - i18n support: Chinese, English, Russian, Spanish, French - Approval workflow engine - Docker development environment - Feishu integration Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
36 lines
879 B
PHP
36 lines
879 B
PHP
<?php
|
|
|
|
namespace App\Middleware;
|
|
|
|
use App\Util\JwtUtil;
|
|
use Webman\Http\Request;
|
|
use Webman\Http\Response;
|
|
use support\Log;
|
|
|
|
class AuthMiddleware
|
|
{
|
|
public function process(Request $request, callable $handler): Response
|
|
{
|
|
// 获取 Token
|
|
$token = $request->header('Authorization');
|
|
$token = str_replace('Bearer ', '', $token);
|
|
|
|
if (!$token || !JwtUtil::verify($token)) {
|
|
return json([
|
|
'code' => 401,
|
|
'message' => 'Unauthorized',
|
|
'data' => null,
|
|
], 401);
|
|
}
|
|
|
|
// 解析 Token 并设置用户信息到请求
|
|
$payload = JwtUtil::decode($token);
|
|
if ($payload) {
|
|
$request->userId = $payload['user_id'] ?? null;
|
|
$request->companyId = $payload['company_id'] ?? null;
|
|
}
|
|
|
|
return $handler($request);
|
|
}
|
|
}
|