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