chrisjohnleah/velocity-fleet-api
Composer 安装命令:
composer require chrisjohnleah/velocity-fleet-api
包简介
Framework-agnostic PHP SDK for the Radius Velocity Fleet Telematics API (customers + live device positions), built on Saloon.
README 文档
README
A modern, framework-agnostic PHP SDK for the Radius Velocity Fleet Telematics API, built on Saloon. Bearer authentication, an optional OAuth2 refresh-token flow, typed responses, and transient-error backoff — all baked in.
Using Laravel? Reach for the companion bridge
chrisjohnleah/velocity-fleet-api-laravelfor a service provider, config, and a persistent token store.
What it covers
The Velocity Telematics API exposes a small, focused surface — and this SDK wraps all of it:
| Endpoint | SDK |
|---|---|
| List the customers linked to your user | $velocity->customers()->list() |
| List live device (vehicle) positions for a customer | $velocity->devicePositions()->forCustomer($id) |
Requirements
- PHP 8.3+
- A Velocity Fleet API token (generated in the UI), or a customer-issued refresh token if you're a third-party integration.
Installation
composer require chrisjohnleah/velocity-fleet-api
Quick start
With an API token (existing customers)
Generate a token in the Velocity UI under Account → Account Settings → API Integrations → Create API Token, then:
use ChrisJohnLeah\VelocityFleet\VelocityFleet; $velocity = VelocityFleet::withToken(getenv('VELOCITY_API_TOKEN')); // Every customer linked to your user — typed. foreach ($velocity->customers()->list() as $customer) { printf("%s (#%s) — %s\n", $customer->name, $customer->number, $customer->product); }
With a refresh token (third-party integrations)
Your customer supplies a Refresh Token. The SDK exchanges it for a short-lived access token on first use (standard OAuth2 refresh_token grant), and refreshes again whenever a call comes back unauthorised:
use ChrisJohnLeah\VelocityFleet\VelocityFleet; $velocity = VelocityFleet::withRefreshToken( refreshToken: getenv('VELOCITY_REFRESH_TOKEN'), clientId: getenv('VELOCITY_CLIENT_ID'), // if your OAuth client requires it clientSecret: getenv('VELOCITY_CLIENT_SECRET'), );
Reading device positions
$positions = $velocity->devicePositions()->forCustomer($customer->id); echo "{$positions->deviceCount} devices\n"; foreach ($positions->devices as $device) { printf( "%s @ %.5f,%.5f — %d %s, ignition %s, seen %s\n", $device->vehicleRegistration, $device->lat ?? 0.0, $device->lon ?? 0.0, $device->speed ?? 0, $device->speedMeasureText ?? '', $device->ignitionOn() ? 'on' : 'off', $device->occurredAt()?->format('H:i') ?? 'n/a', ); } // The same devices are also grouped: foreach ($positions->deviceGroups as $group) { echo "{$group->name}: ".count($group->devices)." devices\n"; }
Use the right id. The customers response is keyed by each customer's unique id — exposed as
Customer::$id. Pass that toforCustomer(), not the human-facingCustomer::$number.
Persisting tokens
When you use the refresh-token flow, implement Contracts\TokenStore to keep the rotated token between requests (the in-memory ArrayTokenStore only lives for the current process). The token endpoint may rotate the refresh token, so your put() must always overwrite the previous record:
use ChrisJohnLeah\VelocityFleet\Auth\StoredToken; use ChrisJohnLeah\VelocityFleet\Contracts\TokenStore; use ChrisJohnLeah\VelocityFleet\VelocityFleet; use ChrisJohnLeah\VelocityFleet\VelocityFleetConnector; final class MyTokenStore implements TokenStore { public function get(): ?StoredToken { /* load access/refresh/expiresAt */ } public function put(StoredToken $token): void { /* overwrite */ } public function forget(): void { /* delete */ } } $velocity = new VelocityFleet( new VelocityFleetConnector(clientId: '…', clientSecret: '…'), new MyTokenStore(), );
Errors
Failures surface as typed exceptions, all extending Exceptions\VelocityFleetException:
| Exception | When |
|---|---|
NotConnectedException |
No token available (and none could be obtained) |
AuthenticationException |
401 / 403 after a refresh attempt — re-authorise |
ApiException |
Any other API error or transport failure (carries ->status, ->body, ->headers, header(), and retryAfter()) |
use ChrisJohnLeah\VelocityFleet\Exceptions\ApiException; try { $velocity->devicePositions()->forCustomer($id); } catch (ApiException $e) { report("Velocity API {$e->status}: {$e->getMessage()}"); }
A note on authentication details
The Velocity API is a Django REST Framework service using Bearer (SimpleJWT) access tokens, with token issuance via an OAuth2 endpoint (django-oauth-toolkit). The third-party refresh-token exchange isn't part of the public reference, so the SDK targets the standard OAuth2 refresh_token grant at https://www.velocityfleet.com/o/token/ by default. If your integration documents a different token endpoint or client-authentication requirement, pass it through VelocityFleetConnector (tokenEndpoint, clientId, clientSecret) — no code changes needed.
Sending raw requests
Anything not yet wrapped in a resource can be sent through the client, which still applies auth, refresh-on-401, and typed error handling:
use ChrisJohnLeah\VelocityFleet\Requests\Customers\GetCustomers; $customers = $velocity->send(new GetCustomers())->dto();
Testing
composer test # Pest composer analyse # PHPStan (max) composer lint # Pint --test composer check # all three
Tests never hit the network — every request is faked with Saloon's MockClient.
Contributing
Issues and PRs welcome — see CONTRIBUTING.md. Please report security issues privately per SECURITY.md.
Licence
MIT © Chris John Leah. See LICENSE.
Not affiliated with or endorsed by Radius or Velocity Fleet. "Radius", "Velocity" and "Kinesis" are trademarks of their respective owners.
chrisjohnleah/velocity-fleet-api 适用场景与选型建议
chrisjohnleah/velocity-fleet-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 06 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sdk」 「radius」 「Kinesis」 「velocity」 「telematics」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chrisjohnleah/velocity-fleet-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chrisjohnleah/velocity-fleet-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chrisjohnleah/velocity-fleet-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
TYPO3 Address-Manager by coding.ms: Filial-finder, radius-search, location-overview, store-finder, radial-search, radius-search, people-directory, person-database, employee-directory: Manages and displays address and person records. Comes with three kinds of categories (groups, organisations and pos
Calculate LatLng radius
A PSR-7 compatible library for making CRUD API endpoints
Fork of original package to allow use on Packagist. This plug-in allows finding and selecting a location on the Google map. Along with single point selection, it allows area selection by choosing a point and specifying a radius. The selection can be saved to any HTML input element or processed by Ja
Complete, universal PHP client for Mikrotik RouterOS v7 REST API. Framework-agnostic, zero-dependency.
Complete, universal PHP client for Mikrotik RouterOS v6 API (Socket Protocol Port 8728). Framework-agnostic, zero-dependency.
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 42
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-09