承接 christoph-schaeffer/dhl-business-shipping 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

christoph-schaeffer/dhl-business-shipping

Composer 安装命令:

composer require christoph-schaeffer/dhl-business-shipping

包简介

DHL business customer shipping

README 文档

README

An unofficial library for the DHL business shipping soap API (Version 3.3) written in PHP.

api version api version PHP version Build Status Coverage License

Features

This library provides access to functions provided by the official dhl business shipping soap api in an object oriented way.

Since version 3.2 this library also includes the DHL shipment tracking api to obtain tracking data of sent shipments.

These functions are:

  • Create, delete and update shipment labels
  • Generate export documents
  • Check if shipment data is valid
  • Download reports of a given date as a pdf file

Additional functions this library provides:

  • Mapping the returned status messages to objects instead of just returning strings
  • Seperation of street name and street/house number. However this is experimental.
  • Country code to country name conversion
  • PHPunit testing of internal functions
  • A detailed documentation page

Since version 3.2 this library also includes the DHL shipment tracking api to obtain tracking data of sent shipments.

This introduced the following new features:

  • Obtain tracking data of sent shipments
  • Download signature images of signed shipments

Getting started

Technical Requirements

Authentication Requirements

  • DHL developer account
  • To get an API key login to your DHL developer account and register your application here. For production mode you will also have to request approval of your application by DHL.
  • DHL business customer account, which is essentially the live account a user will login and order shipment labels with.
  • For Tracking: ZT-Token and Password of that token. You can get those on the DHL business customer portal under My Data->Tracking

Installation

Add this repository to your composer.json requirements manually or navigate to your repository and enter the following command:

composer require christoph-schaeffer/dhl-business-shipping

Usage

There are 3 client classes in this library ShippingClient, TrackingClient and MultiClient. The MultiClient combines both Clients into one, which usually is what you want. Thus we use it as the base example. The authentication credentials are stored in 2 classes. One for the business shipping api and one for the tracking api. These 2 APIs are not the same and need different parameter for authentication.

Create a shipping client credentials object and fill it with your credentials.

use ChristophSchaeffer\Dhl\BusinessShipping\Credentials\ShippingClientCredentials; // Autoload the ShippingClientCredentials class

$shippingClientCredentials = new ShippingClientCredentials(
    'appID',        // In sandbox mode this is your developer ID.
    'apiToken',     // In sandbox mode this is your developer account password.
    'login',        // DHL business customer account name. This is optional and defaults to 2222222222_01 (sandbox)
    'password',     // DHL business customer password. This is optional and defaults to pass (sandbox)
);

Create a tracking client credentials object and fill it with your credentials.

use ChristophSchaeffer\Dhl\BusinessShipping\Credentials\TrackingClientCredentials; // Autoload the TrackingClientCredentials class

$trackingClientCredentials = new TrackingClientCredentials(
    'appID',        // In sandbox mode this is your developer ID.
    'apiToken',     // In sandbox mode this is your developer account password.
    'ztToken',      // DHL business customer ZT Token. This is optional and defaults to zt12345 (sandbox)
    'password',     // DHL business customer ZT Token password. This is optional and defaults to geheim (sandbox)
);

Create a client object and fill it with your credentials.

use ChristophSchaeffer\Dhl\BusinessShipping\MultiClient; // Autoload the MultiClient class

$client = new MultiClient(
    $shippingClientCredentials
    $trackingClientCredentials
    TRUE,                              // isSandbox
    MultiClient::LANGUAGE_LOCALE_ENGLISH_GB // Set the status message language to english(default is german).
);

Usage for the shipping api (shipment label creation)

The following is a simple example usage of the createShipmentOrder function. However please keep in mind that there is a lot of additional functionality. For more details or examples of other functions please read the documentation.

Create a new shipment order for each shipment you want to send.

$shipmentOrder = new \ChristophSchaeffer\Dhl\BusinessShipping\Resource\ShipmentOrder();

Set the shipment details.

$shipmentOrder->Shipment->ShipmentDetails->product = 'V01PAK'; // V01PAK = National package
$shipmentOrder->Shipment->ShipmentDetails->accountNumber = '22222222220101'; // DHL bussiness customer account number
$shipmentOrder->Shipment->ShipmentDetails->ShipmentItem->weightInKG = 1.2; // The weight including packaging
$shipmentOrder->Shipment->ShipmentDetails->shipmentDate = '2020-12-08'; // The shipping date. Must not be in the past

Set the shippers address in case the shipment can't be delivered it will be returned to that address.

$shipmentOrder->Shipment->Shipper->Name->name1 = 'DHL Paket GmbH';
$shipmentOrder->Shipment->Shipper->Address->streetName = 'Sträßchensweg';
$shipmentOrder->Shipment->Shipper->Address->streetNumber = '10';
$shipmentOrder->Shipment->Shipper->Address->zip = '53113';
$shipmentOrder->Shipment->Shipper->Address->city = 'Bonn';
$shipmentOrder->Shipment->Shipper->Address->Origin->countryISOCode = 'DE';

Set the receivers address.

