修改ca开具处方

This commit is contained in:
wucongxing 2023-04-18 16:36:40 +08:00
parent 7f00e9554b
commit 823b8e0ff0
4 changed files with 31 additions and 105 deletions

View File

@ -23,6 +23,7 @@ use App\Model\UserPharmacistInfo;
use App\Utils\Log; use App\Utils\Log;
use Extend\Alibaba\Oss; use Extend\Alibaba\Oss;
use Extend\Ca\Ca; use Extend\Ca\Ca;
use Extend\Ca\CaOffline;
use Extend\Prescription\Prescription; use Extend\Prescription\Prescription;
use Hyperf\Contract\LengthAwarePaginatorInterface; use Hyperf\Contract\LengthAwarePaginatorInterface;
use Hyperf\Utils\WaitGroup; use Hyperf\Utils\WaitGroup;
@ -242,7 +243,7 @@ class OrderPrescriptionService extends BaseService
$icd_name = ""; $icd_name = "";
} }
$ca = new Ca(); $CaOffline = new CaOffline();
// 获取云证书签名 // 获取云证书签名
$data = array(); $data = array();
@ -268,23 +269,23 @@ class OrderPrescriptionService extends BaseService
} }
dump("获取用户云证书签名"); dump("获取用户云证书签名");
$cert_sign_result = $ca->getCertSign($user_entity_id, $user_entity_id, $data); $cert_sign_result = $CaOffline->getCertSign($user_entity_id, $user_entity_id, $data);
dump("获取用户云证书签名成功"); dump("获取用户云证书签名成功");
// 验证云证书签名-验证无需处理,只要不返回错误即可 // 验证云证书签名-验证无需处理,只要不返回错误即可
dump("验证用户云证书签名"); dump("验证用户云证书签名");
$ca->verifyPkcs7($cert_sign_result['signP7'], $data); $CaOffline->verifyPkcs7($cert_sign_result['signP7'], $data);
dump("验证用户云证书签名成功"); dump("验证用户云证书签名成功");
if ($user['user_type'] == 3) { if ($user['user_type'] == 3) {
dump("获取医院云证书签名"); dump("获取医院云证书签名");
unset($cert_sign_result); unset($cert_sign_result);
$cert_sign_result = $ca->getCertSign($hospital_entity_id, $hospital_entity_id, $data); $cert_sign_result = $CaOffline->getCertSign($hospital_entity_id, $hospital_entity_id, $data);
dump("获取医院云证书签名成功"); dump("获取医院云证书签名成功");
// 验证云证书签名-验证无需处理,只要不返回错误即可 // 验证云证书签名-验证无需处理,只要不返回错误即可
dump("验证医院云证书签名"); dump("验证医院云证书签名");
$ca->verifyPkcs7($cert_sign_result['signP7'], $data); $CaOffline->verifyPkcs7($cert_sign_result['signP7'], $data);
dump("验证医院云证书签名成功"); dump("验证医院云证书签名成功");
} }
@ -481,7 +482,7 @@ class OrderPrescriptionService extends BaseService
$data = array(); $data = array();
$data['sign_param'] = json_encode($sign_param); $data['sign_param'] = json_encode($sign_param);
$data['pdf_file'] = $pdf_file; $data['pdf_file'] = $pdf_file;
$sign_pdf_result = $ca->addSignPdf($user_entity_id, $data); $sign_pdf_result = $CaOffline->addSignPdf($user_entity_id, $data);
if (empty($sign_pdf_result[0]['fileId'])) { if (empty($sign_pdf_result[0]['fileId'])) {
throw new BusinessException("处方签章失败"); throw new BusinessException("处方签章失败");
} }
@ -490,7 +491,7 @@ class OrderPrescriptionService extends BaseService
// 下载处方签章文件 // 下载处方签章文件
$file_id = $sign_pdf_result[0]['fileId']; $file_id = $sign_pdf_result[0]['fileId'];
$prescription_pdf_result = $ca->getSignedFile($user_entity_id, $file_id); $prescription_pdf_result = $CaOffline->getSignedFile($user_entity_id, $file_id);
if (empty($prescription_pdf_result)) { if (empty($prescription_pdf_result)) {
throw new BusinessException("下载处方签章文件失败"); throw new BusinessException("下载处方签章文件失败");
@ -537,7 +538,7 @@ class OrderPrescriptionService extends BaseService
$data = array(); $data = array();
$data['sign_param'] = json_encode($sign_param); $data['sign_param'] = json_encode($sign_param);
$data['pdf_file'] = $pdf_file; $data['pdf_file'] = $pdf_file;
$hospital_sign_pdf_result = $ca->addSignPdf($hospital_entity_id, $data); $hospital_sign_pdf_result = $CaOffline->addSignPdf($hospital_entity_id, $data);
if (empty($hospital_sign_pdf_result[0]['fileId'])) { if (empty($hospital_sign_pdf_result[0]['fileId'])) {
throw new BusinessException("处方签章失败"); throw new BusinessException("处方签章失败");
} }
@ -547,7 +548,7 @@ class OrderPrescriptionService extends BaseService
// 下载处方签章文件 // 下载处方签章文件
unset($prescription_pdf_result); unset($prescription_pdf_result);
$file_id = $hospital_sign_pdf_result[0]['fileId']; $file_id = $hospital_sign_pdf_result[0]['fileId'];
$prescription_pdf_result = $ca->getSignedFile($hospital_entity_id, $file_id); $prescription_pdf_result = $CaOffline->getSignedFile($hospital_entity_id, $file_id);
if (empty($prescription_pdf_result)) { if (empty($prescription_pdf_result)) {
throw new BusinessException("下载处方签章文件失败"); throw new BusinessException("下载处方签章文件失败");

View File

@ -81,9 +81,16 @@ return [
"token" => "NDc5MzExMDMxMDY2NDMxNDg5L", // 鉴权回调使用 "token" => "NDc5MzExMDMxMDY2NDMxNDg5L", // 鉴权回调使用
], ],
'ca' => [ // ca 'ca' => [ // ca
"app_id" => env('CA_APP_ID', 'SCCA1560150113940832258'), "offline" => [
"secret" => env('CA_APP_SECRET', 'facded39929f4aef9893cb766cd52e25'), "app_id" => env('CA_OFFLINE_APP_ID', 'SCCA1560150113940832258'),
"api_url" => env('CA_API_URL', 'http://testmicrosrv.scca.com.cn:9527'), "secret" => env('CA_OFFLINE_APP_SECRET', 'facded39929f4aef9893cb766cd52e25'),
"api_url" => env('CA_OFFLINE_API_URL', 'http://testmicrosrv.scca.com.cn:9527'),
],
"online" => [
"app_id" => env('CA_ONLINE_APP_ID', 'SCCA1646691325903052802'),
"secret" => env('CA_ONLINE_APP_SECRET', 'adf718ebc1fb4bb7b158de9117d1313a'),
"api_url" => env('CA_ONLINE_API_URL', 'http://testmicrosrv.scca.com.cn:9527'),
],
], ],
'prescription_platform' => [ // 处方平台 'prescription_platform' => [ // 处方平台
"client_id" => env('PRE_PLAT_CLIENT_ID', 'ZD-004'), "client_id" => env('PRE_PLAT_CLIENT_ID', 'ZD-004'),

View File

@ -14,22 +14,10 @@ use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerInterface; 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 * @param array $data
@ -331,79 +319,4 @@ class Ca
throw new BusinessException($e->getMessage()); 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'];
}
} }

View File

@ -53,10 +53,15 @@ AMQP_USER=gdxz_2022rabbitmq
AMQP_PASSWORD=qwr2p&¥e@3.2p AMQP_PASSWORD=qwr2p&¥e@3.2p
AMQP_VHOST=gdxz_2022rabbitmq AMQP_VHOST=gdxz_2022rabbitmq
# [CA] # [CA-offline]
CA_APP_ID=SCCA1560150113940832258 CA_OFFLINE_APP_ID=SCCA1560150113940832258
CA_APP_SECRET=facded39929f4aef9893cb766cd52e25 CA_OFFLINE_APP_SECRET=facded39929f4aef9893cb766cd52e25
CA_API_URL=http://testmicrosrv.scca.com.cn:9527 CA_OFFLINE_API_URL=http://testmicrosrv.scca.com.cn:9527
# [CA-online]
CA_ONLINE_APP_ID=SCCA1646691325903052802
CA_ONLINE_APP_SECRET=adf718ebc1fb4bb7b158de9117d1313a
CA_ONLINE_API_URL=http://testmicrosrv.scca.com.cn:9527
# [处方平台] # [处方平台]
PRE_PLAT_CLIENT_ID=ZD-004 PRE_PLAT_CLIENT_ID=ZD-004