api-check/php-client

ApiCheck get 的包装器,用于验证地址。

1.0 2022-10-09 16:27 UTC

This package is auto-updated.

Last update: 2024-09-09 21:15:20 UTC


README

这是 ApiCheck 端点的 PHP 客户端。ApiCheck 帮助您验证客户数据。

目前支持的国家:荷兰、比利时和卢森堡。

要求

  • ApiCheck 控制台 上注册账户并选择合适的订阅类型。
  • 创建一个新的 API 密钥。

安装

使用 composer 安装此包

$ composer require api-check/php-client:^1.0
{
  "require": {
    "api-check/php-client": "^1.0"
  }
}

示例

第一步是设置您的 API 密钥(可选地也可以加载 autoload.php)

使用查找 API

查找 API 目前仅支持荷兰和卢森堡。请参阅: 查找 API 文档

use ApiCheck\Api\ApiClient;

require "./vendor/autoload.php";

$apicheckClient = new ApiClient();
$apicheckClient->setApiKey("YOUR_API_KEY");

使用查找 API

$address = $apicheckClient->lookup('nl', ['postalcode' => '2513AA', 'number' => 1]);
// Do something with the result:
print("🥳 Yay! We have a result: \n $address->street $address->number \n $address->postalcode $address->city \n {$address->Country->name}");

使用搜索 API

搜索 API 目前支持荷兰、比利时、卢森堡和法国。请参阅: 搜索 API 文档

$results = $apicheckClient->search('be', 'city', ['name' => 'Namur']);

这将返回包含搜索结果的数组

异常

ApiCheck 客户端使用自定义异常来处理失败响应

use ApiCheck\Api\ApiClient;
use ApiCheck\Api\Exceptions\NotFoundException;
use ApiCheck\Api\Exceptions\ValidationException;
use ApiCheck\Api\Exceptions\UnsupportedCountryException;

try {
    $address = $apicheckClient->lookup('nl', ['postalcode' => '2513AA', 'number' => 1]);
} catch (NotFoundException $e) {
    // No results have been found using the supplied data
} catch (ValidationException $e) {
    // One of the submitted fields is not valid or set
} catch (UnsupportedCountryException $e) {
    // The given country-code is not supported
}

更多示例可以在 examples 目录中找到。

贡献

欢迎拉取请求。对于重大更改,请先提出问题以讨论您想更改的内容。

请确保适当地更新测试。

许可

MIT

支持

联系: www.apicheck.nlsupport@apicheck.nl