firewizard/innoship-sdk

Innoship API 的消费者 SDK

v1.1.0 2022-05-19 11:08 UTC

This package is auto-updated.

Last update: 2024-09-19 16:18:27 UTC


README

请务必先阅读 Innoship API 文档Swagger 文档

需求

  • PHP >= 7.0
  • curl 扩展
  • json 扩展

安装

使用 composer 需求该包

composer require firewizard/innoship-sdk

用法

要与 API 交互,您需要创建一个新的 Innoship\Innoship 实例,使用您的 API 密钥

$innoship = new Innoship\Innoship('my-api-key-123');

这公开了几个服务对象,按照 swagger 分组

  • 快递
  • 反馈
  • 标签
  • 位置
  • 订单
  • 价格
  • 跟踪

例如,要获取所有客户端位置,调用将如下所示

$locations = $innoship->location()->clientLocations()->getContent();

所有请求都返回一个 Innoship\Response\Contract 实例,该实例提供两个公共方法

  1. isSuccessful() - 确保请求成功且内容不是错误消息
  2. getContent() - 获取实际响应

获取国家列表

$countries = $innoship->location()->countries()->getContent();

获取给定地区的城市列表

$cities = $innoship->location()->cities('94')->getContent();

获取给定国家的地区列表

$innoship->location()->regions('HU')->getContent());

获取特定时间段的反馈

$innoship->feedback()->get('2021-12-01', '2021-12-10')->getContent();

获取单个 AWB 的跟踪信息

  • 对于单个 AWB
$info = $innoship->track()->byAwb('3', '5749162310001')->getContent();
  • 对于 AWB 列表
$info = $innoship->track()->byAwb('3', ['5749162310001', '5749162310002'])->getContent();

获取 AWB 的 PDF 标签

file_put_contents('awb-5749162310001.pdf', $innoship->label()->byCourierAwb('3', '5749162310001')->getContent();

获取固定位置列表

$request = new Innoship\Request\GetFixedLocations();
$request
    ->setCourier('Sameday')
    ->setCountryCode('RO')
    ->setCountyName('Bucuresti')
    ->setLocalityName('Bucuresti')
    ->setFixedLocationType($request::TYPE_LOCKER);

$locations = $innoship->location()->fixedLocations($request);

获取运费报价

$address = new Innoship\Request\CreateOrder\Address();
$address
    ->setName('Tester Testerson')
    ->setContactPerson('Tester Testerson')
    ->setPhone('0723000000')
    ->setEmail('tester.testerson@example.com')
    ->setAddressText('Sos Principala nr 1')
    ->setLocalityName('Socolari')
    ->setCountyName('Caras-Severin')
    ->setCountry('RO');

$content = new Innoship\Request\CreateOrder\Content();
$content
    ->setParcelsCount(1)
    ->setTotalWeight(10)
    ->setContents('Obiecte de artă')
    ->setPackage('carton');

$extra = new Innoship\Request\CreateOrder\Extra();
$extra
    //->setOpenPackage(true)
    //->setSaturdayDelivery(true)
    ->setBankRepaymentAmount(125)
    ->setBankRepaymentCurrency('RON');

$request = new Innoship\Request\CreateOrder();
$request
    ->setServiceId(1)
    ->setShipmentDate(now())
    ->setAddressTo($address)
    ->paidBySender()
    ->setContent($content)
    ->setExtra($extra)
    ->setExternalClientLocation('Default')
    ->setExternalOrderId('10000001')
    ->setSourceChannel('website')
    ->setCustomAttributes(['x' => 1, 'y' => 2])
    //->includePriceBreakdown()
    //->includeCourierResponse()
    ;

$rates = $innoship->price()->get($request)->getContent();

创建新的运货 AWB

使用上述相同的请求对象,调用

$response = $innoship->order()->create($request);

确保在此次调用中设置快递 ID 和服务 ID,否则请求将失败。

删除现有的运货 AWB

$response = $innoship->order()->delete('3', '5749162310001');

贡献

发现了错误或认为有改进之处?请随意提交 PR,所有贡献都受到欢迎!

许可协议

本软件包是开源软件,遵循 MIT 许可协议