covie/sdk-php

用于与 Covie API 交互的 PHP SDK

0.2 2022-03-19 01:32 UTC

This package is auto-updated.

Last update: 2024-09-11 18:44:52 UTC


README

用于与 Covie API 交互的 PHP SDK

注意:这是预发布软件,在开发过程中可能会发生变化。

安装

我们建议您使用 Composer 将 Covie PHP SDK 添加到您的项目中。

$ composer require covie/sdk-php

快速入门

首先,使用您的 client-idclient-secret 创建客户端

use Covie\SDK\Client;
$client = Client::createFromCredentials('client-id', 'client-secret');

现在您有了客户端,可以与 Covie 交互。

创建集成

创建一个名为 test 的新集成

$integration = $sdk->integrations()->create('test');

您可以使用以下方式访问新集成密钥

$key = $integration->getIntegrationKey();

密钥可用于 SDK 和其他集成级别 API 调用。

检索政策数据

要检索政策,您需要知道其 ID,其格式为 po_xxxxxxxxxxxxxxxx,然后可以使用

$policy = $sdk->policies()->get($policyId);

现在我们有了政策,我们可以以 JSON 格式获取政策数据

echo json_encode($policy->jsonSerialize(), JSON_PRETTY_PRINT) . PHP_EOL;

我们还可以检索其文档。例如,检索声明 PDF 并写入磁盘

use Covie\SDK\Model\DocumentType;
$pdfContent = $sdk->policies()->getLatestDocumentOfType($policy, DocumentType::DECLARATION);
file_put_contents('declaration.pdf', $pdfContent);

可用类型列在 DocumentType 类中。

贡献

目前我们不接受对 Covie PHP SDK 的贡献。