Merge branch 'release/0.0.8'

develop 0.0.8
X14XA\shengli 2 weeks ago
commit 356f73f6eb
  1. 2
      composer.json
  2. 14
      src/http/Response.php

@ -1,6 +1,6 @@
{
"name": "tansilu/hfpay-lib",
"version": "0.0.7",
"version": "0.0.8",
"type": "library",
"require": {
"php": ">=7.4",

@ -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;

Loading…
Cancel
Save