修改ca开具处方
This commit is contained in:
+2
-89
@@ -14,22 +14,10 @@ use Hyperf\Utils\ApplicationContext;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* 四川ca云证书+电子签章
|
||||
* 四川ca云证书+电子签章-线下
|
||||
*/
|
||||
class Ca
|
||||
class Ca extends Base
|
||||
{
|
||||
#[Inject]
|
||||
protected ContainerInterface $container;
|
||||
|
||||
#[Inject]
|
||||
protected Client $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->container = ApplicationContext::getContainer();
|
||||
$this->client = $this->container->get(Client::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取云证书
|
||||
* @param array $data
|
||||
@@ -331,79 +319,4 @@ class Ca
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求签名
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
protected function getRequestSign(array $data): string
|
||||
{
|
||||
$sign_data = array();
|
||||
if (isset($data['form_params'])) {
|
||||
$sign_data = $data['form_params'];
|
||||
}
|
||||
|
||||
if (isset($data['multipart'])) {
|
||||
foreach ($data['multipart'] as $item) {
|
||||
// pdf进行签章时,此参数为文件流,不参与签名
|
||||
if ($item['name'] == "pdfFile") {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sign_data[$item['name']] = $item['contents'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($sign_data)){
|
||||
ksort($sign_data);
|
||||
$data = implode('&', $sign_data);
|
||||
}else{
|
||||
$data = "";
|
||||
}
|
||||
|
||||
return hash_hmac("sha1", $data, config("ca.secret"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装公共请求
|
||||
* @param string $path
|
||||
* @param array $arg
|
||||
* @return mixed
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
protected function httpRequest(string $path, array $arg = []): mixed
|
||||
{
|
||||
$option = [
|
||||
"headers" => [
|
||||
"app_id" => config("ca.app_id"),
|
||||
"signature" => $this->getRequestSign($arg),
|
||||
],
|
||||
];
|
||||
|
||||
$arg = array_merge($arg, $option);
|
||||
|
||||
$response = $this->client->post($path, $arg);
|
||||
|
||||
if ($response->getStatusCode() != '200') {
|
||||
// 请求失败
|
||||
throw new BusinessException($response->getBody()->getContents());
|
||||
}
|
||||
$body = json_decode($response->getBody(), true);
|
||||
dump($body);
|
||||
if (empty($body)) {
|
||||
// 返回值为空
|
||||
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
|
||||
}
|
||||
|
||||
if ($body['result_code'] != 0) {
|
||||
// 请求失败
|
||||
if (!empty($body['result_msg'])) {
|
||||
throw new BusinessException($body['result_msg']);
|
||||
}
|
||||
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
|
||||
}
|
||||
|
||||
return $body['body'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user