香洲二院小程序
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.
mini_xzey/app/Utils/Transfer/HisMedicalHttpClient/ClientMockHttpTransfer.php

129 lines
2.9 KiB

<?php
declare(strict_types=1);
namespace App\Utils\Transfer\HisMedicalHttpClient;
use App\Exceptions\GeneralException;
use App\Utils\Transfer\HttpTransferAbstract;
use Exception;
use Random\RandomException;
class ClientMockHttpTransfer extends HttpTransferAbstract
{
/**
* ClientMockTransfer Construct
* @param string $his_name
*/
public function __construct(string $his_name = "")
{
parent::__construct($his_name);
}
/**
* 设置客户端选项
* @return array
*/
public function clientHeaders(): array
{
return [];
}
/**
* @param string $class_name
* @return $this
*/
public function transferClass(string $class_name): static
{
return $this;
}
/**
* @throws GeneralException
*/
public function transferMethod(string $method, string $request_name, array $request_data = []): self
{
// 使用 match 替代 switch
return match ($request_name) {
'GetPrecalculatedFeeGh' => $this->mockGetPrecalculatedFeeGh($request_data),
'GetUnpayedList' => $this->mockGetUnpayedList($request_data),
'GetPrecalculatedFee' => $this->mockGetPrecalculatedFee($request_data),
'NotifyPayed' => $this->mockNotifyPayed($request_data),
default => throw new GeneralException("Method '{$request_name}' not found"),
};
}
/**
* 响应格式化
* @return mixed
* @throws Exception
*/
public function responseFormat(): mixed
{
try {
// 此处为json格式
return json_decode((string)$this->transfer_response, true);
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
/**
* 获取返回值
* @param bool $is_format
* @return mixed
* @throws Exception
*/
public function getResult(bool $is_format = true): mixed
{
return $this->responseFormat($this->transfer_response);
}
/**
* mockGetPrecalculatedFeeGh
* @param array $params
* @return self
*/
private function mockGetPrecalculatedFeeGh(array $params): self
{
$this->transfer_response = '';
return $this;
}
/**
* mockRegisterCard
* @param array $params
* @return self
*/
private function mockGetUnpayedList(array $params): self
{
$this->transfer_response = '';
return $this;
}
/**
* mockGetPrecalculatedFee
* @param array $params
* @return self
*/
private function mockGetPrecalculatedFee(array $params): self
{
$this->transfer_response = '';
return $this;
}
/**
* mockNotifyPayed
* @param array $params
* @return self
*/
private function mockNotifyPayed(array $params): self
{
$this->transfer_response = '';
return $this;
}
}