$shipmentOrder->Shipment->Receiver->name1 = 'DHL Paket GmbH';
$shipmentOrder->Shipment->Receiver->Address->streetName = 'Charles-de-Gaulle-Str.';
$shipmentOrder->Shipment->Receiver->Address->streetNumber = '20';
$shipmentOrder->Shipment->Receiver->Address->zip = '53113';
$shipmentOrder->Shipment->Receiver->Address->city = 'Bonn';
$shipmentOrder->Shipment->Receiver->Address->Origin->countryISOCode = 'DE';

Add up to 30 shipment orders into an array.

$shipmentOrders = [$shipmentOrder]; // It is possible to send up to 30 shipment orders in one request.

Set up the request object, call the createShipmentOrder function and get its response.

$request = new \ChristophSchaeffer\Dhl\BusinessShipping\Request\Shipping\createShipmentOrder($shipmentOrders);
$response = $client->createShipmentOrder($request);

To check if the request was successful use the hasNoErrors function. If the request itself or any of the creation state objects have errors you can display their messages.

if($response->hasNoErrors()): // checks if any error status messages have been returned.
    echo 'Success!';
    foreach($response->CreationStates as $creationState):
        echo 'shipment number: '. $creationState->shipmentNumber;
        echo 'shipment label url:'.$creationState->LabelData->labelUrl; // When the label response type is url
        echo 'shipment label data:'.$creationState->LabelData->labelData; // When the label response type is base64 or ZPL2
    endforeach;
else:
    echo 'An error occured!\n';

    foreach($response->Status as $status): // echo all response status messages.
        echo '\n- '.$status->message;
    endforeach;

    foreach($response->CreationStates as $creationState): // There will be a creation state for each shipment order.
        foreach($creationState->LabelData->Status as $status): // echo all creation state status messages .
            echo '\n-- '.$status->message;
        endforeach;
    endforeach;
endif;

Usage for the tracking api

The following is an example of the getPieceDetail function. If you only track shipments you have sent yourself this is the best function to use, because it contains all data getPiece and getPieceEvents will return in one request. However, this request only works with shipment numbers of shipments you have sent with the same business customer account you are using the zt token of.

Set up the request object, call the getPieceDetail function and get its response.

$request = new \ChristophSchaeffer\Dhl\BusinessShipping\Request\Tracking\getPieceDetail();
$request->pieceCode = '00340434161094027318';
$response = $client->getPieceDetail($request);

To check if the request was successful use the hasNoErrors function. If the request itself or any child object does not have the status code "0", which is = success, this will return false.

if($response->hasNoErrors()): // checks if any error status messages have been returned.
    echo 'Success!';
else:
    echo 'An error occured!\n';
    echo $response->error;   // this is the string error message submitted by dhl
endif;

If you want to track shipments that you have not sent yourself you can use the getStatusForPublicUser function. This function contains less data, but works with all shipment numbers. You can also request more than one shipment number.

Please also keep in mind, that for some reason DHL decided to disable this function in sandbox mode. So you need to use production mode to test it.

Set up the pieces you want to request

$piece1 = new PieceData(); // create the first Piece you want to request
$piece1->pieceCode = '00340435091628083543'; // set the shipment number

$piece2 = new PieceData(); // create the second Piece you want to request
$piece2->pieceCode = '00340435091628083544'; // set the shipment number

$pieces = [$piece1, $piece2]; // combine both pieces into an array

Set up the request object, call the getStatusForPublicUser function and get its response.

$request = new \ChristophSchaeffer\Dhl\BusinessShipping\Request\Tracking\getStatusForPublicUser($pieces);
$response = $client->getStatusForPublicUser($request);

To check if the request was successful use the hasNoErrors function. If the request itself or any child object does not have the status code "0", which is = success, this will return false.

if($response->hasNoErrors()): // checks if any error status messages have been returned.
    echo 'Success!';

    foreach($response->pieceStatusPublicList as $pieceStatusPublic):
    if(!$pieceStatusPublic->hasNoErrors()) {
        echo 'An error occured with the shipment number'.$pieceStatusPublic->pieceCode.'\n';
        echo $pieceStatusPublic->pieceStatusDesc.'\n';
    }
endforeach;
else:
    echo 'An error occured!\n';
    echo $response->error.'\n';   // this is the string error message submitted by dhl
endif;

Documentation

  • There is an official documentation by DHL found here. However it is partly outdated and incomplete.
  • A documentation page for this project can be found here.

Support

License

This project is licensed under the MIT license. Please read the LICENSE file for details.

christoph-schaeffer/dhl-business-shipping 适用场景与选型建议

christoph-schaeffer/dhl-business-shipping 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26.84k 次下载、GitHub Stars 达 30, 最近一次更新时间为 2020 年 07 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 christoph-schaeffer/dhl-business-shipping 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 christoph-schaeffer/dhl-business-shipping 我们能提供哪些服务?
定制开发 / 二次开发

基于 christoph-schaeffer/dhl-business-shipping 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 26.84k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 31
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 30
  • Watchers: 8
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-23