From f145391b5221e1ca456c36b0fb8acac2d7d1feec Mon Sep 17 00:00:00 2001 From: hgc Date: Thu, 26 Dec 2024 21:13:49 +0800 Subject: [PATCH] =?UTF-8?q?tinywan\rpc=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 3 +- composer.lock | 103 +++++++++++++++++- .../plugin/tinywan/exception-handler/app.php | 59 ++++++++++ config/plugin/tinywan/rpc/app.php | 9 ++ config/plugin/tinywan/rpc/process.php | 9 ++ 5 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 config/plugin/tinywan/exception-handler/app.php create mode 100644 config/plugin/tinywan/rpc/app.php create mode 100644 config/plugin/tinywan/rpc/process.php diff --git a/composer.json b/composer.json index 99a5b6a..3c750c6 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,8 @@ "illuminate/redis": "^10.48", "symfony/var-dumper": "^6.4", "webman/think-orm": "^1.1", - "phpoffice/phpspreadsheet": "^3.6" + "phpoffice/phpspreadsheet": "^3.6", + "tinywan/rpc": "^1.3" }, "suggest": { "ext-event": "For better performance. " diff --git a/composer.lock b/composer.lock index 8d7b20d..32d4f52 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": "69fc720415852f55d5319c4ab078fb79", + "content-hash": "55aa2739027c5188b7b150b785715692", "packages": [ { "name": "brick/math", @@ -3663,6 +3663,107 @@ ], "time": "2024-11-08T15:28:48+00:00" }, + { + "name": "tinywan/exception-handler", + "version": "v1.5.4", + "source": { + "type": "git", + "url": "https://github.com/Tinywan/webman-exception.git", + "reference": "19b58b0e3c6927fa0726c0896364275329ab52d5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Tinywan/webman-exception/zipball/19b58b0e3c6927fa0726c0896364275329ab52d5", + "reference": "19b58b0e3c6927fa0726c0896364275329ab52d5", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=7.4", + "workerman/webman-framework": "^1.5" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.6", + "phpstan/phpstan": "^1.4", + "tinywan/jwt": "^1.2", + "tinywan/storage": "^0.2.2", + "tinywan/validate": "^1.0", + "webman/think-orm": "^1.1", + "workerman/webman": "^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Tinywan\\ExceptionHandler\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "webman exception handler plugin", + "support": { + "issues": "https://github.com/Tinywan/webman-exception/issues", + "source": "https://github.com/Tinywan/webman-exception/tree/v1.5.4" + }, + "time": "2024-07-13T05:00:19+00:00" + }, + { + "name": "tinywan/rpc", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/Tinywan/webman-rpc.git", + "reference": "5bad7989a88f877a2b1579f862e7894533368d6a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Tinywan/webman-rpc/zipball/5bad7989a88f877a2b1579f862e7894533368d6a", + "reference": "5bad7989a88f877a2b1579f862e7894533368d6a", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=7.4", + "tinywan/exception-handler": "^1.5", + "workerman/webman-framework": "^1.5" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.6", + "phpstan/phpstan": "^1.4", + "workerman/webman": "^1.0" + }, + "type": "library", + "autoload": { + "files": [ + "src/function.php" + ], + "psr-4": { + "Tinywan\\Rpc\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Tinywan", + "email": "756684177@qq.com" + } + ], + "description": "simple rpc service for webman plugin", + "keywords": [ + "plugin", + "rpc", + "webman" + ], + "support": { + "issues": "https://github.com/Tinywan/webman-rpc/issues", + "source": "https://github.com/Tinywan/webman-rpc/tree/v1.3.0" + }, + "time": "2024-08-16T06:46:51+00:00" + }, { "name": "topthink/think-helper", "version": "v3.1.10", diff --git a/config/plugin/tinywan/exception-handler/app.php b/config/plugin/tinywan/exception-handler/app.php new file mode 100644 index 0000000..74a4c33 --- /dev/null +++ b/config/plugin/tinywan/exception-handler/app.php @@ -0,0 +1,59 @@ + true, + // 错误异常配置 + 'exception_handler' => [ + // 不需要记录错误日志 + 'dont_report' => [ + Tinywan\ExceptionHandler\Exception\BadRequestHttpException::class, + Tinywan\ExceptionHandler\Exception\UnauthorizedHttpException::class, + Tinywan\ExceptionHandler\Exception\ForbiddenHttpException::class, + Tinywan\ExceptionHandler\Exception\NotFoundHttpException::class, + Tinywan\ExceptionHandler\Exception\RouteNotFoundException::class, + Tinywan\ExceptionHandler\Exception\TooManyRequestsHttpException::class, + Tinywan\ExceptionHandler\Exception\ServerErrorHttpException::class, + Tinywan\Validate\Exception\ValidateException::class, + Tinywan\Jwt\Exception\JwtTokenException::class + ], + // 自定义HTTP状态码 + 'status' => [ + 'validate' => 400, // 验证器异常 + 'jwt_token' => 401, // 认证失败 + 'jwt_token_expired' => 401, // 访问令牌过期 + 'jwt_refresh_token_expired' => 402, // 刷新令牌过期 + 'server_error' => 500, // 服务器内部错误 + 'server_error_is_response' => false, // 是否响应服务器内部错误 + 'type_error' => 400, // 参数类型错误码 + 'type_error_is_response' => false, // 参数类型与预期声明的参数类型不匹配 + ], + // 自定义响应消息 + 'body' => [ + 'code' => 0, + 'msg' => '服务器内部异常', + 'data' => null + ], + // 事件,event 与 webman/event 存在冲突,event 重命名为 event_trigger + 'event_trigger' => [ + 'enable' => false, + // 钉钉机器人 + 'dingtalk' => [ + 'accessToken' => 'xxxxxxxxxxxxxxxx', + 'secret' => 'xxxxxxxxxxxxxxxx', + 'title' => '钉钉机器人异常通知', + ] + ], + /** 异常报警域名标题 */ + 'domain' => [ + 'dev' => 'dev-api.tinywan.com', // 开发环境 + 'test' => 'test-api.tinywan.com', // 测试环境 + 'pre' => 'pre-api.tinywan.com', // 预发环境 + 'prod' => 'api.tinywan.com', // 生产环境 + ], + /** 是否生产环境 。可以通过配置文件或者数据库读取返回 eg:return config('app.env') === 'prod';*/ + 'is_prod_env' => function () { + return false; + }, + ], + +]; \ No newline at end of file diff --git a/config/plugin/tinywan/rpc/app.php b/config/plugin/tinywan/rpc/app.php new file mode 100644 index 0000000..185bbc1 --- /dev/null +++ b/config/plugin/tinywan/rpc/app.php @@ -0,0 +1,9 @@ + true, + 'server' => [ + 'namespace'=> 'service\\', // 自定义服务命名空间 + 'listen_text_address' => 'text://0.0.0.0:9512', // 自定义Text协议地址 + ], +]; diff --git a/config/plugin/tinywan/rpc/process.php b/config/plugin/tinywan/rpc/process.php new file mode 100644 index 0000000..210cea2 --- /dev/null +++ b/config/plugin/tinywan/rpc/process.php @@ -0,0 +1,9 @@ + [ + 'handler'=> \Tinywan\Rpc\Protocol\RpcTextProtocol::class, + 'listen' => config('plugin.tinywan.rpc.app.server.listen_text_address'), + 'count' => 10, // 根据配置文件调整 + ] +]; \ No newline at end of file