定制 booni3/dhl-express-rest 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

booni3/dhl-express-rest

Composer 安装命令:

composer require booni3/dhl-express-rest

包简介

DHL Express REST API

README 文档

README

Latest Version on Packagist

PHP package for the MyDHL Express REST API. The package is hand-written around the existing DTO surface and is tested against the bundled MyDHL API 3.3.1 OpenAPI spec.

Installation

composer require booni3/dhl-express-rest:^0.7

Client

use Booni3\DhlExpressRest\DHL;

$dhl = DHL::make([
    'user' => 'DHLUSER',
    'pass' => 'DHLPASS',
    'sandbox' => true, // false or omit for production
]);

The package sends the required x-version: 3.3.1 header on every request.

  • Sandbox base URI: https://express.api.dhl.com/mydhlapi/test/
  • Production base URI: https://express.api.dhl.com/mydhlapi/

Creating a Shipment

use Booni3\DhlExpressRest\DHL;
use Booni3\DhlExpressRest\DTO\Address;
use Booni3\DhlExpressRest\DTO\Package;
use Booni3\DhlExpressRest\DTO\ShipmentCreator;

$shipment = new ShipmentCreator();
$shipment->setShipperAccountNumber('123456789');
$shipment->setProductCode('N');
$shipment->setShipper(
    (new Address(
        'John Smith',
        '21 Apple Drive',
        '',
        '',
        'Malmesbury',
        'SN16 4TB',
        'GB',
        'business',
        'My Awesome Company',
        '07111111111',
        'sender@example.com'
    ))
        ->addVat('GB1234')
        ->addEORI('GB1234')
);
$shipment->setReceiver(new Address(
    'Helen Jones',
    '4 Example Drive',
    '',
    '',
    'London',
    'E14 8DW',
    'GB',
    'direct_consumer',
    '-',
    '07111111112',
    'receiver@example.com'
));
$shipment->addReference('123456-custom-ref');
$shipment->addPackage(new Package(12.5, 20, 10, 10, 'Jumpers', 'order-ref-1244'));

$response = $dhl->shipments()->create($shipment);

$response->trackingNumber; // shipment tracking number
$response->trackingUrl;    // DHL tracking URL
$response->labelData();    // decoded label data

Address requires a DHL typeCode: business, direct_consumer, government, other, private, or reseller. The optional trailing constructor arguments are countyName and provinceCode.

Customs, DDP, and IOSS

For customs-declarable shipments, set the customs flag, description, invoice, export declaration, and line items. DDP and IOSS are set explicitly.

use Booni3\DhlExpressRest\DTO\LineItem;
use Carbon\Carbon;

$shipment->setConsignmentDescription('Table legs');
$shipment->setCustomsDeclarable(true, true); // customs declarable, paperless trade

// DDP: adds value-added service DD and the duties/taxes billing account.
$shipment->setTermsDDP('123456789');

// IOSS: defaults to DAP unless you pass a different incoterm as the third argument.
// $shipment->setTermsIOSS('IM1234567890', 'GB');

$shipment->setInvoice('PS-1234', Carbon::now(), 'Adam Lambert');
$shipment->setExportDeclaration('sale', 'permanent', 'GBP');
$shipment->addExportLineItem(new LineItem(
    'Black steel table legs',
    84.95,
    1,
    9403999045,
    'GB',
    9.1
));

Rates

$rates = $dhl->rates()->retrieve($shipment);

$rates->cheapestProduct();
$rates->fastestProduct();
$rates->shortestTransitDaysAndCheapest();

When a declared value is set on the ShipmentCreator, rates use that value and currency. Existing callers that do not set a declared value keep the previous default of 100 GBP.

Landed Cost

The landed-cost endpoint accepts the MyDHL landed-cost request payload as an array and returns a LandedCostResponse.

$landedCost = $dhl->landedCost()->retrieve($payload);

$landedCost->warnings;
$landedCost->landedCostProducts();
$landedCost->firstLandedCostProduct();

firstLandedCostProduct() summarises the selected DHL product with totalPrice, priceCurrency, duty, tax, fee, the Duty Tax Paid service row when DHL returns one, and the raw item breakdowns.

Tracking

$tracking = $dhl->tracking()->single('1234567890');

$multiTracking = $dhl->tracking()->multi([
    '1234567890',
    '0987654321',
]);

Tracking::multi() accepts 1 to 200 tracking numbers and sends repeated shipmentTrackingNumber query parameters as required by the MyDHL spec.

Testing

composer test

The test suite uses Guzzle mock handlers only; it does not make live DHL calls. Contract tests validate built request payloads against docs/dpdhl-express-api-3.3.1.yaml, after sanitising DHL's tab-containing YAML through bin/build-spec.php.

Changelog

Please see CHANGELOG for more information about recent changes.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email adam@profilestudio.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Other Resources

booni3/dhl-express-rest 适用场景与选型建议

booni3/dhl-express-rest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 460 次下载、GitHub Stars 达 3, 最近一次更新时间为 2021 年 01 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「booni3」 「dhl-express-rest」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 booni3/dhl-express-rest 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

与 booni3/dhl-express-rest 相关的其它包

同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:

统计信息

  • 总下载量: 460
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-25