api-postcode/api-postcode-bundle

Symfony Api Postcode 包

1.0.7 2022-07-11 10:56 UTC

This package is not auto-updated.

Last update: 2024-09-19 08:12:09 UTC


README

此包可以用于通过邮编号码获取地址详情。

更多信息请见: https://api-postcode.nl

安装

安装是一个简单的3步过程

  1. 使用composer下载api-postcode-bundle
  2. 在AppKernel.php中启用Bundle
  3. 配置Api Postcode凭证

步骤1:使用composer下载postcode-bundle

运行以下命令添加ApiPostcodeBundle

$ composer require api-postcode/api-postcode-bundle

步骤2:在AppKernel.php中启用Bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new ApiPostcode\PostcodeBundle\ApiPostcodeBundle(),
    );
}

步骤3:配置Api Postcode凭证

# app/config/config.yml

# Api Postcode Token
api_postcode:
    token: secret-token

使用服务

$address = $this->get('api.postcode')->fetchAddress('1012JS', 1);
	
$address->getStreet();      // Dam
$address->getCity();        // Amsterdam
$address->getHouseNumber(); // 1
$address->getZipCode();     // 1012JS
$address->getLongitude();   // 4.4584
$address->getLatitude();    // 52.2296

通过API使用

或者尝试API响应

http://127.0.0.1:8000/api/postcode?postcode=2011WD&nummer=2