|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Utils\Transfer\HisHttpClient;
|
|
|
|
|
|
|
|
use App\Utils\Transfer\HttpTransferAbstract;
|
|
|
|
use Exception;
|
|
|
|
use JsonException;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
|
|
|
|
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 [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 响应格式化
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function responseFormat(): mixed
|
|
|
|
{
|
|
|
|
$response = $this->transfer_response;
|
|
|
|
if ($this->transfer_response instanceof ResponseInterface) {
|
|
|
|
$response = $this->transfer_response->getBody()->getContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
return json_decode($response, true, JSON_THROW_ON_ERROR);
|
|
|
|
} catch (JsonException|Exception $e) {
|
|
|
|
return [
|
|
|
|
'status' => 200,
|
|
|
|
'success' => false,
|
|
|
|
'msg' => '解析JSON失败',
|
|
|
|
'msgDev' => $e->getMessage(),
|
|
|
|
'response' => $data
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|