sqits/laravel-postcode

Laravel 对 postcode-nl api 的封装

v0.1.4 2024-03-19 11:09 UTC

This package is auto-updated.

Last update: 2024-09-19 12:06:20 UTC


README

安装和用法

此包需要 PHP 7.2 和 Laravel 5.8 或更高版本。在控制台中运行以下命令安装包;

composer require sqits/laravel-postcode

您可以使用以下命令发布配置文件;

php artisan vendor:publish --provider="Sqits\Postcode\PostcodeServiceProvider" --tag="config"

这是已发布配置文件的内容

 /*
     * Request options required for GuzzleHttp client.
     */
    'requestOptions' => [
        
        /*
         * URI
         *
         * Settings which api url the package should use. There are several endpoints available
         */
        'uri' => [
            'extension' => env('POSTCODENL_URI_EXTENSION', 'nl'),
        ],
        
        /*
         * Authentication
         *
         * Register an account with Postcode.nl to obtain a key and secret. See https://api.postcode.nl/#register for
         * further information.
         */
        'auth' => [
            env('POSTCODENL_KEY', null),
            env('POSTCODENL_SECRET', null)
        ],

        /*
         * Timeout (in seconds)
         *
         * By default, the client waits 10 seconds for a response. You may set a different timeout.
         */
        'timeout' => env('POSTCODENL_TIMEOUT', 10),

    ],

    /*
     * Enable routes
     *
     * This package comes with a set of routes, which are not loaded by default. In order to use them, set this
     * option to true.
     */
    'enableRoutes' => env('POSTCODENL_ENABLE_ROUTES', false),

使用 JSON API

为了使用 API,请在配置中启用它。启用后,以下路由可用

route('postcode-nl::address', [$postcode, $houseNumber, $houseNumberAddition = null]);

或使用以下 URL(例如,用于 AJAX 调用)

/postcode-nl/address/{postcode}/{houseNumber}/{houseNumberAddition?}

配置

凭证(必需)

密钥和秘密用于认证。没有它们,您无法使用此服务。

POSTCODENL_KEY=<your-api-key>
POSTCODENL_SECRET=<your-secret>

启用路由(可选)

此包附带一个可立即使用的 JSON API,默认情况下已禁用。您可以按如下方式启用它

POSTCODENL_ENABLE_ROUTES=true

超时时间(秒,可选)

默认情况下,客户端等待 10 秒的响应。您可以设置不同的超时时间。

POSTCODENL_TIMEOUT=<timeout-in-seconds>

变更日志

有关最近更改的更多信息,请参阅 变更日志

安全

如果您发现任何安全问题,请通过 电子邮件 发送至 info@sqits.nl,而不是使用问题跟踪器。

鸣谢

许可证

MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件