From d4d678ce1244888bbf660ff04293068c402c7007 Mon Sep 17 00:00:00 2001 From: Lkeme <19500576+lkeme@users.noreply.github.com> Date: Sat, 7 Aug 2021 10:23:19 +0800 Subject: [PATCH] [fix] AloneTcpClient & Forward --- composer.lock | 51 ++++++++++++++++++----------------- src/plugin/AloneTcpClient.php | 16 +++++++---- src/plugin/Forward.php | 4 +++ 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/composer.lock b/composer.lock index 4ea622f..c14ef03 100644 --- a/composer.lock +++ b/composer.lock @@ -80,16 +80,16 @@ }, { "name": "amphp/amp", - "version": "v2.5.2", + "version": "v2.6.0", "source": { "type": "git", "url": "https://github.com/amphp/amp.git", - "reference": "efca2b32a7580087adb8aabbff6be1dc1bb924a9" + "reference": "caa95edeb1ca1bf7532e9118ede4a3c3126408cc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/amp/zipball/efca2b32a7580087adb8aabbff6be1dc1bb924a9", - "reference": "efca2b32a7580087adb8aabbff6be1dc1bb924a9", + "url": "https://api.github.com/repos/amphp/amp/zipball/caa95edeb1ca1bf7532e9118ede4a3c3126408cc", + "reference": "caa95edeb1ca1bf7532e9118ede4a3c3126408cc", "shasum": "", "mirrors": [ { @@ -99,14 +99,14 @@ ] }, "require": { - "php": ">=7" + "php": ">=7.1" }, "require-dev": { "amphp/php-cs-fixer-config": "dev-master", "amphp/phpunit-util": "^1", "ext-json": "*", "jetbrains/phpstorm-stubs": "^2019.3", - "phpunit/phpunit": "^6.0.9 | ^7", + "phpunit/phpunit": "^7 | ^8 | ^9", "psalm/phar": "^3.11@dev", "react/promise": "^2" }, @@ -163,7 +163,7 @@ "support": { "irc": "irc://irc.freenode.org/amphp", "issues": "https://github.com/amphp/amp/issues", - "source": "https://github.com/amphp/amp/tree/v2.5.2" + "source": "https://github.com/amphp/amp/tree/v2.6.0" }, "funding": [ { @@ -171,7 +171,7 @@ "type": "github" } ], - "time": "2021-01-10T17:06:37+00:00" + "time": "2021-07-16T20:06:06+00:00" }, { "name": "bramus/ansi-php", @@ -741,16 +741,16 @@ }, { "name": "laminas/laminas-servicemanager", - "version": "3.6.4", + "version": "3.7.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-servicemanager.git", - "reference": "b1445e1a7077c21b0fad0974a1b7a11b9dbe0828" + "reference": "2b0aee477fdbd3191af7c302b93dbc5fda0626f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/b1445e1a7077c21b0fad0974a1b7a11b9dbe0828", - "reference": "b1445e1a7077c21b0fad0974a1b7a11b9dbe0828", + "url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/2b0aee477fdbd3191af7c302b93dbc5fda0626f4", + "reference": "2b0aee477fdbd3191af7c302b93dbc5fda0626f4", "shasum": "", "mirrors": [ { @@ -779,14 +779,16 @@ }, "require-dev": { "composer/package-versions-deprecated": "^1.0", - "laminas/laminas-coding-standard": "~1.0.0", + "laminas/laminas-coding-standard": "~2.2.0", "laminas/laminas-container-config-test": "^0.3", - "laminas/laminas-dependency-plugin": "^2.1", + "laminas/laminas-dependency-plugin": "^2.1.2", "mikey179/vfsstream": "^1.6.8", "ocramius/proxy-manager": "^2.2.3", - "phpbench/phpbench": "^1.0.0-alpha3", + "phpbench/phpbench": "^1.0.4", "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.4" + "phpunit/phpunit": "^9.4", + "psalm/plugin-phpunit": "^0.16.1", + "vimeo/psalm": "^4.8" }, "suggest": { "ocramius/proxy-manager": "ProxyManager ^2.1.1 to handle lazy initialization of services" @@ -830,20 +832,20 @@ "type": "community_bridge" } ], - "time": "2021-02-03T08:44:41+00:00" + "time": "2021-07-24T19:33:07+00:00" }, { "name": "laminas/laminas-stdlib", - "version": "3.4.0", + "version": "3.5.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-stdlib.git", - "reference": "e89c2268c9cad25099f562f7f015c28c5dd383c9" + "reference": "c8ac6a76a133e682acfabc821d4a2ec646934b12" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-stdlib/zipball/e89c2268c9cad25099f562f7f015c28c5dd383c9", - "reference": "e89c2268c9cad25099f562f7f015c28c5dd383c9", + "url": "https://api.github.com/repos/laminas/laminas-stdlib/zipball/c8ac6a76a133e682acfabc821d4a2ec646934b12", + "reference": "c8ac6a76a133e682acfabc821d4a2ec646934b12", "shasum": "", "mirrors": [ { @@ -853,11 +855,10 @@ ] }, "require": { - "laminas/laminas-zendframework-bridge": "^1.0", "php": "^7.3 || ^8.0" }, - "replace": { - "zendframework/zend-stdlib": "^3.2.1" + "conflict": { + "zendframework/zend-stdlib": "*" }, "require-dev": { "laminas/laminas-coding-standard": "~2.3.0", @@ -896,7 +897,7 @@ "type": "community_bridge" } ], - "time": "2021-06-28T21:37:31+00:00" + "time": "2021-08-03T13:40:40+00:00" }, { "name": "laminas/laminas-text", diff --git a/src/plugin/AloneTcpClient.php b/src/plugin/AloneTcpClient.php index da3f3c7..0c921b8 100644 --- a/src/plugin/AloneTcpClient.php +++ b/src/plugin/AloneTcpClient.php @@ -61,10 +61,10 @@ class AloneTcpClient /** * @use 数据封装 * @param $value - * @param $fmt + * @param string $fmt * @return string */ - private static function packMsg($value, $fmt = "N"): string + private static function packMsg($value, string $fmt = "N"): string { $head = pack($fmt, strlen($value)); return $head . $value; @@ -75,11 +75,11 @@ class AloneTcpClient * @param $value * @param string $fmt * @return array|false + * @throws \Exception */ - private static function unPackMsg($value, $fmt = "N") + private static function unPackMsg($value, string $fmt = "N") { - $data = unpack($fmt, $value); - return $data[1]; + return unpack($fmt, $value); } /** @@ -126,6 +126,12 @@ class AloneTcpClient throw new Exception("Connection failure"); } if ($length == 4) $data = self::unPackMsg($data); + // 防止解包异常 + if (!$data) { + throw new Exception("Connection failure"); + } else { + $data = $data[1]; + } break; } } catch (Exception $exception) { diff --git a/src/plugin/Forward.php b/src/plugin/Forward.php index 14e3e41..a89805d 100644 --- a/src/plugin/Forward.php +++ b/src/plugin/Forward.php @@ -211,6 +211,10 @@ class Forward $did = $dynamic['desc']['dynamic_id']; $card = json_decode($dynamic['card'], true); foreach ($msg_list as $msg) { + // 异常情况 跳过 + if (!isset($card['item']['content']) || !$msg) { + continue; + } if (strpos($card['item']['content'], $msg) !== false) { Log::info("[删除所有动态] 删除动态 {$did}"); Dynamic::removeDynamic($did);