项目作者: awaluk

项目描述 :
Simple library to integrate application with DHL API
高级语言: PHP
项目地址: git://github.com/awaluk/dhl-api-library.git
创建时间: 2017-08-31T16:47:46Z
项目社区:https://github.com/awaluk/dhl-api-library

开源协议:MIT License

下载


DHL API Library

Travis

Important! This library isn’t complete. In this moment I implemented only few methods specified below.

Installation

  • composer install

Example usage

  1. <?php
  2. require_once 'vendor/autoload.php';
  3. $config = new \awaluk\DhlApi\Config(
  4. 'url to API',
  5. 'username',
  6. 'password'
  7. );
  8. $api = new \awaluk\DhlApi\Api($config);
  • Get API version

    1. echo $api->getVersion();
  • Check delivery on Saturday for date and postal code

    1. $saturdayDelivery = $api->getPostalCodeServices('00001', new DateTime('2017-09-02'))['deliverySaturday'];
  • Get shipments number for month

    1. $shipments = $api->getMyShipments(new DateTime('2017-09-01'), new DateTime('2017-09-30'));
    2. foreach ($shipments as $shipment) {
    3. echo $shipment['shipmentId'];
    4. }
  • Get waybill in PDF for shipment

    1. $waybill = $api->getLabels('LP', 12345)['labelData'];
  • Errors handling with exceptions

    1. try {
    2. $saturdayDelivery = $api->getPostalCodeServices('00001', new DateTime('2017-09-02'))['deliverySaturday'];
    3. } catch (\awaluk\DhlApi\Exception\ApiErrorException $e) {
    4. echo $e->getMessage();
    5. }