TD-322: [BACK]. [реализовать сервис для подписания документов в контейнере signer] #2
|
|
@ -11,3 +11,5 @@ APP_SECRET=850da55654c68f779822ea80d2b66a94
|
||||||
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
|
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
|
||||||
###< doctrine/doctrine-bundle ###
|
###< doctrine/doctrine-bundle ###
|
||||||
DOT_DOT_URL='http://dot-dot.local'
|
DOT_DOT_URL='http://dot-dot.local'
|
||||||
|
|
||||||
|
API_TOKEN='secret'
|
||||||
|
|
@ -10,4 +10,5 @@ class SignRequest implements RequestDtoInterface
|
||||||
{
|
{
|
||||||
public string $url;
|
public string $url;
|
||||||
public int $batch;
|
public int $batch;
|
||||||
|
public string $apiToken;
|
||||||
}
|
}
|
||||||
|
|
@ -24,6 +24,6 @@ class SignController extends AbstractController
|
||||||
{
|
{
|
||||||
$token = $request->server->get('HTTP_AUTHORIZATION');
|
$token = $request->server->get('HTTP_AUTHORIZATION');
|
||||||
|
|
||||||
return new JsonResponse($this->signService->signDocument($signRequest->url, $token, $signRequest->batch));
|
return new JsonResponse($this->signService->signDocument($signRequest, $token));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,9 +6,11 @@ namespace App;
|
||||||
|
|
||||||
use App\Api\Api;
|
use App\Api\Api;
|
||||||
use App\Api\ApiParams;
|
use App\Api\ApiParams;
|
||||||
|
use App\Api\Request\SignRequest;
|
||||||
use App\Infrastructure\External\Api\BinaryStringFileResult;
|
use App\Infrastructure\External\Api\BinaryStringFileResult;
|
||||||
use Exception;
|
use Exception;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
|
|
||||||
class SignService
|
class SignService
|
||||||
{
|
{
|
||||||
|
|
@ -22,16 +24,20 @@ class SignService
|
||||||
$this->devSignService = new DevSignService();
|
$this->devSignService = new DevSignService();
|
||||||
$this->prodSignService = new ProdSignService();
|
$this->prodSignService = new ProdSignService();
|
||||||
}
|
}
|
||||||
public function signDocument(string $url, string $token, int $batch): array
|
public function signDocument(SignRequest $request,string $token): array
|
||||||
{
|
{
|
||||||
|
if ($_ENV['API_TOKEN'] !== $request->apiToken) {
|
||||||
|
throw new AccessDeniedHttpException('Доступ запрещен');
|
||||||
|
}
|
||||||
|
|
||||||
$this->api->apiParams = $this->apiParams;
|
$this->api->apiParams = $this->apiParams;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$document = $this->api->download($url, $token);
|
$document = $this->api->download($request->url, $token);
|
||||||
|
|
||||||
$this->sign($document->tempFileName);
|
$this->sign($document->tempFileName);
|
||||||
|
|
||||||
$response = $this->api->send($token, $document->tempFileName . '_sign.pdf', $batch);
|
$response = $this->api->send($token, $document->tempFileName . '_sign.pdf', $request->batch);
|
||||||
|
|
||||||
$this->removeExistingDocument($document);
|
$this->removeExistingDocument($document);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue