harm-smits/sendcloud-shipping-api

SendCloud Shipping API 的 PHP 客户端,支持异步操作和完整对象映射

v1.5.10 2021-12-06 08:15 UTC

README

一个简单的 API,几乎支持所有调用,并相应地映射到对象。

按照以下步骤初始化客户端并与 API 一起工作

$client = new \HarmSmits\SendCloudClient\Client(
    "...",
    "..."
);

遍历所有包裹非常简单

$cursor = null;
while (($result = $client->getParcels($cursor))) {
    $cursor = $result->getNext();
    foreach ($result->getParcels() as $parcel) {
        ...
    }
}

状态同样适用

foreach ($client->getParcelStatuses() as $parcelStatus) {
    ...
}

品牌也类似

$cursor = null;
while (($result = $client->getBrands($cursor))) {
    $cursor = $result->getNext();
    foreach ($result->getBrands() as $brand) {
        ...
    }
}

所有操作都可以异步进行

$promise = $client->asyncGetParcelStatuses();
...
$result = $promise->wait();

以下方法可以直接从客户端使用,如果想要获取一个承诺(Promise),方法后缀加上 Async

  • getParcels
  • getParcel
  • createParcel
  • createParcels
  • updateParcel
  • cancelOrDeleteParcel
  • getParcelReturnPortalUrl
  • getParcelDocuments
  • getParcelStatuses
  • getReturns
  • getReturn
  • getBrands
  • getBrand
  • getShippingMethods
  • getShippingMethod
  • getPdfLabel
  • getBulkPdfLabel
  • getUser
  • getInvoices
  • getInvoice
  • getSenderAddresses
  • getSenderAddress
  • getIntegrations