PHP code example of zhaowe1 / laravel-tuya-client

1. Go to this page and download the library: Download zhaowe1/laravel-tuya-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zhaowe1 / laravel-tuya-client example snippets




ig = [
    'endpoint' => 'https://openapi.tuyacn.com',
    'access_id' => '',
    'access_secret' => '',
];
$client = LaravelTuyaClient\TuyaClient::getClient($config);


// 查询用户家庭列表
$uid = 'ay00000000';
$res = $client->send('GET', '/v1.0/users/{uid}/homes', [
        'params' => [
            'uid' => $uid
        ]
    ]
);
print_r($res);

// 获取设备日志上报
$deviceId = '';
$startTime = '';
$endTime = '';
$res = $client->send('GET', '/v1.0/devices/{device_id}/logs', [
    'params' => [
        'device_id' => $deviceId
    ],
    'query' => [
        'type' => 7,
        'start_time' => $startTime,
        'end_time' => $endTime
    ],
]);
print_r($res);

// 下发设备指令
$deviceId = '';
$commandArr = [];
$res = $client->send('POST', '/v1.0/devices/{device_id}/commands', [
    'params' => ['device_id' => $deviceId],
    'body' => ['commands' => $commandArr],
]);
print_r($res);