first commit

This commit is contained in:
Mr.Qin
2022-08-19 19:48:37 +08:00
commit afdd648b65
3275 changed files with 631084 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Yansongda\Pay\Parser;
use Psr\Http\Message\ResponseInterface;
use Yansongda\Pay\Contract\ParserInterface;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Exception\InvalidResponseException;
class ArrayParser implements ParserInterface
{
/**
* @throws \Yansongda\Pay\Exception\InvalidResponseException
*/
public function parse(?ResponseInterface $response): array
{
if (is_null($response)) {
throw new InvalidResponseException(Exception::RESPONSE_NONE);
}
$contents = $response->getBody()->getContents();
$result = json_decode($contents, true);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new InvalidResponseException(Exception::UNPACK_RESPONSE_ERROR, 'Unpack Response Error', ['contents' => $contents, 'response' => $response]);
}
return $result;
}
}