pamekar/laravel-postnl-api

Laravel PostNL API包

dev-master 2024-06-19 21:49 UTC

This package is not auto-updated.

Last update: 2024-09-25 23:03:57 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License StyleCI

通过ServiceProvider和Facade将PostNL API与Laravel 5 & 6集成。

安装

composer require deniztezcan/laravel-postnl-api

config/app.php中将ServiceProvider添加到providers数组中

    'providers' => [
    	//other things here

    	DenizTezcan\LaravelPostNLAPI\PostNLAPIServiceProvider::class,
    ];

将facade添加到facades数组中

    'aliases' => [
    	//other things here

    	'PostNLAPI' => DenizTezcan\LaravelPostNLAPI\Facades\PostNLAPI::class,
    ];

最后,发布配置文件

php artisan vendor:publish --provider="DenizTezcan\LaravelPostNLAPI\PostNLAPIServiceProvider"

配置

请设置API:urlkey以及客户codenumberlocationemailaddress,在config/postnlapi.php

用法

要生成barcode,可以使用以下调用。要查找要使用的typeserie,请参阅PostNL文档

$barcode = PostNLAPI::generateBarcode('3S', '00000000000-99999999999');

要生成label,可以使用以下调用。要查找要使用的PrinterTypeAddressTypeProductCodeDelivery,请参阅PostNL文档

use DenizTezcan\LaravelPostNLAPI\Entities\{Address, Contact};

$label = PostNLAPI::generateLabel(
	$barcode, 
	'GraphicFile|PDF',
	[Address::create([
        'AddressType' 	=> '01',
        'City'        	=> "Testdorp",
        'CompanyName' 	=> "Crusty Crab BV",
        'Countrycode' 	=> "NL",
        'HouseNr'     	=> "1",
        'Street'      	=> "Teststraat",
        'Zipcode'     	=> "1111AA",
        'FirstName'	  	=> "Meneer",
        'Name'	 	  	=> "Krabs"
    ]),
    Address::create([
        'AddressType'   => '09',
        'City'          => "Testdorp",
        'CompanyName'   => "Crusty Crab BV",
        'Countrycode'   => "NL",
        'HouseNr'       => "1",
        'Street'        => "Teststraat",
        'Zipcode'       => "1111AA",
        'FirstName'     => "Meneer",
        'Name'          => "Krabs"
    ])],
    [Contact::create([
    	'ContactType'	=> "01",
    	'Email'			=> 'test@meneer.nl',
    	'SMSNr'			=> '061111111',
    	'TelNr'			=> '061111111'
    ])],
    '01',
    '3085',
    'This is a reference',
    'This is a remark'
);

注意:注意需要传递给第二个和第三个参数的数组!没有它将无法正常工作!

要获取最近的PostNL位置的数组,可以使用以下调用。您必须将CountryCodePostalCode作为参数传递。

$locations = PostNLAPI::nearestLocations('NL', '1111AA');