You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
504 B
26 lines
504 B
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Yansongda\Pay\Packer;
|
|
|
|
use Yansongda\Pay\Contract\PackerInterface;
|
|
|
|
class JsonPacker implements PackerInterface
|
|
{
|
|
public function pack(array $payload): string
|
|
{
|
|
return json_encode($payload, JSON_UNESCAPED_UNICODE);
|
|
}
|
|
|
|
public function unpack(string $payload): ?array
|
|
{
|
|
$data = json_decode($payload, true);
|
|
|
|
if (JSON_ERROR_NONE === json_last_error()) {
|
|
return $data;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|