apanicker / hekr-cloud-api-client
PHP版的HEKR IOT API客户端
v1.0.1
2020-06-15 16:18 UTC
Requires
- php: ^7.2.5
- ext-json: *
- guzzlehttp/guzzle: ^6.5
Requires (Dev)
- phpunit/phpunit: ^8.5
- symfony/var-dumper: ^5.1
This package is auto-updated.
Last update: 2024-09-20 00:46:19 UTC
README
这是一个简单的PHP API客户端,用于HEKR物联网云平台。
use Hekr\User;
use Hekr\Device;
use Hekr\Client;
//Initialize the client
$client = new Client();
//Setup user value object
$user = new User('user@test.com', 'password');
//Generate Access Token for the user
$auth = $client->auth($user);
//Fetch all IoT devices associated with the user account
$response = $client->setAccessToken($auth['access_token'])->getAllDevices();
$devices = $response['data'];
//Set up the device value object
$device = new Device(
$devices[0]['ctrlKey'],
$devices[0]['devTid'],
$devices[0]['productPublicKey']
);
//Fetch latest device snapshot
$snapshot = $client->setAccessToken($this->accessToken)
->setDevice($device)
->getDeviceSnapshot();
安装
使用Composer
composer require apanicker/hekr-cloud-api-client
{
"require": {
"apanicker/hekr-cloud-api-client": "^1.0.0"
}
}
测试
为了使用测试套件,请确保在tests/ClientTest.php
中更新您的HEKR用户名和密码。
$ phpunit
PHPUnit 8.5.5 by Sebastian Bergmann and contributors.
.... 4 / 4 (100%)
Time: 14.95 seconds, Memory: 6.00 MB
OK (4 tests, 8 assertions)