valentinbv / wialon-php-sdk

v0.0.2 2020-06-12 11:11 UTC

This package is not auto-updated.

Last update: 2024-09-18 17:03:01 UTC


README

PHP 库,用于与 Wialon API 交互,包括 API 方法。

1. 前置条件

  • PHP 7.1 或更高版本
  • "guzzlehttp/guzzle": "~6.0"

2. 安装

可以使用 Composer 安装 wialon-php-sdk,运行以下命令:

composer require valentinbv/wialon-php-sdk

从 Git 安装时,请将以下内容添加到 composer.json 文件中:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/ValentinBV/wialon-php-sdk.git"
        }
    ],
    "require": {
        "valentinbv/wialon-php-sdk": "dev-master"
    }
}

3. 初始化

使用以下代码创建 Wialon API 客户端对象:

$httpClient = new GuzzleHttp\Client();
$wialonRequest = new valentinbv\Wialon\Request\Action($httpClient);
$wialonRequest->sid='your sid';

4. API 请求

您可以在以下链接找到 Wialon API 方法的完整列表:https://sdk.wialon.com/wiki/en/start

请求示例

调用方法 core/get_account_data 的示例

$httpClient = new GuzzleHttp\Client();
$wialonRequest = new valentinbv\Wialon\Request\Action($httpClient);
$wialonRequest->sid='your sid';
try {
    $result = $wialonRequest->execute(
        'core/get_account_data',
        ['type' => 2]
    );
} catch(\Exception  $e) {
    //some action
}

$result 数组包含对 Wialon 服务器查询的结果,具体请参考文档:https://sdk.wialon.com/wiki/en/start

5. 结构

所有用于与 Wialon API 交互的类都继承自基类.valentinbv\Wialon\Request\BaseRequest

因此,您可以使用基类执行对 Wialon API 的请求

$httpClient = new GuzzleHttp\Client();
$wialonRequest = new valentinbv\Wialon\Request\BaseRequest($httpClient);
$wialonRequest->sid='your sid';
try {
    $result = $wialonRequest->request(
        [
            'sid' => 'your sid',
            'svc' => 'core/get_account_data',
            'params' => json_encode(['type' => 1])
        ]
    );
} catch(\Exception  $e) {
    //some action
}

当您需要执行任意请求或部分请求时,上述方法很方便使用。https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/requests/requests

对于大多数请求,valentinbv\Wialon\Request\Action 类更方便。

还增加了一个用于接收事件的特殊类。此查询方便地用于根据文档维护会话。https://sdk.wialon.com/wiki/en/sidebar/remoteapi/apiref/requests/avl_evts

$httpClient = new GuzzleHttp\Client();
$wialonRequest = new valentinbv\Wialon\Request\Events($httpClient);
$wialonRequest->sid='your sid';
try {
    $result = $wialonRequest->execute();
} catch(\Exception  $e) {
    //some action
}

支持:bvv1988@gmail.com