xint0 / wialon-php
PHP client for the Wialon API.
0.2.2
2024-07-19 12:02 UTC
Requires
- php: >=8.1
- ext-json: *
- php-http/discovery: ^1.0
- psr/http-client-implementation: *
- psr/http-factory-implementation: *
- psr/http-message: ^1.0 || ^2.0
- symfony/options-resolver: ^6.1 || ^7.0
Requires (Dev)
- guzzlehttp/psr7: ^2.0
- php-http/message: ^1.0
- php-http/mock-client: ^1.0
README
Wialon API client.
Installation
Requirements
- PHP 7.4 or later.
- PSR-18 HTTP client implementation.
Install using Composer
Install with Guzzle 7 adapter:
composer require xint0/wialon-php php-http/guzzle7-adapter
If you already have a PSR-18 client in your project, you can install only the Wialon API client:
composer require xint0/wialon-php
How to use
Token authentication
First follow the instructions in the Wialon SDK documentation to obtain an authentication token.
Login to Wialon service
use Xint0\WialonPhp\Wialon;
use Xint0\WialonPhp\WialonException;
// You can specify a custom host.
$baseUri = 'https://hst-api.wialon.com';
$wialon = new Wialon($baseUri)
try {
$token = 'your authentication token';
$wialon->login($token);
// After logging in to service a session ID is returned.
$wialon->sessionId()
} catch (WialonException $exception) {
// WialonException is thrown when request fails or service returns error response.
}
Logout
use Xint0\WialonPhp\Wialon;
use Xint0\WialonPhp\WialonException;
$token = 'token';
$wialon = new Wialon();
$wialon->login($token);
$wialon->logout();
$wialon->sessionId(); // Returns `null` after logging out.
Get unit by name
use Xint0\WialonPhp\Wialon;
use Xint0\WialonPhp\WialonException;
$token = 'token';
$wialon = new Wialon();
$wialon->login($token);
$data = $wialon->unitByName('Unit name'); // Returns associative array with response data.
Get location by coordinates
use Xint0\WialonPhp\Wialon;
use Xint0\WialonPhp\WialonException;
$token = 'token';
$wialon = new Wialon();
$wialon->login($token);
$longitude = -111.004287;
$latitude = 30.6141861;
$format = '32100';
$data = $wialon->getLocations($longitude, $latitude, $format); // Returns associative array with response data.
/*
$data == ["Magdalena, Sonora, Mexico"]
*/
License
The Wialon API client is open source software licensed under the MIT license.