mpp/universign-bundle

Symfony Universign Bundle


README

安装

要安装此包,请运行以下命令

$ composer require mpp/universign-bundle

如何运行

运行之前,您需要在项目的 .env 文件中添加 UNIVERSIGN_ENTRYPOINT_SIGNUNIVERSIGN_ENTRYPOINT_RA 变量,并使用 Universign 账户的 URL 和凭据。

###> mpp/unviversign-bundle ###
UNIVERSIGN_ENTRYPOINT_SIGN=https://<LOGIN>:<PASSWORD>@sign.test.cryptolog.com/sign/rpc/
UNIVERSIGN_ENTRYPOINT_RA=https://<LOGIN>:<PASSWORD>@sign.test.cryptolog.com/ra/rpc/
###< mpp/unviversign-bundle ###

之后,您就可以在您的 Symfony 项目中使用此包。

如何使用

以下是 Universign 工作流程的介绍

Universign workflow

请求签名

首先,您需要将交易发送到 Universign 服务。

交易请求

以下是一个示例

...
use Mpp\UniversignBundle\Requester\SignerInterface;

...
/**
 * @var SignerInterface;
 */
private $requester;

public function __construct(SignerInterface $requester)
{
    $this->requester = $requester;
}

...
    $transactionRequest = $this->requester->initiateTransactionRequest([
        'signers' => [
            [
                'firstname' => 'john',
                'lastname' => 'doe',
                'organization' => 'dummy company',
                'emailAddress' => 'john.doe@dummy-company.com',
                'phoneNum' => '+0122334455',
                'language' => 'fr',
                'birthDate' => new \DateTime::createFromFormat('Y-m-d', '2000-01-01'),
            ],
        ],
        'documents' => [
            'mpp_contract' => [
                'fileName' => $document->getFileName(),
                'content' => $this->storage->resolvePath($document),
                'signatureFields' => [
                    [
                        'name' => 'Signature:',
                        'page' => 18,
                        'signerIndex' => 0,
                    ],
                ],
            ],
        ],
        'finalDocSent' => true,
    ]);

    $transactionResponse = $this->requester->requestTransaction($transactionRequest);

一旦发送了交易请求,您将得到一个 TransactionResponse 对象,其中您将找到交易 ID 和一个 URL。

交易响应

以下是一个 TransactionResponse 对象的示例

{
 'id' => "bde1e661-a217-4d2b-a3ec-160c2e266ff4"
 'url' => "https://sign.test.universign.eu/sig/#/?id=7d161638-9fb7-42c9-bb56-c902ea491404"
}

id 值用于标识交易,它允许您获取有关交易的更多信息,检索已签名的文档。 url 值用于签名人签署文档。

请求已签名的文档

在发送交易请求并签署之后,使用之前的交易 ID 发送请求以获取已签名的文档

$documents = $this->requester->getDocuments($transactionId);

您将得到一个包含 Document 对象的数组

[
    0 => [
        'id' => 'http.example.com',
        'documentType' => 'pdf',
        'content' => "JVBERi0xLj[...]UKJb4",
        'fileName' => 'contract_test',
        'signatureFields' => [
            [
                'name' => 'Client:',
                'page' => 1,
                'x' => 100,
                'y' =>  200,
                'signerIndex' => 0,
            ],
        ]
        'checkBoxTexts' => null,
        'metaData' => null,
        'title' => null,
        'sepaData' => [
            'rum' => '87654345678765'
            'ics' => 'FR12ZZZ123456'
            'iban' => 'FR7630006000011234567890189'
            'bic' => 'BREDFRPPXXX'
            'recuring' => false
            'debtor' => [
                'name' => 'Victor Vidal'
                'address' => '805, boulevard Richard'
                'postalCode' => '32 082'
                'city' => 'Ruiz-sur-Dos Santos'
                'country' => 'Christmas (Île)'
            ]
        ]
        'creditor' => [
            'name' => 'Marie Pierre'
            'address' => 'rue Roger Marie'
            'postalCode' => '71 625'
            'city' => 'Deschamps-sur-Dupre'
            'country' => 'Bosnie-Herzégovine'
        ]
    ]
]

content 参数是您的已签名文档 base64 编码。只需解码它即可获取文件。

更多信息