定制 setasign/setapdf-signer-addon-safe 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

setasign/setapdf-signer-addon-safe

Composer 安装命令:

composer require setasign/setapdf-signer-addon-safe

包简介

A SetaPDF-Signer component signature module for the "Serviço de Assinatura de Faturas Eletrónicas" (SAFE) of the Portuguese State.

README 文档

README

This package offers a module for the SetaPDF-Signer component that allows you to use the "Serviço de Assinatura de Faturas Eletrónicas" (SAFE) of the Portuguese State to digital sign PDFs in pure PHP.

Comments and notes on the implementation

  • While the documentation says that the API conforms to the CSC API we noted several differences which makes it impossible to use our existing CSC API module.
  • As we do not understand or speak Portuguese while the official documentation is only available in Portuguese, we tried to implement the API based on an automated translation and the OpenAPI Specification definitions found on the projects official GitHub repository.
  • We're also not able to authenticate as a Portuguese citizen and were dependent on users to provide test credentials/tokens.
  • The hashing algorithm is fixated to SHA256 as per documentation and the information from the /credentials/info endpoint are ignored.

Requirements

You need to have credentials and a valid access token to the SAFE API endpoints.

This package is developed and tested on PHP >= 8.0. Requirements of the SetaPDF-Signer component can be found here.

We're using PSR-17 (HTTP Factories) and PSR-18 (HTTP Client) for the requests. So you'll need an implementation of these. We recommend using Guzzle.

    "require" : {
        "guzzlehttp/guzzle": "^7.0",
        "http-interop/http-factory-guzzle": "^1.0"
    }

Installation

Add following to your composer.json:

{
    "require": {
        "setasign/setapdf-signer-addon-safe": "^1.0"
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://www.setasign.com/downloads/"
        }
    ]
}

and execute composer update. You need to define the repository to resolve the dependency to the SetaPDF-Signer component (see here for more details).

Usage

All classes in this package are located in the namespace setasign\SetaPDF\Signer\Module\SAFE. See the examples/ folder for working examples.

The Client class

This class is a kind of proxy class to the SAFE API. Its constructor requires the following arguments:

  • $apiUri The base url of the api e.g. https://pprsafe.autenticacao.gov.pt
  • $basicAuthUsername The username for HTTP Basic authentiaction
  • $basicAuthPassword The password for HTTP Basic authentiaction
  • $httpClient PSR-18 HTTP Client implementation.
  • $requestFactory PSR-17 HTTP Factory implementation.
  • $streamFactory PSR-17 HTTP Factory implementation.

If you need to call an endpoint which is not covered by a proxy method, you can use the call(string $path, ?string $accessToken = null, array $inputData = []) method.

The Module class

This is the main module for the SetaPDF-Signer which implements the SetaPDF_Signer_Signature_Module_ModuleInterface interface.

Internally it creates PAdES conforming signatures by using the SetaPDF_Signer_Signature_Module_PadesProxyTrait.

Its constructor requires the following arguments:

  • $accessToken - The access token which is passed with the custom header SAFEAuthorization.
  • $client - An instance of the Client class.
  • $credentialId - The id of the credentials (can be received as demoed in list-credentials.php)
  • $processId - A process id (a new Globally Unique Identifier (GUID) for each invocation).
  • $clientName - The value for the clientName field.

Additionally, the module offers a setDocumentName() method. This method allows you to define the document name related to the hash send to the SAFE API. By default, the document name is set to "document.pdf".

The Batch class

This class allows you to digital sign several PDF files in a single signature flow.

Its constructor requires the following arguments:

  • $accessToken - The access token which is passed with the custom header SAFEAuthorization.
  • $client - An instance of the Client class.
  • $credentialId - The id of the credentials (can be received as demoed in list-credentials.php)
  • $processId - A process id (a new Globally Unique Identifier (GUID) for each invocation).
  • $clientName - The value for the clientName field.

You can pass several files as an array to the sign($files) method:

$files = [
    [
        'in' => string|SetaPDF_Core_Reader_ReaderInterface,
        'out' => 'path/to/result.pdf'    
    ]   
];

Additionally, the sign() method accepts callbacks to e.g. add individual signature appearances or signature properties. For an example see the batch-complex.php demo.

License

This package is open-sourced software licensed under the MIT license.

setasign/setapdf-signer-addon-safe 适用场景与选型建议

setasign/setapdf-signer-addon-safe 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 setasign/setapdf-signer-addon-safe 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 setasign/setapdf-signer-addon-safe 我们能提供哪些服务?
定制开发 / 二次开发

基于 setasign/setapdf-signer-addon-safe 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-14