From 019ac8fcc5c5e83f77c8c86bc961369499927feb Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Wed, 22 Mar 2023 17:53:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E9=97=AE=E8=AF=8A=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E8=B0=83=E6=95=B4=E6=AC=A1=E6=95=B0=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/TestController.php | 30 +++--- app/Services/DoctorInquiryService.php | 48 +++++----- app/Services/PatientDoctorService.php | 2 +- extend/Alibaba/Oss.php | 1 + extend/Ca/Ca.php | 130 ++++++++++++++++---------- 5 files changed, 118 insertions(+), 93 deletions(-) diff --git a/app/Controller/TestController.php b/app/Controller/TestController.php index 791c7b3..eab2eb5 100644 --- a/app/Controller/TestController.php +++ b/app/Controller/TestController.php @@ -19,8 +19,8 @@ class TestController extends AbstractController // $this->test_8(); // $this->test_3(); // $this->test_4(); - $this->test_6(); - +// $this->test_6(); + $this->test_9(); } @@ -308,22 +308,12 @@ class TestController extends AbstractController $pdf->AddPage(); $pdf->Image('@' . $result, 10, 10, 0, 0, '', '', '', false, 300, '', false, false, 0, false, false, false); - return $pdf->Output("","S"); + $pdf->Output(dirname(__DIR__, 2) . "/prescription_img.pdf","F"); } // pdf进行签章 public function test_6(){ - $pdf_file = $this->test_5(); - -// $oss = new Oss(); -// $filename = "Basic/images/prescription_img.jpg"; -// -// $pdf_file = $oss->getObjectToRAM($filename); -// $pdf_file = file_get_contents('./runtime/dsddasdasdasdasdasdsa.pdf'); - -// $pdf_file = new \CURLFILE('./runtime/dsddasdasdasdasdasdsa.pdf'); -// $pdf_file = fopen("/Users/wucongxing/Desktop/work/php/hospital-applets-api/runtime/dsddasdasdasdasdasdsa.pdf",'f'); -// dump($pdf_file);die; + $pdf_file = fopen("./runtime/prescription_img.pdf",'r'); $oss = new Oss(); @@ -337,8 +327,6 @@ class TestController extends AbstractController return fail(HttpEnumCode::SERVER_ERROR); } -// $sign_image = urlencode($sign_image); - $sign_param = [ [ "llx"=> "700", // 左边底部X坐标 @@ -355,7 +343,8 @@ class TestController extends AbstractController $ca = new Ca(); $result = $ca->addSignPdf("491925054435950592",$data); - dump($result); +// fclose($data['pdf_file']); + } // 延迟队列测试 @@ -397,4 +386,11 @@ class TestController extends AbstractController $ca = new Ca(); $result = $ca->deleteUserSignConfig("491925054435950592"); } + + // 下载签章的pdf文件 + public function test_9(){ + $ca = new Ca(); + $result = $ca->getSignedFile("491925054435950592","1638477783898161153"); + } + } \ No newline at end of file diff --git a/app/Services/DoctorInquiryService.php b/app/Services/DoctorInquiryService.php index 163f54d..f541b5f 100644 --- a/app/Services/DoctorInquiryService.php +++ b/app/Services/DoctorInquiryService.php @@ -338,30 +338,30 @@ class DoctorInquiryService extends BaseService } } else { // 在线问诊限制在线问诊验证修改次数 - if ($inquiry_type == 1 && $doctor_inquiry_config['inquiry_price'] != $inquiry_price) { - // 获取月份内总调整次数 - $params = array(); - $params[] = ['doctor_id', '=', $user_info['client_user_id']]; - $params[] = ['inquiry_config_id', '=', $doctor_inquiry_config['inquiry_config_id']]; - $params[] = ['created_at', '>', date('Y-m-01', time())]; - $modify_month_count = DoctorInquiryPriceRecord::getCount($params); - if ($modify_month_count >= 5) { - // 每自然月仅限调整5次 - Db::rollBack(); - return fail(HttpEnumCode::HTTP_ERROR, "问诊价格每自然月仅限调整5次"); - } - - $params = array(); - $params[] = ['doctor_id', '=', $user_info['client_user_id']]; - $params[] = ['inquiry_config_id', '=', $doctor_inquiry_config['inquiry_config_id']]; - $params[] = ['created_at', '>', date('Y-m-d', time())]; - $modify_month_count = DoctorInquiryPriceRecord::getCount($params); - if ($modify_month_count >= 1) { - // 问诊价格每日仅限调整1次 - Db::rollBack(); - return fail(HttpEnumCode::HTTP_ERROR, "问诊价格每日仅限调整1次"); - } - } +// if ($inquiry_type == 1 && $doctor_inquiry_config['inquiry_price'] != $inquiry_price) { +// // 获取月份内总调整次数 +// $params = array(); +// $params[] = ['doctor_id', '=', $user_info['client_user_id']]; +// $params[] = ['inquiry_config_id', '=', $doctor_inquiry_config['inquiry_config_id']]; +// $params[] = ['created_at', '>', date('Y-m-01', time())]; +// $modify_month_count = DoctorInquiryPriceRecord::getCount($params); +// if ($modify_month_count >= 5) { +// // 每自然月仅限调整5次 +// Db::rollBack(); +// return fail(HttpEnumCode::HTTP_ERROR, "问诊价格每自然月仅限调整5次"); +// } +// +// $params = array(); +// $params[] = ['doctor_id', '=', $user_info['client_user_id']]; +// $params[] = ['inquiry_config_id', '=', $doctor_inquiry_config['inquiry_config_id']]; +// $params[] = ['created_at', '>', date('Y-m-d', time())]; +// $modify_month_count = DoctorInquiryPriceRecord::getCount($params); +// if ($modify_month_count >= 1) { +// // 问诊价格每日仅限调整1次 +// Db::rollBack(); +// return fail(HttpEnumCode::HTTP_ERROR, "问诊价格每日仅限调整1次"); +// } +// } // 修改 if ($doctor_inquiry_config['work_num_day'] != $work_num_day || $doctor_inquiry_config['inquiry_price'] != $inquiry_price) { diff --git a/app/Services/PatientDoctorService.php b/app/Services/PatientDoctorService.php index be3c746..1ede3d6 100644 --- a/app/Services/PatientDoctorService.php +++ b/app/Services/PatientDoctorService.php @@ -28,7 +28,7 @@ class PatientDoctorService extends BaseService $expertise_id = $this->request->input('expertise_id'); $province_id = $this->request->input('province_id'); $city_id = $this->request->input('city_id'); - $sort_order = $this->request->input('sort_order'); + $sort_order = $this->request->input('sort_order',1); $keyword = $this->request->input('keyword',""); $page = $this->request->input('page',1); $per_page = $this->request->input('per_page',10); diff --git a/extend/Alibaba/Oss.php b/extend/Alibaba/Oss.php index 588886a..2b371b0 100644 --- a/extend/Alibaba/Oss.php +++ b/extend/Alibaba/Oss.php @@ -141,4 +141,5 @@ class Oss throw new BusinessException($e->getMessage()); } } + } \ No newline at end of file diff --git a/extend/Ca/Ca.php b/extend/Ca/Ca.php index 4ea28b5..02fb17a 100644 --- a/extend/Ca/Ca.php +++ b/extend/Ca/Ca.php @@ -24,7 +24,8 @@ class Ca #[Inject] protected Client $client; - public function __construct(){ + public function __construct() + { $this->container = ApplicationContext::getContainer(); $this->client = $this->container->get(Client::class); } @@ -47,7 +48,7 @@ class Ca try { $response = $this->httpRequest(config("ca.api_url") . '/cloud-certificate-service' . '/api/cloudCert/open/v2/cert/offlineAuthCertEnroll', $option); - if (empty($response)){ + if (empty($response)) { // 返回值为空 throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); } @@ -64,12 +65,12 @@ class Ca * @param array $data * @return mixed */ - public function getCertSign(string $user_id,string $pin,array $data): mixed + public function getCertSign(string $user_id, string $pin, array $data): mixed { $option = [ 'form_params' => [ 'entityId' => $user_id, // 用户唯一标识,由业务系统定义 - 'toSign' => hash_hmac("sha1",json_encode($data,JSON_UNESCAPED_UNICODE),config("ca.secret")), // 签名原文 + 'toSign' => hash_hmac("sha1", json_encode($data, JSON_UNESCAPED_UNICODE), config("ca.secret")), // 签名原文 'pin' => $pin, // 证书PIN码 ] ]; @@ -79,7 +80,7 @@ class Ca config("ca.api_url") . '/cloud-certificate-service' . '/api/cloudCert/open/cert/sign', $option ); - if (empty($response)){ + if (empty($response)) { // 返回值为空 throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); } @@ -91,7 +92,8 @@ class Ca // PKCS7签名验证接口 // 对客户端签名信息进行验证,返回证书信息,同时可以配置回调服务,在验证成功后回调业务系统 - public function verifyPkcs7(string $sign_p7,array $data){ + public function verifyPkcs7(string $sign_p7, array $data) + { $generator = $this->container->get(IdGeneratorInterface::class); $option = [ @@ -99,7 +101,7 @@ class Ca 'opType' => "签名验证", 'requestId' => $generator->generate(),// 业务流水号,唯一 'signedData' => $sign_p7, // 签名值:签名接口返回的signP7 - 'toSign' => hash_hmac("sha1",json_encode($data,JSON_UNESCAPED_UNICODE),config("ca.secret")), // 签名原文 + 'toSign' => hash_hmac("sha1", json_encode($data, JSON_UNESCAPED_UNICODE), config("ca.secret")), // 签名原文 ] ]; @@ -108,7 +110,7 @@ class Ca config("ca.api_url") . '/signgw-service/api/signature/verifyPkcs7', $option ); - if (empty($response)){ + if (empty($response)) { // 返回值为空 throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); } @@ -125,7 +127,7 @@ class Ca * @param array $data * @return mixed */ - public function addUserSignConfig(string $user_id,string $card_num,array $data): mixed + public function addUserSignConfig(string $user_id, string $card_num, array $data): mixed { $option = [ 'form_params' => [ @@ -196,7 +198,7 @@ class Ca config("ca.api_url") . '/signature-server/api/open/signature/fetchUserSeal', $option ); - if (empty($response)){ + if (empty($response)) { // 返回值为空 throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); } @@ -208,35 +210,32 @@ class Ca /** * PDF添加电子签章 + * @param string $user_id + * @param array $data + * @return mixed */ - public function addSignPdf(string $user_id,array $data){ + public function addSignPdf(string $user_id, array $data) + { $option = [ -// 'form_params' => [ -// 'userId' => $user_id,// 用户标识信息 -// 'configKey' => $user_id,// 签章配置唯一标识 -// 'signParams' => $data['sign_param'],// 签章参数,JSON格式数据,如果不指定,那么以签章配置接口配置为准 -// 'pdfFile' => $data['pdf_file'],// 待签章PDF文件(字节流) -// 'cloudCertPass' => $user_id,// 云证书PIN码,云证书签章时使用 -// ], 'multipart' => [ [ - 'name' => 'pdfFile', - 'contents' => $data['pdf_file'], + 'name' => 'pdfFile', + 'contents' => $data['pdf_file'],// 待签章PDF文件(字节流) ], [ - 'name' => 'userId', + 'name' => 'userId', 'contents' => $user_id, // 用户标识信息 ], [ - 'name' => 'configKey', + 'name' => 'configKey', 'contents' => $user_id, // 签章配置唯一标识 ], [ - 'name' => 'signParams', + 'name' => 'signParams', 'contents' => $data['sign_param'],// 签章参数,JSON格式数据,如果不指定,那么以签章配置接口配置为准 ], [ - 'name' => 'cloudCertPass', + 'name' => 'cloudCertPass', 'contents' => $user_id,// 云证书PIN码,云证书签章时使用 ], ] @@ -248,7 +247,37 @@ class Ca $option ); - if (empty($response)){ + if (empty($response)) { + // 返回值为空 + throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); + } + return $response; + } catch (GuzzleException $e) { + throw new BusinessException($e->getMessage()); + } + } + + /** + * 下载签章的pdf文件 + * @param string $user_id + * @param string $file_id + * @return mixed + */ + public function getSignedFile(string $user_id, string $file_id): mixed + { + $option = [ + 'form_params' => [ + 'userId' => $user_id,// 用户标识信息(为云证书entityId) + 'fileId' => $file_id,// 签章接口返回的文件标识 + ] + ]; + + try { + $response = $this->httpRequest( + config("ca.api_url") . '/signature-server/api/open/signature/fetchSignedFile', + $option + ); + if (empty($response)) { // 返回值为空 throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); } @@ -259,7 +288,6 @@ class Ca } - /** * 获取请求签名 * @param array $data @@ -267,22 +295,26 @@ class Ca */ protected function getRequestSign(array $data): string { - // pdf进行签章时,此参数为文件流,不参与签名 - unset($data['form_params']['pdfFile']); + $sign_data = array(); + if (isset($data['form_params'])) { + $sign_data = $data['form_params']; + } - // signParams参数计算时不进行urlencode处理 -// if (isset($data['form_params']['signParams'])){ -// $sign_param = json_decode($data['form_params']['signParams'],true); -// $sign_param[0]['sealImg'] = urldecode($sign_param[0]['sealImg']); -// -// $data['form_params']['signParams'] = json_encode($sign_param); -// } + if (isset($data['multipart'])) { + foreach ($data['multipart'] as $item) { + // pdf进行签章时,此参数为文件流,不参与签名 + if ($item['name'] == "pdfFile") { + continue; + } + $sign_data[$item['name']] = $item['contents']; + } + } - ksort($data['form_params']); - $data = implode('&',$data['form_params']); - dump($data); - $data = hash_hmac("sha1",$data,config("ca.secret")); + ksort($sign_data); + $data = implode('&', $sign_data); + + $data = hash_hmac("sha1", $data, config("ca.secret")); return $data; } @@ -293,7 +325,7 @@ class Ca * @return mixed * @throws GuzzleException */ - protected function httpRequest(string $path,array $arg = []): mixed + protected function httpRequest(string $path, array $arg = []): mixed { $option = [ "headers" => [ @@ -302,28 +334,24 @@ class Ca ], ]; - $arg = array_merge($arg,$option); + $arg = array_merge($arg, $option); - try { - $response = $this->client->post($path, $arg); - }catch(\Exception $e){ - dump($e->getMessage()); - } + $response = $this->client->post($path, $arg); - if ($response->getStatusCode() != '200'){ + if ($response->getStatusCode() != '200') { // 请求失败 throw new BusinessException($response->getBody()->getContents()); } - $body = json_decode($response->getBody(),true); + $body = json_decode($response->getBody(), true); dump($body); - if (empty($body)){ + if (empty($body)) { // 返回值为空 throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); } - if ($body['result_code'] != 0){ + if ($body['result_code'] != 0) { // 请求失败 - if (!empty($body['result_msg'])){ + if (!empty($body['result_msg'])) { throw new BusinessException($body['result_msg']); } throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));