firstred/postnl-api-php

PostNL REST API PHP 绑定

v2.0.11 2024-09-18 10:35 UTC

README

Latest Stable Version Total Downloads .github/workflows/test.yaml Documentation Status codecov license mit PHP Version Require

关于

这个 PostNL REST API 的非官方 PHP 库旨在提供一种简单的方法将您的应用程序与 PostNL 连接起来。通过在处理货运信息时抽象出不必要的复杂性并提高容错性,您可以在几分钟内开始使用 PostNL。
在底层,此库使用异步通信和有效载荷拆分来提高性能。

状态

* PostNL::getTimeframesAndNearestLocations 可以用作具有更多功能的替代品:[链接](https://postnl-php.readthedocs.io/en/v1.4.x/quickstart.html#requesting-timeframes-location-and-delivery-date-at-once)

说明

  • 克隆此仓库
  • 运行 composer install(没有 composer?请访问 [链接](https://getcomposer.org.cn/))
  • 可选地运行 composer require guzzlehttp/guzzle 以使用 Guzzle 而不是直接使用 cURL
  • 您已经准备好开始使用了!本 README 中提供了一个简单的示例。请查看完整文档以获取 [快速入门指南](https://postnl-php.readthedocs.io/en/v1.2.x/quickstart.html)。

文档

示例

允许用户使用默认 REST API 下载标签

<?php

use Firstred\PostNL\PostNL;
use Firstred\PostNL\Entity\Customer;
use Firstred\PostNL\Entity\Address;
use Firstred\PostNL\Entity\Shipment;
use Firstred\PostNL\Entity\Dimension;

require_once __DIR__.'/vendor/autoload.php';

$customer = Customer::create([
    'CollectionLocation' => '123456',
    'CustomerCode'       => 'DEVC',
    'CustomerNumber'     => '11223344',
    'ContactPerson'      => 'Peter',
    'Address'            => Address::create([
        'AddressType' => '02',
        'City'        => 'Hoofddorp',
        'CompanyName' => 'PostNL',
        'Countrycode' => 'NL',
        'HouseNr'     => '42',
        'Street'      => 'Siriusdreef',
        'Zipcode'     => '2132WT',
    ]),
    'Email'              => 'info@voorbeeld.nl',
    'Name'               => 'Michael',
]);

$apikey = 'YOUR_API_KEY_HERE';
$sandbox = false;

$postnl = new PostNL($customer, $apikey, $sandbox);

$barcode = $postnl->generateBarcodeByCountryCode('NL');

$shipment = Shipment::create([
    'Addresses'           => [
        Address::create([
            'AddressType' => '01',
            'City'        => 'Utrecht',
            'Countrycode' => 'NL',
            'FirstName'   => 'Peter',
            'HouseNr'     => '9',
            'HouseNrExt'  => 'a bis',
            'Name'        => 'de Ruijter',
            'Street'      => 'Bilderdijkstraat',
            'Zipcode'     => '3521VA',
        ]),
    ],
    'Barcode'             => $barcode,
    'Dimension'           => new Dimension(/* weight */ '2000'),
    'ProductCodeDelivery' => '3085',
]);

header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="label.pdf"');
echo base64_decode($postnl->generateLabel(
    /* The actual shipment */ $shipment, 
    /* The output format */ 'GraphicFile|PDF',
    /* Immediately confirm the shipment */ true
)
    ->getResponseShipments()[0]
    ->getLabels()[0]
    ->getContent()
);
exit;

完整文档

完整文档可以在本页面上找到:[链接](https://postnl-php.readthedocs.io/)

构建文档

生成文档分为两个步骤

  1. 生成此库中所有 PHP 类的参考 RST 文件。
  2. 生成可以浏览的 HTML 输出。

生成 PHP 类参考

生成参考依赖于一个相当旧的库。从 require-dev 中先移除其他依赖可能是在安装 abbadon1334/phpdoc-to-rst 时最好的解决方案。

  "require-dev": {
  },

然后安装 PHPdoc 到 RST 工具。

composer require abbadon1334/phpdoc-to-rst -W

此仓库包含一个简单的 PHP 文件,它使用上述提到的工具以编程方式生成参考 RST 文件。它还移动了一些文件以将参考集成到其余文档中。
只需运行(已在 PHP 8.2 上测试)

php ./build-docs-reference.php
生成最终 HTML 输出

文档自动构建并托管在 readthedocs.io 上。您可以通过安装 Sphinx 并运行以下命令来构建本地 HTML 副本:[链接](https://sphinx-doc.cn/en/master/usage/installation.html)

pip install -r docs/requirements.txt

来安装需求,然后

sphinx-build -b html docs builddir

builddir 目录中构建 HTML 输出。

许可

此库已使用 MIT 许可证授权。

完整许可证文本

MIT 许可证(MIT)。版权所有(c)2017-2023 Michael Dekker ([链接](https://github.com/firstred))

以下条件下,任何人都可以免费获得本软件及其相关文档文件(以下简称“软件”)的副本,并且可以不受限制地处理软件,包括但不限于以下权利:使用、复制、修改、合并、发布、分发、再许可和/或出售软件的副本,并允许向软件提供方提供软件的人这样做,前提是满足以下条件

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

本软件按“原样”提供,不提供任何形式的保证,无论是明示的还是隐含的,包括但不限于适销性、特定目的适用性和非侵权性。在任何情况下,作者或版权所有者不应对任何索赔、损害或其他责任负责,无论这些责任是基于合同、侵权或其他任何原因,这些责任源于、因之产生于或与软件或软件的使用或其他方式有关。