spikkl/spikkl-php-client

Spikkl API 客户端库,用于 PHP

v1.3 2022-10-04 10:00 UTC

This package is auto-updated.

Last update: 2024-09-04 13:53:10 UTC


README

Spikkl API 客户端,用于 PHP

Build Status

需求

要使用 Spikkl API 客户端,需要以下事项

安装

安装 Spikkl API 客户端最简单的方法是使用 Composer 需求它。

$ composer require spikkl/spikkl-php-client:^1.2
{
  "require": {
    "spikkl/spikkl-php-client": "^1.2"
  }
}

手动

如果您不熟悉使用 composer,我们在发布版本中添加了一个包含 API 客户端以及通常由 composer 安装的包的 ZIP 文件。从 发布页面 下载 spikkl-php-client.zip

如初始化示例所示,包含 vendor/autoload.php

入门

初始化 Spikkl API 客户端,并设置您的 API 密钥。

$spikkl = new \Spikkl\Api\ApiClient();
$spikkl->setApiKey("API_KEY");

执行邮政编码查找请求。

$results = $spikkl->lookup("NLD", "2611HB", "175");

通过坐标(经度,纬度)执行查找。

$results = $spikkl->reverse("NLD", 4.899431, 52.379189);

注意:经度和纬度值将被四舍五入到小数点后 9 位。

异常处理

Spikkl API 使用传统的 HTTP 响应代码来指示 API 请求的成功或失败。范围在 2xx 的代码表示成功,范围在 4xx 的代码表示失败。Spikkl API 客户端使用特定的异常处理特定的失败响应。

try {
    $results = $spikkl->lookup("NLD", "2611HB", "175");
} catch (\Spikkl\Api\Exceptions\AccessRestrictedException $exception) {
    // The API key is restricted for designated origins
} catch (\Spikkl\Api\Exceptions\InvalidApiKeyException $exception) {
    // The authentication with the Spikkl API failed
} catch (\Spikkl\Api\Exceptions\RevokedApiKeyException $exception) {
    // The provided API key is restricted.
} catch (\Spikkl\Api\Exceptions\ZeroResultsException $exception) {
    // The API call is successful but the API cannot find any results
} catch (\Spikkl\Api\Exceptions\QuotaReachedException $exception) {
    // The quota is reached for your current plan.
} catch (\Spikkl\Api\Exceptions\InvalidRequestException $exception) {
    // One of the query parameters (postal_code, street_number, or street_number_suffix)
    // might be invalid or missing
}

反向查找请求可能会抛出其他异常。

try {
    $results = $spikkl->reverse("NLD", 4.899431, 52.379189);
} catch (\Spikkl\Api\Exceptions\OutOfRangeException $exception) {
    // The coordinates provided do not correspond with the country code
} 

API 文档

如果您想了解更多关于我们的 API 的信息,请访问 Spikkl API 文档

许可证

BSD (伯克利软件发行版) 许可证。版权所有 (c) 2020, Spikkl

支持

联系方式:www.spikkl.nlsupport@spikkl.nl