From 5c029936582bb9ea2d2d2323259fe1ffa748ec22 Mon Sep 17 00:00:00 2001 From: "X14XA\\shengli" Date: Sat, 18 Apr 2026 11:48:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=B5=8B=E5=80=BC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/http/Response.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/http/Response.php b/src/http/Response.php index 7b68450..fcbad98 100644 --- a/src/http/Response.php +++ b/src/http/Response.php @@ -2,6 +2,7 @@ namespace Tansilu\HfPayLib\http; +use GuzzleHttp\Exception\InvalidArgumentException; use Psr\Http\Message\ResponseInterface; use Tansilu\HfPayLib\exception\ApiException; @@ -11,7 +12,7 @@ class Response * @var int 状态码 */ private int $statusCode = 200; - private array $body = []; + private ?array $body = []; private string $source; @@ -34,7 +35,14 @@ class Response switch ($bodyFormat[0]) { case 'text/html': case 'application/json': - $self->body = json_decode($self->source, true); + try { + $deRet = json_decode($self->source, true); + if($deRet != null) { + $self->body = $deRet; + } + } catch (InvalidArgumentException $e) { + throw new ApiException('反馈的消息格式错误'); + } break; case 'application/xml': case 'text/plain': @@ -45,7 +53,7 @@ class Response return $self; } - public static function tempInit(int $code, array $body) + public static function tempInit(int $code, ?array $body): Response { $self = new self(); $self->statusCode = $code; From 54741ff23ea5fb8872d8f65295bcb001b26b2950 Mon Sep 17 00:00:00 2001 From: "X14XA\\shengli" Date: Sat, 18 Apr 2026 11:49:02 +0800 Subject: [PATCH 2/2] 0.0.8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 463ae09..699871d 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "tansilu/hfpay-lib", - "version": "0.0.7", + "version": "0.0.8", "type": "library", "require": { "php": ">=7.4",