ashirchkov/yandex-logistics

Yandex logistics (同日和次日) 交付API服务的PHP SDK

1.0.1 2023-11-27 09:39 UTC

This package is auto-updated.

Last update: 2024-08-27 11:26:18 UTC


README

完整的SDK实现,用于集成Yandex Logistics API

描述

API文档

次日配送API

「快递配送」/「当日配送」API

功能

次日配送API

  • [x] 准备订单
    • [x] 预估配送成本
    • [x] 获取配送时间间隔
  • [x] 自提点和物流点
    • [x] 获取居民点标识符
    • [x] 获取自提点和物流点列表
  • [x] 主要请求
    • [x] 创建订单
    • [x] 确认订单
    • [x] 获取订单信息
    • [x] 获取时间间隔内的订单信息
    • [x] 编辑订单
    • [x] 获取新收货地点的配送时间间隔
    • [x] 订单状态历史
    • [x] 取消订单
  • [x] 标签和交接单
    • [x] 获取标签
    • 获取发货交接单

次日配送API

  • [ ] 「当日配送」方法
    • [ ] 「当日配送」时间间隔
  • [ ] 预估
    • [ ] 不创建订单的初步成本评估
    • [ ] 获取点的可用运费
  • [ ] 基础方法
    • [ ] 创建订单
    • [ ] 确认订单
    • [ ] 搜索订单
    • [ ] 获取订单信息
  • [ ] 取消订单和跳过点
    • [ ] 获取取消标志
    • [ ] 取消订单
    • [ ] 在多地点订单中跳过点
  • [ ] 快递员信息
    • [ ] 获取快递员电话
    • [ ] 获取快递员位置
    • [ ] 获取跟踪快递员的链接
  • [ ] 确认码和交接单
    • [ ] 获取确认码
    • [ ] 获取交接单
  • [ ] 订单信息
    • [ ] 获取多个订单的信息
    • [ ] 订单变更日志
    • [ ] 获取到达点的预计时间
  • [ ] 编辑订单
    • [ ] 在确认前编辑订单
    • [ ] 确认后部分编辑订单
    • [ ] 获取变更应用结果
  • [ ] 罗盘
    • [ ] 检查罗盘配送可能性
    • [ ] 打开罗盘盖
  • [ ] 确认配送
    • [ ] 获取点的照片
    • [ ] 获取订单信息

安装

$ composer require ashirchkov/yandex-logistics

SDK文档

初始化API客户端

示例中使用GuzzleHttp客户端,您可以使用任何PSR-18客户端。

<?php 

require_once 'vendor/autoload.php';

$psr18Client = new GuzzleHttp\Client();
$apiKey = '<your API-key>';
$testMode = true; // Если установлен true, запросы будут отправляться к тестовому API сервису Yandex

$apiClient = new AlexeyShirchkov\Yandex\Logistics\Client($psr18Client, $apiKey, $testMode); 

以下示例中假设您已初始化 $apiClient

次日配送API

预估配送成本

参数列表

$params = [
    'tariff' => 'self_pickup',
    'source' => [
        'platform_station_id' => '4eb18cc4-329d-424d-a8a8-abfd8926463d',
    ],
    'destination' => [
        'platform_station_id' => '0530d1b2-58be-4dba-8d69-3fb86fd61c9c',
    ],
    'total_assessed_price' => 100000,
    'total_weight' => 1000,
]

$response = $apiClient->anotherDay()->calculate()->calculatePrice($params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}

获取配送时间间隔

参数列表

$stationId = '4eb18cc4-329d-424d-a8a8-abfd8926463d';

$params = [
    'self_pickup_id' => '0530d1b2-58be-4dba-8d69-3fb86fd61c9c',
    'send_unix' => true,
];

$response = $apiClient->anotherDay()->calculate()->calculateIntervals($stationId, $params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}

获取居民点标识符

参数列表

$response = $apiClient->anotherDay()->location()->getGeoIdByAddress('Москва');

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}

获取自提点和物流点列表

参数列表

$params = [
    'type' => 'terminal',
];

