wedesignit / parcel-pro-php-api-client
Parcel Pro API 的 PHP 客户端
v2.1.0
2024-07-12 14:27 UTC
Requires
- php: ^8.1
- ext-json: *
- guzzlehttp/guzzle: ^6|^7
This package is auto-updated.
Last update: 2024-09-12 14:58:24 UTC
README
安装
composer require wedesignit/parcel-pro-php-api-client
版本和 PHP 兼容性
创建连接器
$client = new \WeDesignIt\ParcelPro\Client($userId, $apiKey); $parcelPro = new \WeDesignIt\ParcelPro\ParcelPro($client);
在此之后,$parcelPro 类可以返回可以调用的 Endpoints。
端点方法可以调用普通数组,或者可以使用流畅的 Resource 类。
使用示例
始终:设置
这适用于以下所有示例,并应添加到每个示例之前。
$client = new \WeDesignIt\ParcelPro\Client( '<your login ID>' '<your API key>' ); $parcelPro = new \WeDesignIt\ParcelPro\ParcelPro($client);
检查 API 密钥是否有效
$parcelPro->apiKey()->isValid();
获取货运类型
$parcelPro->shipmentType()->list();
响应示例(来自文档)
[
[
"Id" => 8,
"Type" => "DFY",
"Code" => "00",
"Label" => "DFY",
"Carrier_Id" => 2,
"Carrier" => "DHL",
"CarrierNaam" => "DHL",
"CarrierLabel" => "",
"CarrierKlantcode" => "1234567",
"Buitenland" => 1,
"Benelux" => 1,
"EU" => null,
"Worldwide" => null,
"Land" => null,
"Tolplichtig" => null,
"InleverenOpServicePoint" => 1,
"ServicePoint" => 1,
"HandtekeningVoorOntvangst" => 1,
"NietBijBuren" => 1,
"AvondLevering" => null,
"ZaterdagLevering" => null1,
"1100Levering" => null,
"VerhoogdAansprakelijk" => 1,
"Rembours" => null,
"MiniPallet" => null,
"Pallet" => null,
"Collo" => null
],
[
"Id" => 9,
"Type" => "PostNL",
"Code" => "3085",
"Label" => "Standaard Pakket",
"Carrier_Id" => 3,
"Carrier" => "PostNL",
"CarrierNaam" => "PostNL",
"CarrierLabel" => "",
"CarrierKlantcode" => "7654321",
"Buitenland" => 0,
"Benelux" => 0,
"EU" => null,
"Worldwide" => null,
"Land" => null,
"Tolplichtig" => null,
"InleverenOpServicePoint" => null,
"ServicePoint" => 1,
"HandtekeningVoorOntvangst" => 1,
"NietBijBuren" => 1,
"AvondLevering" => null,
"ZaterdagLevering" => null1,
"1100Levering" => null,
"VerhoogdAansprakelijk" => 1,
"Rembours" => null,
"MiniPallet" => null,
"Pallet" => null,
"Collo" => null
]
]
这将返回一个布尔值。
发送货运
$shipment = [ 'Carrier' => 'Carrier name', 'Type' => 'Shipment type', 'Referentie' => 'E.g. your order number', 'Zaterdaglevering' => '1', 'NaamAfzender' => 'Michael Scott', 'StraatAfzender' => 'Street', 'NummerAfzender' => '11', 'ToevoegingAfzender' => 'A', 'PostcodeAfzender' => '1000 AB', 'PlaatsAfzender' => 'Scranton', 'LandAfzender' => 'NL', 'Naam' => 'Dwight Schrute', 'Straat' => 'Street' 'Nummer' => '11', 'Toevoeging' => 'A', 'Postcode' => '1000 AB', 'Plaats' => 'Scranton', 'Land' => 'NL', 'Email' => 'assistant-regional-manager@dundermifflin.ext', 'AantalPakketten' => 1, 'Gewicht' => 1, 'Opmerking' => 'Thanks to the world\'s #1 boss', ]; $parcelPro->shipment()->create($shipment);
如果您喜欢面向对象的编程方法,也可以使用 Shipment 资源类(及其 子类)。
获取货运标签
如有需要用于打印。注意,您已经从创建货运的调用中获得了标签 URL,您也可以将其呈现给用户以便他们直接访问标签。
// for PDF version $label = $parcelPro->shippingLabel()->get($shipmentId); // for HTML version $pdf = false; $label = $parcelPro->shippingLabel()->get($shipmentId, $pdf);