soerbv/shipsgo
Composer 安装命令:
composer require soerbv/shipsgo
包简介
A PHP client for the ShipsGo v2 API.
README 文档
README
A PHP client for the ShipsGo v2 API. Tracks ocean and air shipments, manages tags and followers.
Requirements
- PHP 8.1+
- ext-curl, ext-json
Install
composer require soerbv/shipsgo
Quick start
use SoerBV\Shipsgo\Shipsgo; $shipsgo = new Shipsgo('YOUR_SHIPSGO_TOKEN'); $shipment = $shipsgo->ocean->shipments->create( containerNumber: 'MSCU1234567', carrier: 'MSCU', reference: 'PO-12345', ); echo $shipment->status->value; // e.g. "SAILING" echo $shipment->carrier?->name; // "MSC"
Authentication
The constructor accepts either a token string or a Config:
use SoerBV\Shipsgo\{Config, Shipsgo}; $shipsgo = new Shipsgo('TOKEN'); // Or for full control: $shipsgo = new Shipsgo(new Config( token: 'TOKEN', baseUri: 'https://api.shipsgo.com/v2', timeoutSeconds: 30, ));
Ocean
// Create $shipment = $shipsgo->ocean->shipments->create( containerNumber: 'MSCU1234567', // or bookingNumber carrier: 'MSCU', reference: 'PO-12345', followers: ['ops@example.com'], tags: ['IMPORT'], ); // Get one by id $shipment = $shipsgo->ocean->shipments->get(123); foreach ($shipment->containers as $container) { echo $container->number . ' — ' . $container->status->value . PHP_EOL; } // Or look up by container / booking number (returns ?Shipment, 2 API calls) $shipment = $shipsgo->ocean->shipments->findByContainerNumber('MSCU1234567'); $shipment = $shipsgo->ocean->shipments->findByBookingNumber('MEDUQY000000'); // List with pagination + filters $page = $shipsgo->ocean->shipments->list( filters: ['status' => 'eq:SAILING'], orderBy: '-created_at', skip: 0, take: 50, ); foreach ($page as $summary) { echo $summary->reference . PHP_EOL; } if ($page->meta->more) { // fetch next page with skip: 50 } // Update reference $shipsgo->ocean->shipments->update(123, 'PO-12345-updated'); // Tags / followers $tag = $shipsgo->ocean->shipments->addTag(123, 'URGENT'); $shipsgo->ocean->shipments->removeTag(123, $tag->id); $shipsgo->ocean->shipments->addFollower(123, 'ops@example.com'); // Route as GeoJSON $geo = $shipsgo->ocean->shipments->geojson(123); // Delete $shipsgo->ocean->shipments->delete(123); // Carriers $carriers = $shipsgo->ocean->carriers->list();
Air
$shipment = $shipsgo->air->shipments->create( awbNumber: '333-88888888', reference: 'AWB-REF', ); $shipment = $shipsgo->air->shipments->get(456); echo $shipment->airline?->name; // Or look up by AWB number (returns ?Shipment, 2 API calls) $shipment = $shipsgo->air->shipments->findByAwbNumber('333-88888888'); $page = $shipsgo->air->shipments->list(take: 50); $airlines = $shipsgo->air->airlines->list();
All ->shipments methods mirror the Ocean shape: get, update, delete, geojson, addTag, removeTag, addFollower, removeFollower.
Credits
The API returns credit cost and remaining balance on each call. They are surfaced both on list responses ($page->credits) and via the client:
$shipsgo->air->shipments->get(456); echo $shipsgo->lastCredits()?->remaining;
Error handling
All API errors extend SoerBV\Shipsgo\Exceptions\ApiException. Status-specific subclasses are thrown so you can catch only what you care about:
| HTTP | Exception |
|---|---|
| 401 | AuthenticationException |
| 402 | InsufficientCreditsException |
| 403 | PermissionException |
| 404 | NotFoundException |
| 409 | ConflictException |
| 422 | ValidationException |
| 429 | RateLimitException (use ->retryAfterSeconds()) |
| 5xx | ServerException |
Network/transport failures throw TransportException. Everything inherits from ShipsgoException if you want a single catch-all.
Laravel
The package is framework-neutral. To use it in Laravel, bind it in a service provider:
$this->app->singleton(Shipsgo::class, fn () => new Shipsgo(config('services.shipsgo.token')));
Upgrading from 1.x
The 1.x client (SoerBV\Shipsgo\Client) targeted the legacy v1.1 ContainerService API and is removed in 2.0. The v2 API uses a different authentication scheme (header-based token), JSON payloads, and a different endpoint layout, so there is no in-place upgrade. Replace any new Client($authCode) usage with new Shipsgo($token) and the resource methods above.
soerbv/shipsgo 适用场景与选型建议
soerbv/shipsgo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.59k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 02 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「tracking」 「air」 「ocean」 「shipsgo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 soerbv/shipsgo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 soerbv/shipsgo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 soerbv/shipsgo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP SDK for the Parcel Monkey UK API
A PSR-7 compatible library for making CRUD API endpoints
Audit changes of your Eloquent models in Laravel/Lumen
Alfabank REST API integration
Contao 4 Hintergrund-Tracking mit Matomo
Trackingmore PHP Library
统计信息
- 总下载量: 2.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-09