postcode-nl/api-restclient

此包已被废弃,不再维护。未建议替代包。

荷兰地址验证的Postcode.nl地址API客户端。您需要在https://api.postcode.nl创建账户。

1.1.2.0 2016-06-21 11:37 UTC

This package is not auto-updated.

Last update: 2020-03-20 15:05:43 UTC


README

一个PHP 5.6+类,提供直接通过提供的REST端点与Postcode.nl API通信的方法。您需要使用Postcode.nl API服务创建账户。

许可证

代码在开源Simplified BSD许可证下可用。(见LICENSE.txt)

安装

最佳安装方式是使用PHP Composer,获取包postcode-nl/api-restclient并轻松保持更新。

或者从我们的GitHub页面下载源代码:https://github.com/postcode-nl/PostcodeNl_Api_RestClient

使用地址API

将类包含到您的PHP项目中,使用您的认证详情实例化PHP类,并调用'lookupAddress'方法。您可以通过捕获定义的Exception类来处理错误。(有关可能抛出的异常的详细信息,请参阅'library/PostcodeNl/Api/RestClient.php'文件)

<?php
	require_once '/PATH/TO/library/PostcodeNl/Api/RestClient.php';
	$client = new PostcodeNl_Api_RestClient('{your key}', '{your secret}');

	// Look up the address for Dutch postcode 2012ES, housenumber 30,
	// with no housenumber addition.
	try
	{
		$address = $client->lookupAddress('2012ES', '30', '');
	}
	catch (PostcodeNl_Api_RestClient_AddressNotFoundException $e)
	{
		die('There is no address on this postcode/housenumber combination: '. $e);
	}
	catch (PostcodeNl_Api_RestClient_InputInvalidException $e)
	{
		die('We have input which can never return a valid address: '. $e);
	}
	catch (PostcodeNl_Api_RestClient_ClientException $e)
	{
		die('We have a problem setting up our client connection: '. $e);
	}
	catch (PostcodeNl_Api_RestClient_AuthenticationException $e)
	{
		die('The Postcode.nl API service does not know who we are: '. $e);
	}
	catch (PostcodeNl_Api_RestClient_ServiceException $e)
	{
		die('The Postcode.nl API service reported an error: '. $e);
	}

	// Print the address data
	echo var_export($address, true);