Compare commits
11 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
2845a7d528 | |
|
|
bf677487d3 | |
|
|
bd3d4b3303 | |
|
|
0e560b59b1 | |
|
|
3dfe7dba30 | |
|
|
b7d24cd749 | |
|
|
a4a12752b8 | |
|
|
6533368534 | |
|
|
82ae1cbdf8 | |
|
|
6943c9c41f | |
|
|
52d40c6249 |
14
Dockerfile
14
Dockerfile
|
|
@ -4,12 +4,12 @@ ARG DEBIAN_FRONTEND=noninteractive
|
|||
RUN apt update && apt install -y wget libgtk-3-0 libpcsclite-dev pcscd curl software-properties-common git zip bash
|
||||
RUN add-apt-repository ppa:ondrej/php
|
||||
RUN apt update && apt install -y \
|
||||
php-fpm \
|
||||
php-curl \
|
||||
php \
|
||||
php-common \
|
||||
php-cli \
|
||||
php-xml \
|
||||
php8.3-fpm \
|
||||
php8.3-curl \
|
||||
php8.3 \
|
||||
php8.3-common \
|
||||
php8.3-cli \
|
||||
php8.3-xml \
|
||||
gnupg \
|
||||
g++ \
|
||||
procps \
|
||||
|
|
@ -55,7 +55,7 @@ RUN apt update && apt install -y okular-csp-utils
|
|||
|
||||
RUN mkdir -p /root/.config
|
||||
COPY license.key /license.key
|
||||
RUN echo Y | pdfcpro install-license /license.key
|
||||
# RUN echo Y | pdfcpro install-license /license.key
|
||||
COPY Inter-Bold.ttf /usr/local/share/fonts/Inter-Bold.ttf
|
||||
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ ARG DEBIAN_FRONTEND=noninteractive
|
|||
RUN apt update && apt install -y wget libgtk-3-0 libpcsclite-dev pcscd curl software-properties-common git zip bash
|
||||
RUN add-apt-repository ppa:ondrej/php
|
||||
RUN apt update && apt install -y \
|
||||
php-fpm \
|
||||
php-curl \
|
||||
php \
|
||||
php-common \
|
||||
php-cli \
|
||||
php-xml \
|
||||
php8.3-fpm \
|
||||
php8.3-curl \
|
||||
php8.3 \
|
||||
php8.3-common \
|
||||
php8.3-cli \
|
||||
php8.3-xml \
|
||||
gnupg \
|
||||
g++ \
|
||||
procps \
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace App\Infrastructure\Api\Response;
|
||||
|
||||
// Абстрактный респонс - от него наследуются нужные респонсы для стандартизации ответа в ApiHelperTrait -> createNewJsonResponse
|
||||
|
||||
abstract class AbstractResponse
|
||||
{
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Infrastructure\External\Api;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Враппер бинарных фалов, при создании класса содает новый временный файл,
|
||||
* при необходимости сохраняет файл под новым именем
|
||||
|
|
@ -23,4 +25,14 @@ class BinaryStringFileResult
|
|||
$this->tempFileName = sprintf('%s/%s_%s', sys_get_temp_dir(), 'Document', time());
|
||||
file_put_contents($this->tempFileName, $content);
|
||||
}
|
||||
|
||||
public function remove(): bool
|
||||
{
|
||||
if (file_exists($this->tempFileName)) {
|
||||
unlink($this->tempFileName);
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new RuntimeException('Temp file not found');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,15 @@ namespace App\SignDocument\Api;
|
|||
|
||||
use App\Infrastructure\External\Api\AbstractApi;
|
||||
use App\Infrastructure\External\Api\BinaryStringFileResult;
|
||||
use GuzzleHttp\Exception\BadResponseException;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
|
||||
class Api extends AbstractApi
|
||||
{
|
||||
public ApiParams $apiParams;
|
||||
|
||||
public function send(string $token, string $path, int $batch): array
|
||||
public function send(string $token, string $path, int $order): array
|
||||
{
|
||||
$params = [
|
||||
RequestOptions::HEADERS => [
|
||||
|
|
@ -22,7 +24,7 @@ class Api extends AbstractApi
|
|||
RequestOptions::MULTIPART => [
|
||||
[
|
||||
'name' => 'file',
|
||||
'contents' => fopen($path, 'r'),
|
||||
'contents' => file_get_contents($path),
|
||||
'filename' => $path,
|
||||
'headers' => [
|
||||
'Content-Type' => '<Content-type header>',
|
||||
|
|
@ -35,7 +37,7 @@ class Api extends AbstractApi
|
|||
],
|
||||
];
|
||||
|
||||
$response = $this->client->post(sprintf('%s%s%s', $this->apiParams->endPointUrl, '/api/v1/document/upload/batch/', $batch), $params);
|
||||
$response = $this->client->post(sprintf('%s%s%s', $this->apiParams->endPointUrl, '/api/v1/documents/upload/carrier/order/', $order), $params);
|
||||
|
||||
return $this->responseHandler->setResponse($response)->getContentJsonToArray();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ use App\Infrastructure\Http\RequestDtoInterface;
|
|||
class SignRequest implements RequestDtoInterface
|
||||
{
|
||||
public string $url;
|
||||
public int $batch;
|
||||
public int $order;
|
||||
public string $apiToken;
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\SignDocument\Api\Response;
|
||||
|
||||
use App\Infrastructure\Api\Response\AbstractResponse;
|
||||
|
||||
class DigitalSignatureResponse extends AbstractResponse
|
||||
{
|
||||
public function __construct(
|
||||
public string $hash,
|
||||
public string $content,
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -25,8 +25,8 @@ class DigitalSignatureController extends AbstractController
|
|||
{
|
||||
$token = $request->server->get('HTTP_AUTHORIZATION');
|
||||
|
||||
return $this->createJsonResponse([
|
||||
'hash' => $this->digitalSignatureService->getSignature($digitalSignatureRequest, $token),
|
||||
]);
|
||||
return $this->createJsonResponseFromObject(
|
||||
$this->digitalSignatureService->getSignature($digitalSignatureRequest, $token)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,22 +4,31 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\SignDocument\Services;
|
||||
|
||||
use App\Infrastructure\External\Api\BinaryStringFileResult;
|
||||
use App\SignDocument\Api\Api;
|
||||
use App\SignDocument\Api\ApiParams;
|
||||
use App\SignDocument\Api\Request\DigitalSignatureRequest;
|
||||
use App\SignDocument\Api\Response\DigitalSignatureResponse;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Exception;
|
||||
use RuntimeException;
|
||||
|
||||
class DigitalSignatureService
|
||||
{
|
||||
private BinaryStringFileResult $document;
|
||||
|
||||
public function __construct(
|
||||
private readonly Api $api,
|
||||
private readonly ApiParams $apiParams,
|
||||
private readonly RemoveExistingDocumentService $removeExistingDocumentService,
|
||||
){
|
||||
}
|
||||
public function getSignature(DigitalSignatureRequest $request, string $token): string
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->document->remove();
|
||||
}
|
||||
|
||||
public function getSignature(DigitalSignatureRequest $request, string $token): DigitalSignatureResponse
|
||||
{
|
||||
if ($_ENV['API_TOKEN'] !== $request->apiToken) {
|
||||
throw new AccessDeniedHttpException('Доступ запрещен');
|
||||
|
|
@ -28,16 +37,17 @@ class DigitalSignatureService
|
|||
$this->api->apiParams = $this->apiParams;
|
||||
|
||||
try {
|
||||
$document = $this->api->download($request->url, $token);
|
||||
$this->document = $this->api->download($request->url, $token);
|
||||
|
||||
exec(sprintf('cp %s %s.pdf', $document->tempFileName, $document->tempFileName));
|
||||
exec(sprintf('cryptcp -sign -detached -der %s', $document->tempFileName . '.pdf'));
|
||||
exec(sprintf('cp %s %s.pdf', $this->document->tempFileName, $this->document->tempFileName));
|
||||
exec(sprintf('cryptcp -sign -detached -der %s.pdf', $this->document->tempFileName));
|
||||
|
||||
$response = base64_encode(file_get_contents($document->tempFileName . '.pdf.sgn'));
|
||||
$response = base64_encode(file_get_contents($this->document->tempFileName . '.pdf.sgn'));
|
||||
|
||||
$this->removeExistingDocumentService->removeExistingDocument($document);
|
||||
|
||||
return $response;
|
||||
return new DigitalSignatureResponse(
|
||||
hash: $response,
|
||||
content: base64_encode(file_get_contents(sprintf('%s.pdf', $this->document->tempFileName)))
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
throw new RuntimeException($e->getMessage());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class SignService
|
|||
|
||||
$this->sign($document->tempFileName);
|
||||
|
||||
$response = $this->api->send($token, $document->tempFileName . '_sign.pdf', $request->batch);
|
||||
$response = $this->api->send($token, $document->tempFileName . '_sign.pdf', $request->order);
|
||||
|
||||
$this->removeExistingDocumentService->removeExistingDocument($document);
|
||||
|
||||
|
|
|
|||
38
license.key
38
license.key
|
|
@ -1,22 +1,22 @@
|
|||
-----BEGIN PGP MESSAGE-----
|
||||
|
||||
owGbwMvMwMX4m2NrnreKjyDj6QN7khjSpXteViuVpRYVZ+bnKVkpKBkq6Sgo5WQm
|
||||
p+YVp4L4ZhbmaakmSYm6BhaWqbomSamJupYpyca6aYYGScZJxsbJ5qmpIC0FRfkp
|
||||
pcklIC352aU5iUW6xalFQHOR5OKRrAEJ5yXmgq2IKTUwMTICkcapINLEHMxOBJMG
|
||||
uvilFUCUYRJC2tgYTFqAlRqCSSOECEwbyP7U3MTMHJAD8vKLU/Oy8x0yS/RS8kt0
|
||||
gVivqBSkorgksaikGKTEyMDIRNfQQNfINMTAwAqMosBmVBRkFqUiKTHUNTIJMTK2
|
||||
MrUEIrCSvNLcpNSi+Py0eGiwglQb1nYyGbMwMHIxyIopsiwQMwp8yVJVvW7Xvj2w
|
||||
+GFlAsUNAxenAExk6QL+PxwK68QK1M50+n6+5/nqf67rlhvB1Yef7bh99zJzstHz
|
||||
LSdsOD4ee3Ik5rf+FtaUfX+nGBpwGmrMb/IqOzC3VfN73/WFEgJb/s5ZocZguCI9
|
||||
aM214nT57238r+tcp/LOfrHoxLEt+j8V5rO17S65PaHVRr3Tv6th0icNiZJD3/er
|
||||
pxtUmHzQKw7h22jIypd3bV3W5teZ04U68jbX3np0wOuZ/fdFB/fUzm2bvHzn2b6p
|
||||
jJ7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