pdffiller/pdffiller-php-api-client

pdffiller.com REST API 的 PHP 客户端


README

Join the chat at https://gitter.im/pdffiller/pdffiller-php-api-client

PDFfiller API 您可以在这里注册 API

系统要求

  • PHP >= 7.0,但建议使用最新稳定版本的 PHP;
  • mbstring 扩展;
  • intl 扩展;

安装

该库可在 Packagist 上获取,并可以使用 Composer 安装。在已安装 Composer 的环境中,运行以下命令即可完成此操作

$ composer require pdffiller/pdffiller-php-api-client

大多数现代框架都自带 Composer。但是,请确保包含以下文件

// Include the Composer autoloader
require 'vendor/autoload.php';

故障排除

如果您遇到以下错误

[RuntimeException]
 Could not load package pdffiller/pdffiller-php-api-client in http://packagi
 st.org: [UnexpectedValueException] Could not parse version constraint ^5.2:
  Invalid version string "^5.2"


 [UnexpectedValueException]
 Could not parse version constraint ^5.2: Invalid version string "^5.2"

尝试运行

composer self-update 

您可能还会遇到以下情况

Warning: require_once(../../vendor/autoload.php): failed to open stream: No such file or directory

通过安装 composer 依赖项可以轻松解决这个问题

composer install

快速入门步骤

使用 composer 安装所需库

cd pdffiller-php-api-client/
composer install

编辑 examples 目录中的 .env 文件,设置 client_id、client_secret、用户名和密码(通过 password_grant 进行授权)

cd examples/ 
cp .env.example .env
vi .env

运行任何示例

cd signature_request/
php 1_get_signature_request_list.php

身份验证

访问令牌在成功从给定用户的凭据中检索到(在 PDFfiller\OAuth2\Client\Provider\PDFfiller::getAccessToken($grant_type, $options) 方法之后)时自动初始化,如下例所示

<?php
require_once __DIR__.'/vendor/autoload.php';

use \PDFfiller\OAuth2\Client\Provider\Enums\GrantType;
use \PDFfiller\OAuth2\Client\Provider\PDFfiller;

$oauthParams = [
    'clientId'       => 'YOUR_CLIENT_ID',
    'clientSecret'   => 'YOUR_CLIENT_SECRET',
    'urlAccessToken' => 'https://api.pdffiller.com/v2/oauth/token',
    'urlApiDomain'   => 'https://api.pdffiller.com/v2/'
];

$passwordGrantCredentials = [
    'username' => 'pdffiller_account@example.com',
    'password' => 'some_pass'
];

/** @var \PDFfiller\OAuth2\Client\Provider\PDFfiller $provider */
$provider = new PDFfiller($oauthParams);

$accessToken = $provider->getAccessToken(GrantType::PASSWORD_GRANT, $passwordGrantCredentials);
print_r($accessToken);

当您的授权成功完成时,您可以使用提供者检索、创建、更新或删除您配置文件中的信息。

用法

使用静态方法检索所有应用程序的列表:PDFfiller\OAuth2\Client\Provider\Core\Model::all(PDFfiller $provider)

$list = Application::all($provider);
print_r($list);

要检索有关一个应用程序的信息,调用静态:PDFfiller\OAuth2\Client\Provider\Core\Model::one(PDFfiller $provider, $appClientId)

$application = Application::one($provider, 'app_client_id');
print_r($application);

如果您要创建一个新的应用程序,您必须创建一个新的 Application 对象并包含必要的信息,然后使用以下方法保存它:PDFfiller\OAuth2\Client\Provider\Core\Model::save()

$application = new Application($provider);

$application->name = 'App name';
$application->description = 'Some application description';
$application->domain = 'http://some.domain.com';
print_r($application->save());

如果您要更新一个实例,您必须检索一个 Application 对象并使用以下方法保存它:PDFfiller\OAuth2\Client\Provider\Core\Model::save()

$application = Application::one($provider, 'app_client_id');

$application->name = 'Updated App name';
$application->description = 'Some changed application description';
$result = $application->save();
print_r($result);

通过使用 PDFfiller\OAuth2\Client\Provider\Core\Model::save() 方法,可以轻松地更新信息。如果您想删除一个应用程序,请使用:PDFfiller\OAuth2\Client\Provider\Core\Model::remove() 方法

$application = Application::one($provider, 'app_client_id');
$result = $application->remove();
print_r($result);

所有其他端点的示例都在 examples 文件夹中

支持

如果您有任何问题,请随时联系我们

许可

此软件受以下 MIT 许可 许可 的许可

作者

API 团队 (integrations@pdffiller.com)