diff --git a/backend/.env b/backend/.env index 5784151..ca3f4c9 100644 --- a/backend/.env +++ b/backend/.env @@ -12,4 +12,15 @@ DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&ch ###< doctrine/doctrine-bundle ### DOT_DOT_URL='http://dot-dot.local' -API_TOKEN='secret' \ No newline at end of file +API_TOKEN='secret' + +###> KONTUR_DIADOC### +API_KONTUR_DIADOC_END_POINT_URL=https://diadoc-api.kontur.ru +API_KONTUR_DIADOC_API_TOKEN=API-3701ccdb-7bdf-4f29-bbe0-3a0278eee913 +API_KONTUR_DIADOC_LOGIN=LOGIN +API_KONTUR_DIADOC_PASSWORD=PASSWORD +###> KONTUR_DIADOC_POST_MESSAGE_DIRECTION### +API_KONTUR_DIADOC_PMD_BOX_ID=c1a0d340-a481-49b2-ba21-d51dea59df55 +API_KONTUR_DIADOC_PMD_FROM_DEPT_ID=00000000-0000-0000-0000-000000000000 +API_KONTUR_DIADOC_PMD_TO_DEPT_ID=da0f3b33-ef70-41e9-8e9e-fb431a891ef4 +###< KONTUR_DIADOC### \ No newline at end of file diff --git a/backend/config/routes.yaml b/backend/config/routes.yaml index 41ef814..ed04f5a 100644 --- a/backend/config/routes.yaml +++ b/backend/config/routes.yaml @@ -1,5 +1,5 @@ -controllers: +controllers_sign_document: resource: - path: ../src/Controller/ - namespace: App\Controller - type: attribute + path: ../src/SignDocument/Controller/ + namespace: App\SignDocument\Controller + type: attribute \ No newline at end of file diff --git a/backend/config/services.yaml b/backend/config/services.yaml index aede265..8803408 100644 --- a/backend/config/services.yaml +++ b/backend/config/services.yaml @@ -28,6 +28,6 @@ services: GuzzleHttp\Client: '@guzzle.http_client' - App\Api\ApiParams: + App\SignDocument\Api\ApiParams: arguments: $endPointUrl: '%env(DOT_DOT_URL)%' \ No newline at end of file diff --git a/backend/src/Controller/.gitignore b/backend/src/Controller/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/backend/src/Entity/.gitignore b/backend/src/Entity/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/backend/src/Repository/.gitignore b/backend/src/Repository/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/backend/src/Api/Api.php b/backend/src/SignDocument/Api/Api.php similarity index 97% rename from backend/src/Api/Api.php rename to backend/src/SignDocument/Api/Api.php index 0ad4285..e3404b0 100644 --- a/backend/src/Api/Api.php +++ b/backend/src/SignDocument/Api/Api.php @@ -2,11 +2,10 @@ declare(strict_types=1); -namespace App\Api; +namespace App\SignDocument\Api; use App\Infrastructure\External\Api\AbstractApi; use App\Infrastructure\External\Api\BinaryStringFileResult; -use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; class Api extends AbstractApi diff --git a/backend/src/Api/ApiParams.php b/backend/src/SignDocument/Api/ApiParams.php similarity index 80% rename from backend/src/Api/ApiParams.php rename to backend/src/SignDocument/Api/ApiParams.php index f920f32..044c612 100644 --- a/backend/src/Api/ApiParams.php +++ b/backend/src/SignDocument/Api/ApiParams.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Api; +namespace App\SignDocument\Api; class ApiParams { diff --git a/backend/src/SignDocument/Api/Request/DigitalSignatureRequest.php b/backend/src/SignDocument/Api/Request/DigitalSignatureRequest.php new file mode 100644 index 0000000..8fc03da --- /dev/null +++ b/backend/src/SignDocument/Api/Request/DigitalSignatureRequest.php @@ -0,0 +1,13 @@ +server->get('HTTP_AUTHORIZATION'); + + return new JsonResponse($this->digitalSignatureService->getSignature($digitalSignatureRequest, $token)); + } + +} \ No newline at end of file diff --git a/backend/src/Controller/SignController.php b/backend/src/SignDocument/Controller/SignController.php similarity index 85% rename from backend/src/Controller/SignController.php rename to backend/src/SignDocument/Controller/SignController.php index c7822b7..0dd1f21 100644 --- a/backend/src/Controller/SignController.php +++ b/backend/src/SignDocument/Controller/SignController.php @@ -2,15 +2,15 @@ declare(strict_types=1); -namespace App\Controller; +namespace App\SignDocument\Controller; -use App\Api\Request\SignRequest; -use App\SignService; +use App\SignDocument\Api\Request\SignRequest; +use App\SignDocument\Services\SignService; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Annotation\Route; class SignController extends AbstractController { diff --git a/backend/src/DevSignService.php b/backend/src/SignDocument/Services/DevSignService.php similarity index 83% rename from backend/src/DevSignService.php rename to backend/src/SignDocument/Services/DevSignService.php index d9a8dc8..ef8653a 100644 --- a/backend/src/DevSignService.php +++ b/backend/src/SignDocument/Services/DevSignService.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App; +namespace App\SignDocument\Services; class DevSignService { diff --git a/backend/src/SignDocument/Services/DigitalSignatureService.php b/backend/src/SignDocument/Services/DigitalSignatureService.php new file mode 100644 index 0000000..5b5744a --- /dev/null +++ b/backend/src/SignDocument/Services/DigitalSignatureService.php @@ -0,0 +1,45 @@ +apiToken) { + throw new AccessDeniedHttpException('Доступ запрещен'); + } + + $this->api->apiParams = $this->apiParams; + + try { + $document = $this->api->download($request->url, $token); + + exec(sprintf('cp %s %s.pdf', $document->tempFileName, $document->tempFileName)); + $signature = exec(sprintf('cryptcp -sign -detached -der %s', $document->tempFileName)); + + $response = base64_encode($signature); + + $this->removeExistingDocumentService->removeExistingDocument($document); + + return $response; + } catch (Exception $e) { + throw new RuntimeException($e->getMessage()); + } + } +} \ No newline at end of file diff --git a/backend/src/ProdSignService.php b/backend/src/SignDocument/Services/ProdSignService.php similarity index 94% rename from backend/src/ProdSignService.php rename to backend/src/SignDocument/Services/ProdSignService.php index 3207646..0a69756 100644 --- a/backend/src/ProdSignService.php +++ b/backend/src/SignDocument/Services/ProdSignService.php @@ -3,7 +3,7 @@ declare(strict_types=1); -namespace App; +namespace App\SignDocument\Services; class ProdSignService diff --git a/backend/src/SignDocument/Services/RemoveExistingDocumentService.php b/backend/src/SignDocument/Services/RemoveExistingDocumentService.php new file mode 100644 index 0000000..0020cb6 --- /dev/null +++ b/backend/src/SignDocument/Services/RemoveExistingDocumentService.php @@ -0,0 +1,18 @@ +tempFileName)) { + unlink($document->tempFileName); + } + } +} \ No newline at end of file diff --git a/backend/src/SignService.php b/backend/src/SignDocument/Services/SignService.php similarity index 62% rename from backend/src/SignService.php rename to backend/src/SignDocument/Services/SignService.php index 5a3b44e..5a981f4 100644 --- a/backend/src/SignService.php +++ b/backend/src/SignDocument/Services/SignService.php @@ -2,27 +2,24 @@ declare(strict_types=1); -namespace App; +namespace App\SignDocument\Services; -use App\Api\Api; -use App\Api\ApiParams; -use App\Api\Request\SignRequest; -use App\Infrastructure\External\Api\BinaryStringFileResult; +use App\SignDocument\Api\Api; +use App\SignDocument\Api\ApiParams; +use App\SignDocument\Api\Request\SignRequest; use Exception; use RuntimeException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; class SignService { - private DevSignService $devSignService; - private ProdSignService $prodSignService; - public function __construct( - private Api $api, - private ApiParams $apiParams + private readonly Api $api, + private readonly ApiParams $apiParams, + private readonly DevSignService $devSignService, + private readonly ProdSignService $prodSignService, + private readonly RemoveExistingDocumentService $removeExistingDocumentService, ){ - $this->devSignService = new DevSignService(); - $this->prodSignService = new ProdSignService(); } public function signDocument(SignRequest $request,string $token): array { @@ -39,7 +36,7 @@ class SignService $response = $this->api->send($token, $document->tempFileName . '_sign.pdf', $request->batch); - $this->removeExistingDocument($document); + $this->removeExistingDocumentService->removeExistingDocument($document); return $response; } catch (Exception $e) { @@ -54,11 +51,4 @@ class SignService 'prod' => $this->prodSignService->sign($documentUrl), }; } - - private function removeExistingDocument(BinaryStringFileResult $document): void - { - if (file_exists($document->tempFileName)) { - unlink($document->tempFileName); - } - } } \ No newline at end of file