api-check / php-laravel-client
Laravel的ApiCheck包装器
1.1
2022-10-09 16:53 UTC
Requires
- php: ^7.1|^8.0
- api-check/php-client: ^1.0
- illuminate/support: ^6.0 | ^7.0 | ^8.0 | ^9.0
Requires (Dev)
- phpunit/phpunit: ^9.5
README
这是一个用于ApiCheck端点的Laravel PHP客户端。ApiCheck帮助您验证客户数据。
当前支持的国家:荷兰、比利时和卢森堡。
要求
- 在ApiCheck仪表板注册账户并选择合适的订阅类型。
- 创建一个新的API密钥。
安装
使用Composer安装此包
$ composer require apicheck/php-laravel-client:^1.0
{ "require": { "apicheck/php-laravel-client": "^1.0" } }
示例
第一步是将APICHECK_API_KEY
变量添加到您的.env
文件中
APICHECK_API_KEY = "xxxxxxxxxxx"
使用查找API
查找API目前仅支持NL和LU。请参阅:查找API文档
使用查找API
$address = ApiCheck::api()->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目前支持NL、BE、LU和FR。请参阅:搜索API文档
$results = ApiCheck::api()->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 }
更多示例可以在示例目录中找到。
贡献
欢迎Pull请求。对于重大更改,请首先提交问题以讨论您想要更改的内容。
请确保根据需要更新测试。