verbb/shippy

一个对框架无关、支持多承运商的PHP物流库。

资助包维护!
verbb

1.0.7 2024-08-24 21:58 UTC

This package is auto-updated.

Last update: 2024-08-24 21:58:42 UTC


README

Cloner icon

Shippy

Shippy是一个对框架无关、支持多承运商的PHP物流库。它的目标是提供一个一致的API,用于围绕不同的承运商进行运费、跟踪、标签等操作。它是免费使用的,不需要订阅SaaS提供商。

安装

您可以通过composer安装此包

composer require verbb/shippy

使用

作为一个快速示例,使用以下代码从UPS和FedEx获取运费。

use verbb\shippy\carriers\FedEx;
use verbb\shippy\carriers\UPS;
use verbb\shippy\models\Address;
use verbb\shippy\models\Package;
use verbb\shippy\models\Shipment;

// Create a shipment to set the from/to address details
$shipment = new Shipment([
    // You can supply config arrays for quick setting.
    'from' => new Address([
        'street1' => 'One Infinite Loop',
        'city' => 'Cupertino',
        'stateProvince' => 'CA',
        'postalCode' => '95014',
        'countryCode' => 'US',
    ]),
]);

// You can use traditional setters if you prefer
$toAddress = new Address();
$toAddress->setStreet1('1600 Amphitheatre Parkway');
$toAddress->setCity('Mountain View');
$toAddress->setStateProvince('CA');
$toAddress->setPostalCode('94043');
$toAddress->setCountryCode('US');
$shipment->setTo($toAddress);

// Create a package (or more) to represent what we're sending
// You can use fluent syntax if you prefer
$package = new Package()
    ->setLength(300)
    ->setWidth(100)
    ->setHeight(80)
    ->setWeight(2000)
    ->setDimensionUnit('mm')
    ->setWeightUnit('g');

$shipment->addPackage($package);

// Finally, add the carrier(s) we wish to fetch rates for. With multiple carriers, rates will be
// returned across all, sorted by cheapest to most expensive
$shipment->addCarrier(new UPS([
    'isProduction' => false,
    'clientId' => '•••••••••••••••••••••••••••••••••••',
    'clientSecret' => '•••••••••••••••••••••••••••••••••••',
    'accountNumber' => '••••••',
]));

$shipment->addCarrier(new FedEx([
    'isProduction' => false,
    'clientId' => '•••••••••••••••••••••••••••••••••••',
    'clientSecret' => '•••••••••••••••••••••••••••••••••••',
    'accountNumber' => '••••••',
]));

// Fetch the rates and print the response
$rateResponse = $shipment->getRates();

echo '<pre>';
print_r($rateResponse);
echo '</pre>';

请务必查看完整的文档

支持的承运商

Shippy支持以下承运商和功能。

新承运商

我们希望扩展此包以支持尽可能多的承运商。您可以选择以下方式之一

  • 请求新的承运商支持,我们将构建它!我们可能需要您的API凭证来验证一切。
  • 使用文档来创建您自己的(我们可以在社区承运商列表中列出它)。
  • 联系我们以安排优先级、赞助开发。

文档

访问Shippy文档。

支持

对于所有功能请求、错误和问题,请在此处创建Github问题

Shippy通过Postie进行维护,这是一个商业Craft CMS插件。

赞助

Shippy是MIT许可的,这意味着它将始终免费且开源——我们喜欢免费的东西!如果您想支持这个包,请赞助开发。如果您用于商业目的,我们强烈建议这样做。