From 8cb2fc3d3c361d0a821a5f1d3bfdde341a9c8251 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 10 Jul 2025 11:10:12 +0800 Subject: [PATCH] =?UTF-8?q?env(config):=20=E6=9B=B4=E6=96=B0=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E9=85=8D=E7=BD=AE=E5=B9=B6=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改了 .example.env 文件中的数据库和 Redis 配置 - 更新了 IndexController 中的密码处理逻辑 - 替换了 var-dumper 依赖从 max 到 next - 调整了 Redis 和服务器配置文件以使用环境变量 - 更新了异常处理配置 --- .example.env | 21 +++- app/ExceptionHandler.php | 44 +++++++++ app/api/controller/IndexController.php | 8 +- composer.json | 2 +- composer.lock | 131 ++++++++++--------------- config/exception.php | 2 +- config/redis.php | 8 +- config/server.php | 2 +- 8 files changed, 129 insertions(+), 89 deletions(-) create mode 100644 app/ExceptionHandler.php diff --git a/.example.env b/.example.env index aa607c9..2ff0077 100755 --- a/.example.env +++ b/.example.env @@ -1 +1,20 @@ -APP_DEBUG=true DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=likeadmin DB_USERNAME=root DB_PASSWORD=root SESSION_DRIVER=file REDIS_CONNECTION=default REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 REDIS_DB=24 YLY_PARTNER=25991 YLY_API_KEY=d955cc2296d69b4094c6465aad360dc6b19a8c77 YLY_REQUEST_URL=http://open.10ss.net:8888 UNIQUE_IDENTIFICATION = "11d3" DEMO_ENV = "" \ No newline at end of file +APP_DEBUG=true +HOST="http://0.0.0.0:8545" +WEB_URL="/" +DB_CONNECTION=mysql +DB_HOST=47.109.71.135 +DB_PORT=3306 +DB_DATABASE=webman_admin +DB_USERNAME=webman_admin +DB_PASSWORD=nt8mogchd1 + +SESSION_DRIVER=file + +REDIS_CONNECTION=default +REDIS_HOST=redis +REDIS_PASSWORD=123456 +REDIS_PORT=6379 +REDIS_DB=24 + +UNIQUE_IDENTIFICATION = "11d3" +DEMO_ENV = "" \ No newline at end of file diff --git a/app/ExceptionHandler.php b/app/ExceptionHandler.php new file mode 100644 index 0000000..1ac0cd7 --- /dev/null +++ b/app/ExceptionHandler.php @@ -0,0 +1,44 @@ +expectsJson()) { + return json(['code' => 0, 'msg' => $exception->getMessage(),'show'=>1]); + } + return response($exception->getMessage()); + } elseif ($exception instanceof \Exception) { + $isDebug = config('app.debug'); + $error = [ + 'show' => 1, + 'code' => $isDebug ? $exception->getCode() : 0, + 'msg' => $isDebug ? $exception->getMessage() : '服务器内部错误', + ]; + if ($isDebug) { + $error['file'] = $exception->getFile(); + $error['line'] = $exception->getLine(); + } + return response(json_encode($error, JSON_UNESCAPED_UNICODE)); + } + // 非json请求则返回一个页面 + return new Response(200, [], 'msg:'.$exception->getMessage().'。line:'.$exception->getLine().'。file:'.$exception->getFile()); + } +} diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 95880a6..45c5894 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -5,12 +5,18 @@ namespace app\api\controller; use app\admin\validate\tools\GenerateTableValidate; use app\admin\logic\tools\GeneratorLogic; use app\common\controller\BaseLikeAdminController; +use app\common\model\auth\Admin; +use Webman\Config; class IndexController extends BaseLikeAdminController { public function index() { - return json(['msg' => 'hello']); + $password = '123456'; + $passwordSalt = Config::get('project.unique_identification'); + $create_password = create_password($password, $passwordSalt); + Admin::where('id', 1)->update(['password' => $create_password]); + return json(['你修改的密码是' => $password]); } /** diff --git a/composer.json b/composer.json index c44ffab..c471bdb 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "doctrine/annotations": "^1.14", "illuminate/redis": "^10.22", "symfony/cache": "^5.4", - "max/var-dumper": "^0.1.1" + "next/var-dumper": "^0.1.0" }, "suggest": { "ext-event": "For better performance. " diff --git a/composer.lock b/composer.lock index 860c272..cc7c6b3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "180fd50c18ae54063515e2bae5b5e329", + "content-hash": "5285ea3b129580fb4b1aae730e0f4dc3", "packages": [ { "name": "aliyuncs/oss-sdk-php", @@ -1292,45 +1292,6 @@ ], "time": "2022-12-02T22:17:43+00:00" }, - { - "name": "max/var-dumper", - "version": "0.1.1", - "dist": { - "type": "zip", - "url": "https://mirrors.cloud.tencent.com/repository/composer/max/var-dumper/0.1.1/max-var-dumper-0.1.1.zip", - "reference": "603bdeb2135b24c9eb91e559df1f9fc6a95b811d", - "shasum": "" - }, - "require": { - "php": ">=7.4", - "symfony/var-dumper": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.1.x-dev" - } - }, - "autoload": { - "files": [ - "src/helpers.php" - ], - "psr-4": { - "Max\\VarDumper\\": "src/" - } - }, - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "chengyao", - "email": "987861463@qq.com" - } - ], - "homepage": "https://github.com/marxphp/var-dumper", - "time": "2023-07-07T12:54:36+00:00" - }, { "name": "monolog/monolog", "version": "2.9.1", @@ -1494,6 +1455,55 @@ ], "time": "2023-09-07T16:43:50+00:00" }, + { + "name": "next/var-dumper", + "version": "0.1", + "source": { + "type": "git", + "url": "https://github.com/next-laboratory/var-dumper.git", + "reference": "ec86735e0df42240acc57341e4d5c1b8cff6b522" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/next-laboratory/var-dumper/zipball/ec86735e0df42240acc57341e4d5c1b8cff6b522", + "reference": "ec86735e0df42240acc57341e4d5c1b8cff6b522", + "shasum": "" + }, + "require": { + "php": ">=7.4", + "symfony/var-dumper": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.1.x-dev" + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Next\\VarDumper\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "chengyao", + "email": "987861463@qq.com" + } + ], + "homepage": "https://github.com/next-laboratory/var-dumper", + "support": { + "issues": "https://github.com/next-laboratory/var-dumper/issues", + "source": "https://github.com/next-laboratory/var-dumper/tree/0.1" + }, + "time": "2023-10-31T02:27:04+00:00" + }, { "name": "nikic/fast-route", "version": "v1.3.0", @@ -3273,45 +3283,6 @@ "description": "The webman Validate Package", "time": "2022-08-27T08:29:08+00:00" }, - { - "name": "textalk/websocket", - "version": "1.5.8", - "dist": { - "type": "zip", - "url": "https://mirrors.cloud.tencent.com/repository/composer/textalk/websocket/1.5.8/textalk-websocket-1.5.8.zip", - "reference": "d05dbaa97500176447ffb1f1800573f23085ab13", - "shasum": "" - }, - "require": { - "php": "^7.2 | ^8.0", - "psr/log": "^1 | ^2 | ^3" - }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.0", - "phpunit/phpunit": "^8.0|^9.0", - "squizlabs/php_codesniffer": "^3.5" - }, - "type": "library", - "autoload": { - "psr-4": { - "WebSocket\\": "lib" - } - }, - "license": [ - "ISC" - ], - "authors": [ - { - "name": "Fredrik Liljegren" - }, - { - "name": "Sören Jensen", - "email": "soren@abicart.se" - } - ], - "description": "WebSocket client and server", - "time": "2022-04-26T06:28:24+00:00" - }, { "name": "tinywan/storage", "version": "v0.3.4", @@ -3803,5 +3774,5 @@ "ext-json": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/config/exception.php b/config/exception.php index df5efd9..e47d920 100644 --- a/config/exception.php +++ b/config/exception.php @@ -14,5 +14,5 @@ return [ // '' => support\exception\Handler::class, - '' => app\common\exception\Handler::class, + '' => \App\ExceptionHandler::class, ]; \ No newline at end of file diff --git a/config/redis.php b/config/redis.php index 2f9757a..dcd2b15 100644 --- a/config/redis.php +++ b/config/redis.php @@ -14,9 +14,9 @@ return [ 'default' => [ - 'host' => '127.0.0.1', - 'password' => null, - 'port' => 6379, - 'database' => 0, + 'host' =>getenv('REDIS_HOST'), + 'password' => getenv('REDIS_PASSWORD'), + 'port' => getenv('REDIS_PORT'), + 'database' => getenv('REDIS_DB'), ], ]; diff --git a/config/server.php b/config/server.php index 84ea0ef..3b49e4c 100644 --- a/config/server.php +++ b/config/server.php @@ -13,7 +13,7 @@ */ return [ - 'listen' => 'http://0.0.0.0:8787', + 'listen' => getenv('HOST'), 'transport' => 'tcp', 'context' => [], 'name' => 'webman',