mvdnbrk/dhlparcel-php-api
Composer 安装命令:
composer require mvdnbrk/dhlparcel-php-api
包简介
DHL Parcel API client for PHP
README 文档
README
Installation
You can install the package via composer:
composer require mvdnbrk/dhlparcel-php-api
Usage
Initialize the DHL Parcel client and set your credentials.
$dhlparcel = new \Mvdnbrk\DhlParcel\Client(); $dhlparcel->setUserId('your-user-id'); $dhlparcel->setApiKey('your-api-key');
If you have multipe accounts, you may optionally set an account id:
$dhlparcel->setAccountId('123456');
Create a parcel
$parcel = new \Mvdnbrk\DhlParcel\Resources\Parcel([ 'reference' => 'your own reference for the parcel (optional)', 'recipient' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'street' => 'Poststraat', 'number' => '1', 'number_suffix' => 'A', 'postal_code' => '1234AA', 'city' => 'Amsterdam', 'cc' => 'NL', ], 'sender' => [ 'company_name' => 'Your Company Name', 'street' => 'Pakketstraat', 'additional_address_line' => 'Industrie 9999', 'number' => '99', 'postal_code' => '9999AA', 'city' => 'Amsterdam', 'cc' => 'NL', ], // Optional. This will be set as the default. 'pieces' => [ [ 'parcel_type' => \Mvdnbrk\DhlParcel\Resources\Piece::PARCEL_TYPE_SMALL, 'quantity' => 1, ], ], ]);
Create the shipment
$shipment = $dhlparcel->shipments->create($parcel); $shipment->id; // For shipments with multiple pieces: $shipment->pieces->each(function ($item) { $item->label_id; $item->barcode; }) // For a shipment with one single piece: $shipment->label_id; $shipment->barcode;
Retrieving a label
A label can be retrieved by using the label_id.
This will return a PDF label as a string.
$dhlparcel->labels->get($shipment->label_id);
Or you may pass the Shipment instance directly to this method:
$dhlparcel->labels->get($shipment);
Passing a
Shipmentinstance will only retrieve the label for a shipment with a single piece, or the first piece if you have created a shipment with multple pieces. If you have created a shipment with multiple pieces you should retrieve the labels one by one for each piece your shipment contains.
Setting delivery options for a parcel
You can set delivery options for a parcel by passing in the options directly when you create a parcel:
$parcel = new \Mvdnbrk\MyParcel\Resources\Parcel([ ... 'recipient' => [ ... ], 'options' => [ 'description' => 'Order #123', 'signature' => true, 'only_recipient' => true, 'cash_on_delivery' => 9.95, 'evening_delivery' => true, 'extra_assurance' => true, ... ], ]);
Or you may use a method like signature() and others after constructing the parcel:
$parcel->onlyRecipient() ->signature() ->labelDescription('Order #123') ->cashOnDelivery(9.95) ->eveningDelivery() ->extraAssurance();
Mailbox package
If you would like to send a parcel that fits in a standard mailbox you may use the mailboxpackage() method:
$parcel->mailboxpackage();
Deliver a parcel to a DHL service point
You may send a parcel to a DHL service point where a customer can pick up the parcel.
The ID of the service point can be set directly when creating a parcel
or with the servicePoint method:
$parcel = new \Mvdnbrk\MyParcel\Resources\Parcel([ ... 'options' => [ 'service_point_id' => '8004-NL-272403', ... ], ]); $parcel->servicePoint('8004-NL-272403');
Tracking a shipment
$tracktrace = $dhlparcel->tracktrace->get('JVGL...'); // Check if the shipment is delivered: $tracktrace->isDelivered;
Retrieving service points
$servicepoints = $dhlparcel->servicePoints->setPostalcode('1012AA')->setHousenumber('1')->get();
This will return a collection of ServicePoint objects:
$servicepoints->each(function ($item) {
$item->id;
$item->name;
$item->latitude;
$item->longitude;
$item->distance;
$item->distanceForHumans();
});
Usage with Laravel
You may incorporate this package in your Laravel application by using this package.
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
mvdnbrk/dhlparcel-php-api 适用场景与选型建议
mvdnbrk/dhlparcel-php-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 59.57k 次下载、GitHub Stars 达 37, 最近一次更新时间为 2019 年 02 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「parcel」 「dhl」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mvdnbrk/dhlparcel-php-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mvdnbrk/dhlparcel-php-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mvdnbrk/dhlparcel-php-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Web-IT GLS Tracking API
PHP SDK for the Parcel Monkey UK API
The PHP SDK of TrackingMore API
Courier
A PSR-7 compatible library for making CRUD API endpoints
A PHP library for connecting with multiple carriers (FedEx, UPS, USPS) using Shippo.
统计信息
- 总下载量: 59.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 37
- 点击次数: 15
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-22