$response = $apiClient->anotherDay()->location()->getPointList($params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}

创建订单

参数列表

$params = [
    'info' => [
        'operator_request_id' => '1234',
    ],
    'recipient_info' => [
        'first_name' => 'Иван',
        'phone' => '+79999999999',
    ],
    'billing_info' => [
        'payment_method' => 'already_paid',
    ],
    'source' => [
        'platform_station' => [
            'platform_id' => '4eb18cc4-329d-424d-a8a8-abfd8926463d',
        ],
    ],
    'destination' => [
        'type' => 'platform_station',
        'platform_station' => [
            'platform_id' => '0530d1b2-58be-4dba-8d69-3fb86fd61c9c',
        ],
    ],
    'places' => [
        [
            'barcode' => '1234567890',
            'physical_dims' => [
                'predefined_volume' => 100,
                'weight_gross' => 1000,
            ],
        ],
    ],
    'items' => [
        [
            'name' => 'Ручка шариковая (цвет синий)',
            'count' => 5,
            'article' => 'a123456',
            'billing_details' => [
                'assessed_unit_price' => 10000,
                'unit_price' => 10000,
            ],
            'place_barcode' => '1234567890',
        ],
        [
            'name' => 'Ручка шариковая (цвет красный)',
            'count' => 5,
            'article' => 'a654321',
            'billing_details' => [
                'assessed_unit_price' => 20000,
                'unit_price' => 20000,
            ],
            'place_barcode' => '1234567890',
        ],
    ],
    'last_mile_policy' => 'self_pickup',
];

$response = $apiClient->anotherDay()->order()->createOrder($params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}

确认订单

参数列表

$offerId = '<your offer_id>'; // offer_id, полученный после выполнения createOrder

$response = $apiClient->anotherDay()->order()->confirmOrder($offerId);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}

获取订单信息

参数列表

$requestId = '<your request_id>'; // request_id, полученный после выполнения confirmOrder

$response = $apiClient->anotherDay()->order()->getOrder($requestId);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}

获取时间间隔内的订单信息

参数列表

$params = [
    'from' => (new DateTime('today'))->getTimestamp(),
    'to' => (new DateTime('tomorrow'))->getTimestamp(),
];

$response = $apiClient->anotherDay()->order()->getOrders($params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}

编辑订单

参数列表

$requestId = '<your request_id>'; // request_id, полученный после выполнения confirmOrder

$params = [
    'recipient_info' => [
        'name' => 'Пётр'
    ]
];

$response = $apiClient->anotherDay()->order()->editOrder($requestId, $params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}

获取新收货地点的配送时间间隔

参数列表

$requestId = '<your request_id>'; // request_id, полученный после выполнения confirmOrder

$params = [
    'destination' => [
        'type' => 'platform_station'
    ],
];

$response = $apiClient->anotherDay()->order()->redeliveryOrder($requestId, $params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}

订单状态历史

参数列表

$requestId = '<your request_id>'; // request_id, полученный после выполнения confirmOrder

$response = $apiClient->anotherDay()->order()->orderStatusHistory($requestId);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}

取消订单

参数列表

$requestId = '<your request_id>'; // request_id, полученный после выполнения confirmOrder

$response = $apiClient->anotherDay()->order()->cancelOrder($requestId);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}

获取标签

参数列表

$requestIds = [
    '<your request_id>' // список request_id, полученных после выполнения confirmOrder
];

$response = $apiClient->anotherDay()->label()->generateLabels($requestIds);

if ($response->isSuccess()) {
    file_put_contents(__DIR__ . '/labels.pdf', $response->getResult());
} else {
    var_dump($response->getErrors());
}

获取发货交接单

参数列表

$params = [
    'request_ids' => [
        '<your request_id>' // список request_id, полученных после выполнения confirmOrder
    ]
]

$response = $apiClient->anotherDay()->label()->getHandoverAct($params);

if ($response->isSuccess()) {
    var_dump($response->getResult());
} else {
    var_dump($response->getErrors());
}

「快递配送」/「当日配送」API

即将推出...