solunsky/dpd-interconnector

Interconnector是一个基于REST的Web服务,用于集成DPD客户的系统信息,通过POST请求允许使用DPD提供的服务。Interconnector允许通过传输运输信息、请求包裹取件、打印包裹标签等方式使用DPD服务。

v1.0.0 2020-10-11 16:12 UTC

This package is auto-updated.

Last update: 2024-09-12 20:56:49 UTC


README

Interconnector是一个基于REST的Web服务,用于集成DPD客户的系统信息,通过POST请求允许使用DPD提供的服务。Interconnector允许通过传输运输信息、请求包裹取件、打印包裹标签等方式使用DPD服务。

文档

Interconnector (EN) V2.6 | 来自DPD LV(DPD货物运输创建和跟踪Web服务)

Interconnector (EN) V2.4 | 来自DPD EE

安装

要求

  • PHP >=5.5

在PHP ^7.*上运行

composer require solunsky/dpd-interconnector

完整示例

use Solunsky\Interconnector\Authentication;
use Solunsky\Interconnector\Request\CreateShipment;
use Solunsky\Interconnector\Request\PrintLabel;
use Solunsky\Interconnector\Client;

$auth = new Authentication('username', 'password', 'lv');
$shipmentRequest = new CreateShipment($auth, $params);
$client = new Client(array('verify' => false));

// Response
$shipmentResponse = $client->get($shipmentRequest);
// Output json

// Response Label
$printRequest = new PrintLabel($auth, $shipmentResponse['pl_number']);
$printResponse = $client->get($printRequest, false);
// Output string

header("Content-type:application/pdf");
echo $print;

认证(步骤1)

参数
string|array $countryCode: 'lv' or 'ee' or 'lt' or array("uk" => "https://integration.dpd.uk/ws-mapper-rest/")
boolean $debug: default false
示例
use Solunsky\Interconnector\Authentication;

$auth = new Authentication('username', 'password', $countryCode);

方法(步骤2)

创建货物运输

此方法创建可以包含一个或多个包裹的货物运输。创建货物运输所需的数据将取决于请求的DPD服务。

参数

阅读文档

array $params
示例
use Solunsky\Interconnector\Request\CreateShipment;

$response = new CreateShipment($auth, $params);

创建包裹标签

此方法生成包裹标签。存在通过DPD在打印包裹时触发的自动数据提交配置的可能性。

参数

阅读文档

string $numbers: parcel number (pl_number)
string $printType: default PDF, other epl, zpl
string $printFormat: default A6, other A4, A5
integer $printSequence: default 1
string $printPosition: default LeftTop
示例
use Solunsky\Interconnector\Request\PrintLabel;

$print = new PrintLabel($auth, $response['pl_number']);

header("Content-type:application/pdf");
echo $print;

请求包裹取件

此方法为DPD提供您需要快递员取件包裹的信息。如果不存在预约定的常规包裹取件时间,则必须使用此方法。

参数

阅读文档

array $params
示例
use Solunsky\Interconnector\Request\ParcelPickup;

$response = new ParcelPickup($auth, $params);

搜索取件点

此方法提供DPD取件点(包裹商店和取件柜)的列表。

参数

阅读文档

array $params

请求包裹取件

此方法为DPD提供您需要快递员取件包裹的信息。如果不存在预约定的常规包裹取件时间,则必须使用此方法。

参数

阅读文档

array $params
示例
use Solunsky\Interconnector\Request\ParcelPickup;

$response = new ParcelPickup($auth, $params);

删除包裹

此方法删除特定包裹。如果货物运输包含多个包裹,如果删除此货物运输中的任何包裹,则整个货物运输将被删除。

注意:如果在关闭清单、使用parcelDataSend_(发送包裹数据)或DPD配置的自动数据传输之后传输数据,则无法执行此功能。

参数

阅读文档

string $numbers
示例
use Solunsky\Interconnector\Request\DeleteShipment;

$response = new DeleteShipment($auth, $numbers);

提交包裹数据

此方法将货物运输数据提交给DPD。此功能的频率可以根据客户流程进行调整,但至少应在快递员到达前30分钟请求。如果需要,可以在每个包裹之后使用。如果使用清单关闭或DPD配置的自动数据传输,则不应使用此方法。

参数

阅读文档

mixed $auth
示例
use Solunsky\Interconnector\Request\SendParcelData;

$response = new SendParcelData($auth);

关闭清单

此方法提交特定日期创建的货物运输数据,并返回包含有关在当天通过API用户创建的所有包裹的信息的文档,这些包裹未包含在任何其他清单中。此功能的频率可以根据客户流程进行调整,但至少应在快递员到达前30分钟请求。如果需要,可以在每个包裹之后使用。如果使用包裹数据提交方法或DPD配置的自动数据传输,则不应使用此方法。

参数

阅读文档

mixed $date: (YYYYMM-DD)
mixed $format: default PDF, other json, zpl, epl
示例
use Solunsky\Interconnector\Request\PrintManifest;

$response = new PrintManifest($auth, $date, $format);

收集请求

此方法允许将快递员派送到第三方地址。例如,DPD客户为其客户组织免费的退货服务(由DPD客户而非其客户支付)。

参数

阅读文档

array $params
示例
use Solunsky\Interconnector\Request\RequestCollection;

$response = new RequestCollection($auth, $params);

客户端(步骤3)

参数

阅读GuzzleHttp文档

客户端类

array $params

Get方法

mixed $request,
boolean $jsonDecode: default true
示例
use Solunsky\Interconnector\Client;

$client = new Client(array('verify' => false));

$response = $client->get($request);

创建自定义请求

如果您想创建自己的自定义请求,请使用此示例。

namespace Solunsky\Interconnector\Request;

class CustomRequest extends Request
{
    private $params;

    public function __construct($authentication, $params)
    {
        parent::__construct($authentication);

        $this->params = $params;
    }

    public function get()
    {
        $body = array_merge(
            $this->authentication->credentials(),
            $this->params
        );

        $headers = array(
            'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8',
        );

        return $this->build('POST', 'method_uri', $headers, $body);
    }
}

使用
$customRequest = new CustomRequest($auth, $params);

$response = $client->get($customRequest);