salamek/czech-post-api

捷克邮政API(非官方),解析在线门户的HTML

v1.0.4 2019-08-31 13:26 UTC

This package is auto-updated.

Last update: 2024-08-29 04:58:47 UTC


README

Build Status Donate

PHP版本的捷克邮政API客户端(解析podani online),带有自定义标签生成器

需求

  • PHP 5.4 或更高版本

安装

使用 Composer 安装 salamek/czech-post-api

$ composer require salamek/czech-post-api

或者如果您想要master分支的代码

$ composer require salamek/czech-post-api:dev-master

用法

创建包裹

在Ceska posta上创建package/s

$username = 'my_api_username';
$password = 'my_api_password';
$cookieJar = __DIR__.'/cookieJar.txt';

$czechPostApi = new Salamek\CzechPostApi\Api($username, $password, $cookieJar);

$sender = new Salamek\CzechPostApi\Model\Sender('C9569', 'Olomouc', 'My Compamy s.r.o.', 'My Address', '77900', 'info@example.com', '+420123456789', 'http://www.example.cz', Country::CZ);
$recipient = new Salamek\CzechPostApi\Model\Recipient('Olomouc', 'Adam Schubert', 'My Address', '77900', 'adam@example.com', '+420123456789', 'http://www.salamek.cz', Country::CZ, 'My Compamy a.s.');

$myPackageIdFromNumberSeries = 115;
$weight = 3.15;
$insurance = 100;
$package = new Salamek\CzechPostApi\Model\Package($myPackageIdFromNumberSeries, Product::PACKAGE_TO_HAND, $sender, $recipient, null, null, $insurance, [], 'Package desc', 1, 1, null);

try
{
    $czechPostApi->createPackages([$package]);
}
catch (\Exception $e)
{
    echo $e->getMessage() . PHP_EOL;
}

获取标签

返回包含标签的PDF文件,以便打印到纸上,支持两种分解方式,LabelDecomposition::FULL(每页一个A4标签)或LabelDecomposition::QUARTER(每页1/4个A4标签)

$sender = new Salamek\CzechPostApi\Model\Sender('Olomouc', 'My Compamy s.r.o.', 'My Address', '77900', 'info@example.com', '+420123456789', 'http://www.example.cz', Country::CZ);
$recipient = new Salamek\CzechPostApi\Model\Recipient('Olomouc', 'Adam Schubert', 'My Address', '77900', 'adam@example.com', '+420123456789', 'http://www.salamek.cz', Country::CZ, 'My Compamy a.s.');

$myPackageIdFromNumberSeries = 115;
$weight = 3.15;
$insurance = 100;
$package = new Salamek\CzechPostApi\Model\Package($myPackageIdFromNumberSeries, Product::PACKAGE_TO_HAND, $sender, $recipient, null, null, $insurance, [], 'Package desc', 1, 1, null);


$rawPdf = Label::generateLabels([$package]);
file_put_contents($package->getPackageNumber() . '.pdf', $rawPdf);