pingencom/pingen2-sdk-php

官方PHP Pingen SDK for API V2

2.12.1 2024-09-23 07:42 UTC

README

您需要在pingen v2中拥有账户,并获取所需授权类型(通常是client_credentials)的oauth凭证。

如何获取这些凭证的描述见此处: https://api.pingen.com/documentation#section/Authentication/How-to-obtain-a-Client-ID

安装

通过composer安装此包(获取composer: https://getcomposer.org.cn/download/

composer require pingencom/pingen2-sdk-php

环境

我们有两种环境可供选择:生产环境和测试环境(见 https://api.pingen.com/documentation#section/Basics/Environments

此SDK也支持测试环境。 在初始化提供者时(见使用说明),应设置可选的'staging'属性,以及创建端点对象时

使用说明

最简单的集成方法是使用客户端凭证授权(见 https://api.pingen.com/documentation#section/Authentication/Which-grant-type-should-i-use

require __DIR__ . '/vendor/autoload.php';

$provider = new \Pingen\Provider\Pingen(
    array(
        'clientId' => 'YOUR_OAUTH2_CLIENT_ID',
        'clientSecret' => 'YOUR_OAUTH2_CLIENT_SECRET',
        'staging' => true,
    )
);

$access_token = $provider->getAccessToken('client_credentials');

$lettersEndpoint = (new \Pingen\Endpoints\LettersEndpoint($access_token))
    ->setOrganisationId('INSERT_YOUR_ORGANISATION_UUID_HERE')
    ->useStaging();

$lettersEndpoint->uploadAndCreate(
    (new \Pingen\Endpoints\DataTransferObjects\Letter\LetterCreateAttributes())
        ->setFileOriginalName('your_original_pdf_name.pdf')
        ->setAddressPosition('left')
        ->setAutoSend(false),
    fopen('path_to_your_original_pdf_name.pdf', 'r')
);

示例 & 文档

我们的API文档在此: https://api.pingen.com/documentation

在每个端点的右侧,您可以查看PHP和其他语言的请求示例,您可以将这些示例复制并粘贴到您的应用程序中。

错误报告 & 贡献

如果您发现错误,请创建github上的票据或在github上发起pull request。

版本控制

我们遵循语义(主要.次要.补丁)版本控制(https://semver.org/)。这意味着

  • 补丁(x.x.patch)版本修复错误
  • 次要(x.minor.x)版本引入新的、向后兼容的功能或改进现有代码。
  • 主要(major.x.x)版本引入不兼容的激进变化。

在您的自动化或流程中,您可以始终安全地更新补丁和次要版本,而不会使您的应用程序失败。

测试

PHPUnit: vendor/bin/phpunit

ECS: vendor/bin/ecs check src

PHPStan: vendor/bin/phpstan analyse -c phpstan.neon --memory-limit=512M

代码审查: vendor/bin/parallel-lint --exclude vendor .