From c0e5d795b887d238468dbac73d8229cfd183c752 Mon Sep 17 00:00:00 2001 From: cherednik Date: Fri, 11 Oct 2024 18:19:53 +0400 Subject: [PATCH] =?UTF-8?q?TD-322:=20[BACK].=20[=D1=80=D0=B5=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D1=81=D0=B5=D1=80?= =?UTF-8?q?=D0=B2=D0=B8=D1=81=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=B4?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BE=D0=BA?= =?UTF-8?q?=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20=D0=B2=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=82=D0=B5=D0=B9=D0=BD=D0=B5=D1=80=D0=B5=20signer?= =?UTF-8?q?]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/Api/Api.php | 45 ++++++++++++++++----------------- backend/src/DevSignService.php | 13 ++++++++++ backend/src/ProdSignService.php | 16 ++++++++++++ backend/src/SignService.php | 22 ++++++---------- 4 files changed, 59 insertions(+), 37 deletions(-) create mode 100644 backend/src/DevSignService.php create mode 100644 backend/src/ProdSignService.php diff --git a/backend/src/Api/Api.php b/backend/src/Api/Api.php index 5ceef4d..adf5cc9 100644 --- a/backend/src/Api/Api.php +++ b/backend/src/Api/Api.php @@ -11,35 +11,34 @@ use GuzzleHttp\RequestOptions; class Api extends AbstractApi { - private const string TYPE_OTHER = 'other'; - private const string API_DOCUMENT = '/api/v1/document/upload/batch/'; public ApiParams $apiParams; - public function send(string $url, string $token, $urlDocument, int $batch): array + public function send(string $token, string $path, int $batch): array { - $headers = [ - 'Accept' => 'application/json', - 'Authorization' => $token, - ]; - $options = [ - 'multipart' => [ - [ - 'name' => 'type', - 'contents' => self::TYPE_OTHER - ], + $params = [ + RequestOptions::HEADERS => [ + 'Authorization' => $token, + 'Accept' => 'application/json', + ], + RequestOptions::MULTIPART => [ [ 'name' => 'file', - 'contents' => fopen($urlDocument, 'r'), - 'filename' => 'sign_attorney.pdf', - 'headers' => [ - 'Content-Type' => '' - ] - ] - ]]; - $request = new Request('POST', sprintf('%s%s%s', $url, self::API_DOCUMENT, $batch), $headers); - $res = $this->client->sendAsync($request, $options)->wait(); + 'contents' => fopen($path, 'r'), + 'filename' => $path, + 'headers' => [ + 'Content-Type' => '', + ], + ], + [ + 'name' => 'type', + 'contents' => 'other' + ], + ], + ]; - return $this->responseHandler->setResponse($res)->getContentJsonToArray(); + $response = $this->client->post(sprintf('%s%s%s', $this->apiParams->endPointUrl, '/api/v1/document/upload/batch/', $batch), $params); + + return $this->responseHandler->setResponse($response)->getContentJsonToArray(); } public function download(string $url, string $token): BinaryStringFileResult diff --git a/backend/src/DevSignService.php b/backend/src/DevSignService.php new file mode 100644 index 0000000..d9a8dc8 --- /dev/null +++ b/backend/src/DevSignService.php @@ -0,0 +1,13 @@ +devSignService = new DevSignService(); + $this->prodSignService = new ProdSignService(); } public function signDocument(string $url, string $token, int $batch): array { @@ -26,7 +31,7 @@ class SignService $this->sign($document->tempFileName); - $response = $this->api->send($this->apiParams->endPointUrl, $token, $document->tempFileName . '_sign.pdf', $batch); + $response = $this->api->send($token, $document->tempFileName . '_sign.pdf', $batch); $this->removeExistingDocument($document); @@ -39,22 +44,11 @@ class SignService private function sign (string $documentUrl): void { match ($_ENV['APP_ENV']) { - 'dev' => $this->signDev($documentUrl), - 'prod' => $this->signProd($documentUrl), + 'dev' => $this->devSignService->sign($documentUrl), + 'prod' => $this->prodSignService->sign($documentUrl), }; } - private function signDev(string $documentUrl): void - { - exec(sprintf('cp %s %s_sign.pdf', $documentUrl, $documentUrl)); - } - - private function signProd(string $documentUrl): void - { - exec(sprintf('cp %s %s.pdf', $documentUrl, $documentUrl)); - exec(sprintf('pdfcpro sign /mnt/t/%s.pdf -out /mnt/t/%s_sign.pdf -cert ${SHA} -text "\n\t\tПодписано ЭП\n\t\t{subject/cn}\n\t\tСертификат {sha1}\n\t\tДействителен от {since} до {until}\n\t\tДата {date}\n\t\t{subject/t}\n\t\t{subject/fullname}\n\t\t" -fontfile /usr/local/share/fonts/Inter-Bold.ttf -fontsize 8 -x 2 -y 2 -w 96 -h 9', $documentUrl, $documentUrl)); - } - private function removeExistingDocument(BinaryStringFileResult $document): void { if (file_exists($document->tempFileName)) {