yurycooliq/ukrposhta-php

Ukrpochta API (从 https://github.com/martinjack/UkrposhtaAPI 分支)

v1.0.1 2019-12-07 22:53 UTC

This package is auto-updated.

Last update: 2024-09-09 11:09:08 UTC


README

PHP类,用于与乌克邮API交互。从https://github.com/martinjack/UkrposhtaAPI分支,添加了新方法(目前仅为计算配送费用)。

文档

API文档

要求

  • PHP 7+
  • Composer

安装

composer require yurycooliq/ukrposhta-php

使用示例

参见example.php。

方法列表

  1. 入门
  2. 创建地址
  3. 编辑地址
  4. 按ID显示地址
  5. 创建新客户
  6. 编辑客户
  7. 按ID或ExternalID获取客户
  8. 创建新的发送组
  9. 编辑发送组
  10. 获取发送组列表
  11. 按ID获取发送组
  12. 创建新的包裹
  13. 编辑包裹
  14. 获取邮政包裹列表
  15. 按ID获取邮政包裹
  16. 从组中删除邮政包裹
  17. 创建PDF格式的表单
  18. 创建PDF格式的103表单
  19. [NEW] 乌克兰配送成本

示例

入门

<?php

use Ukrposhta\Ukrposhta;

// If you are using framework, like Laravel, skip this line
include __DIR__ . '/vendor/autoload.php';

$ukrpochta = new Ukrposhta('API_KEY');

// Address payload
$data = [
    'postcode'        => '02099',
    'region'          => 'Полтавська',
    'district'        => 'Полтавський',
    'city'            => 'Полтава',
    'street'          => 'Шевченка',
    'houseNumber'     => '25',
    'apartmentNumber' => '20',
];

// Get response in json
$json_string = $ukrpochta->createAddress($data);

// Decode it
$result = json_decode($json_string);

// Example of use
print_r($result->id); // 123130
print_r($result->postcode); // "02099"
print_r($result->country); // "UA"

创建地址

$ukrpochta->createAddress([
    'postcode'        => '02099',
    'region'          => 'Полтавська',
    'district'        => 'Полтавський',
    'city'            => 'Полтава',
    'street'          => 'Шевченка',
    'houseNumber'     => '25',
    'apartmentNumber' => '20',
]);

编辑地址

$ukrpochta->editAddress(123130, [
    'postcode'        => '02050',
    'region'          => 'Полтавська',
    'district'        => 'Полтавський',
    'city'            => 'Полтава',
    'street'          => 'Шевченка',
    'houseNumber'     => '50',
    'apartmentNumber' => '1',
]);

按ID显示地址

$ukrpochta->getAddress(123130);

createClient($token, $data = array())

$ukrpochta->createClient('TOKEN COUNTERPARTY', array(
    'name'                     => 'ФОП «Діскорд',
    'uniqueRegistrationNumber' => '32855961',
    'externalId'               => '12345678',
    'addressId'                => 1245,
    'phoneNumber'              => '0954623442',
    'counterpartyUuid'         => 'COUNTERPARTY UUID',
    'bankCode'                 => '612456',
    'bankAccount'              => '12345684'
));

editClient($id, $token, $data = array())

$ukrpochta->editClient('UUID_CLIENT', 'TOKEN_COUNTERPARTY', array(
    'lastName'                 => 'Петрик',
    'firstName'                => 'Иван',
    'middleName'               => 'Васильович',
    'uniqueRegistrationNumber' => '73232855',
    'addressId'                => 1,
    'phoneNumber'              => '0954623442',
    'counterpartyUuid'         => 'UUID COUNTERPARTY',
    'discount'                 => 24,
    'bankCode'                 => 254,
));

getClient($token, $id = 0, $extID = 0, $type = true)

$ukrpochta->getClient('TOKEN_COUNTERPARTY', 'ID_CLIENT');
$ukrpochta->getClient('TOKEN_COUNTERPARTY', '', 'externalId_CLIENT', false);

createGroup($data = array())

$ukrpochta->createGroup('TOKEN_COUNTERPARTY', array(
    'name'             => 'group1',
    'counterpartyUuid' => 'UUID_COUNTERPARTY',
));

editGroup($token, $id, data = array())

$ukrpochta->editGroup('TOKEN_COUNTERPARTY', 'UUID_GROUP', array(
    'name'             => 'group2',
    'counterpartyUuid' => 'UUID_COUNTERPARTY',
));

groupList($token)

$ukrpochta->groupList('TOKEN_COUNTERPARTY');

getGroup($id)

$ukrpochta->getGroup('UUID_GROUP', 'UUID_COUNTERPARTY');

createParcel($token, $data = array())

$ukrpochta->createParcel('ba5378df-985e-49c5-9cf3-d222fa60aa68', array(
    'sender'            => array(
        'name'                     => 'ПРАТ Иван Движок',
        'firstName'                => '',
        'middleName'               => '',
        'lastName'                 => '',
        'uniqueRegistrationNumber' => '2541',
        'counterpartyUuid'         => '2304bbe5-015c-44f6-a5bf-3e750d753a17',
        'addressId'                => 123130,
        'phoneNumber'              => '0954623442',
        'individual'               => false,
        'bankCode'                 => '123001',
        'bankAccount'              => '111000222000999',
    ),
    'recipient'         => array(
        'name'                     => 'Иванов Иван Иванович',
        'firstName'                => 'Иван',
        'middleName'               => 'Иванович',
        'lastName'                 => 'Иванови',
        'uniqueRegistrationNumber' => '52415',
        'counterpartyUuid'         => '2304bbe5-015c-44f6-a5bf-3e750d753a17',
        'addressId'                => 123130,
        'phoneNumber'              => '0954623442',
        'individual'               => true,
        'bankCode'                 => '123011',
        'bankAccount'              => '111000222000123',
    ),
    'shipmentGroupUuid' => '54d3cb05-7ff4-4310-ab7c-ea77af42d998',
    'deliveryType'      => 'W2W',
    'weight'            => 150,
    'length'            => 20,
    'width'             => 0,
    'height'            => 0,
    'postPay'           => 15,
    'description'       => 'test comment comment',
    'parcels'           => array(
        array(
            'name'          => 'parcel name',
            'weight'        => 1000,
            'length'        => 170,
            'declaredPrice' => 20,
        ),
    ),
));

editParcel($id, $token, $data = array())

$ukrpochta->editParcel('ID_PARCEL', 'TOKEN_COUNTERPARTY', array(
    'sender'            => array(
        'name'                     => 'ПРАТ Иван Движок',
        'firstName'                => '',
        'middleName'               => '',
        'lastName'                 => '',
        'uniqueRegistrationNumber' => '2541',
        'counterpartyUuid'         => '2304bbe5-015c-44f6-a5bf-3e750d753a17',
        'addressId'                => 123130,
        'phoneNumber'              => '0954623442',
        'individual'               => false,
        'bankCode'                 => '123001',
        'bankAccount'              => '111000222000999',
    ),
    'recipient'         => array(
        'name'                     => 'Иванов Иван Иванович',
        'firstName'                => 'Иван',
        'middleName'               => 'Иванович',
        'lastName'                 => 'Иванови',
        'uniqueRegistrationNumber' => '52415',
        'counterpartyUuid'         => '2304bbe5-015c-44f6-a5bf-3e750d753a17',
        'addressId'                => 123130,
        'phoneNumber'              => '0954623442',
        'individual'               => true,
        'bankCode'                 => '123011',
        'bankAccount'              => '111000222000123',
    ),
    'shipmentGroupUuid' => '54d3cb05-7ff4-4310-ab7c-ea77af42d998',
    'deliveryType'      => 'W2W',
    'weight'            => 1500,
    'length'            => 20,
    'width'             => 0,
    'height'            => 0,
    'postPay'           => 15,
    'description'       => 'change comment parcel',
    'parcels'           => array(
        array(
            'name'          => 'parcel name change',
            'weight'        => 1000,
            'length'        => 170,
            'declaredPrice' => 20,
        ),
    ),
));

parcelList($token)

$ukrpochta->parcelList('TOKEN_COUNTERPARTY');

getParcel($id, $token, $type = true)

$ukrpochta->getParcel('ID_PARCEL', 'TOKEN_COUNTERPARTY');
$ukrpochta->getParcel('ID_SENDER', 'TOKEN_COUNTERPARTY');

delParcelGroup($id, $token)

$ukrpochta->delParcelGroup('ID_PARCEL', 'ID_GROUP');

createForm($id, $token, $path, $type = true)

$ukrpochta->createForm('ID_PARCEL', 'TOKEN_COUNTERPARTY', __DIR__ . '/file.pdf');
$ukrpochta->createForm('ID_GROUP', 'TOKEN_COUNTERPARTY', __DIR__ . '/file.pdf', false);

Example PDF 1

createForm103($id, $token, $path)

$ukrpochta->createForm103('ID_GROUP', 'TOKEN_COUNTERPARTY', __DIR__ . '/file.pdf');

Example PDF 2

配送成本

$ukrpochta->deliveryPrice([
    'weight' => 1000,
    'length' => 55,
    'addressFrom' => [
        'postcode' => '03134'
    ],
    'addressTo' => [
        'postcode' => '62404'
    ],
    'type' => 'EXPRESS',
    'deliveryType' => 'W2W',
    'declaredPrice' => 300,
]);