int0/wialon-php

Wialon API 的 PHP 客户端。

0.2.2 2024-07-19 12:02 UTC

This package is auto-updated.

Last update: 2024-09-17 17:10:59 UTC


README

Wialon API 客户端。

安装

要求

  • PHP 7.4 或更高版本。
  • PSR-18 HTTP 客户端实现。

使用 Composer 安装

使用 Guzzle 7 适配器安装

composer require xint0/wialon-php php-http/guzzle7-adapter

如果您项目中已经有一个 PSR-18 客户端,您只需安装 Wialon API 客户端

composer require xint0/wialon-php

如何使用

令牌认证

首先按照 Wialon SDK 文档中的说明获取认证令牌。

登录 Wialon 服务

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.
}

登出

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.

按名称获取单元

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.

按坐标获取位置

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"]
*/

许可证

Wialon API 客户端是开源软件,根据 MIT 许可证 授权。