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)) {