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.
59 lines
1.2 KiB
59 lines
1.2 KiB
3 weeks ago
|
<?php
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace App\Utils\Transfer\HisHttpClient;
|
||
|
|
||
|
use App\Utils\Transfer\HttpTransferAbstract;
|
||
|
use Exception;
|
||
|
use JsonException;
|
||
|
|
||
|
class ClientHttpTransfer extends HttpTransferAbstract
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
* MediWayTransfer Construct
|
||
|
* @param string $his_name
|
||
|
*/
|
||
|
public function __construct(string $his_name = "")
|
||
|
{
|
||
|
parent::__construct($his_name);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 初始化
|
||
|
*/
|
||
|
public function initialize(): void
|
||
|
{
|
||
|
parent::initialize();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 设置客户端选项
|
||
|
* @return array
|
||
|
*/
|
||
|
public function ClientHeaders(): array
|
||
|
{
|
||
|
return [];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 响应格式化
|
||
|
* @param mixed $data
|
||
|
* @return mixed
|
||
|
*/
|
||
|
public function responseFormat(mixed $data): mixed
|
||
|
{
|
||
|
try {
|
||
|
return json_decode($data, true, JSON_THROW_ON_ERROR);
|
||
|
} catch (JsonException|Exception $e) {
|
||
|
return [
|
||
|
'status' => 200,
|
||
|
'success' => false,
|
||
|
'msg' => '解析JSON失败',
|
||
|
'msgDev' => $e->getMessage(),
|
||
|
'response' => $data
|
||
|
];
|
||
|
}
|
||
|
}
|
||
|
}
|