diff --git a/Server/application/common.php b/Server/application/common.php index e6cc5e26..8785f12c 100644 --- a/Server/application/common.php +++ b/Server/application/common.php @@ -75,7 +75,18 @@ if (!function_exists('requestCurl')) { if (!function_exists('dataBuild')) { function dataBuild($array) { - return is_array($array) ? http_build_query($array) : $array; + if (!is_array($array)) { + return $array; + } + + // 处理嵌套数组 + foreach ($array as $key => $value) { + if (is_array($value)) { + $array[$key] = json_encode($value); + } + } + + return http_build_query($array); } } diff --git a/Server/application/http/middleware/Jwt.php b/Server/application/http/middleware/Jwt.php new file mode 100644 index 00000000..4f2fb7d1 --- /dev/null +++ b/Server/application/http/middleware/Jwt.php @@ -0,0 +1,49 @@ + 401, + 'msg' => '未授权访问,缺少有效的身份凭证', + 'data' => null + ])->header(['Content-Type' => 'application/json; charset=utf-8']); + } + + $payload = JwtUtil::verifyToken($token); + if (!$payload) { + return json([ + 'code' => 401, + 'msg' => '授权已过期或无效', + 'data' => null + ])->header(['Content-Type' => 'application/json; charset=utf-8']); + } + + // 将用户信息附加到请求中 + $request->userInfo = $payload; + + // 写入日志 + Log::info('JWT认证通过', ['user_id' => $payload['id'] ?? 0, 'username' => $payload['username'] ?? '']); + + return $next($request); + } +} diff --git a/Server/composer.json b/Server/composer.json index 65db23a6..ea979146 100644 --- a/Server/composer.json +++ b/Server/composer.json @@ -13,29 +13,37 @@ { "name": "liu21st", "email": "liu21st@gmail.com" + }, + { + "name": "yunwuxin", + "email": "448901948@qq.com" } ], "require": { - "php": ">=7.4.0", - "topthink/framework": "5.0.*", - "textalk/websocket": "^1.5", - "aliyuncs/oss-sdk-php": "^2.6", - "monolog/monolog": "^2.8", - "guzzlehttp/guzzle": "^7.5", - "overtrue/wechat": "~4.6", - "endroid/qr-code": "^4.6", - "phpoffice/phpspreadsheet": "^1.28", - "workerman/workerman": "^4.1", - "workerman/gateway-worker": "^3.1", - "eison/image": "^1.0", - "hashids/hashids": "^4.1", - "khanamiryan/qrcode-detector-decoder": "^2.0", - "lizhichao/word": "^2.2", - "adbario/php-dot-notation": "^3.1" + "php": ">=5.6.0", + "topthink/framework": "5.1.*", + "topthink/think-installer": "~1.0", + "topthink/think-captcha": "^2.0", + "topthink/think-helper": "^3.0", + "topthink/think-image": "^1.0", + "topthink/think-queue": "^2.0", + "topthink/think-worker": "^2.0", + "textalk/websocket": "^1.2", + "aliyuncs/oss-sdk-php": "^2.3", + "monolog/monolog": "^1.24", + "guzzlehttp/guzzle": "^6.3", + "overtrue/wechat": "~4.0", + "endroid/qr-code": "^3.5", + "phpoffice/phpspreadsheet": "^1.8", + "workerman/workerman": "^3.5", + "workerman/gateway-worker": "^3.0", + "hashids/hashids": "^2.0", + "khanamiryan/qrcode-detector-decoder": "^1.0", + "lizhichao/word": "^2.0", + "adbario/php-dot-notation": "^2.2" }, "require-dev": { - "symfony/var-dumper": "^5.4", - "topthink/think-trace": "^1.0", + "symfony/var-dumper": "^3.4", "topthink/think-migration": "^2.0" }, "autoload": { @@ -44,18 +52,19 @@ }, "files": [ "application/common.php" - ] + ], + "classmap": [] }, "extra": { "think-path": "thinkphp" }, "config": { - "preferred-install": "dist" + "preferred-install": "dist", + "allow-plugins": { + "topthink/think-installer": true, + "easywechat-composer/easywechat-composer": true + } }, - "scripts": { - "post-autoload-dump": [ - "@php think service:discover", - "@php think vendor:publish" - ] - } + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/Server/config/middleware.php b/Server/config/middleware.php index 132ab645..b221b8a1 100644 --- a/Server/config/middleware.php +++ b/Server/config/middleware.php @@ -23,7 +23,8 @@ return [ // 全局中间件 'alias' => [ - 'cors' => 'app\\common\\middleware\\AllowCrossDomain' + 'cors' => 'app\\common\\middleware\\AllowCrossDomain', + 'jwt' => 'app\\http\\middleware\\Jwt' ], // 应用中间件