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", "name": "tansilu/hfpay-lib",
"version": "0.0.7", "version": "0.0.8",
"type": "library", "type": "library",
"require": { "require": {
"php": ">=7.4", "php": ">=7.4",

@ -2,6 +2,7 @@
namespace Tansilu\HfPayLib\http; namespace Tansilu\HfPayLib\http;
use GuzzleHttp\Exception\InvalidArgumentException;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Tansilu\HfPayLib\exception\ApiException; use Tansilu\HfPayLib\exception\ApiException;
@ -11,7 +12,7 @@ class Response
* @var int 状态码 * @var int 状态码
*/ */
private int $statusCode = 200; private int $statusCode = 200;
private array $body = []; private ?array $body = [];
private string $source; private string $source;
@ -34,7 +35,14 @@ class Response
switch ($bodyFormat[0]) { switch ($bodyFormat[0]) {
case 'text/html': case 'text/html':
case 'application/json': 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; break;
case 'application/xml': case 'application/xml':
case 'text/plain': case 'text/plain':
@ -45,7 +53,7 @@ class Response
return $self; return $self;
} }
public static function tempInit(int $code, array $body) public static function tempInit(int $code, ?array $body): Response
{ {
$self = new self(); $self = new self();
$self->statusCode = $code; $self->statusCode = $code;

Loading…
Cancel
Save