You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.8 KiB
76 lines
1.8 KiB
<?php
|
|
|
|
namespace zixishi\tuya;
|
|
|
|
use zixishi\Base;
|
|
|
|
class Device extends Base
|
|
{
|
|
|
|
/**
|
|
* 查看设备状态
|
|
* @param string $device_id 设备ID
|
|
* @param string $token
|
|
* @date 2022-11-24
|
|
*/
|
|
public function findDeviceStatus($device_id, $token)
|
|
{
|
|
// header
|
|
$header = [
|
|
'appid:' . $this->config['api_id'],
|
|
'cache-control:no-cache',
|
|
'Content-Type:application/json',
|
|
'datetime:' . time(),
|
|
'token:' . $token,
|
|
];
|
|
|
|
// 请求数据
|
|
$data = [
|
|
'device_id' => $device_id
|
|
];
|
|
|
|
// 发送请求
|
|
$result = $this->httpPData($this->url . 'v1/Index/findDeviceStatus',
|
|
$data, $header);
|
|
|
|
// 记录日志
|
|
$uid = defined('UID') ? UID : '';
|
|
platformLog($data, $result, 'zixishi_tuya_find_device_status_' . $uid);
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 控制设备
|
|
* @param string $device_id 设备ID
|
|
* @param string $token
|
|
* @date 2022-11-24
|
|
*/
|
|
public function controlDevice($device_id, $commands, $token)
|
|
{
|
|
// header
|
|
$header = [
|
|
'appid:' . $this->config['api_id'],
|
|
'cache-control:no-cache',
|
|
'Content-Type:application/json',
|
|
'datetime:' . time(),
|
|
'token:' . $token
|
|
];
|
|
|
|
// 请求数据
|
|
$data = [
|
|
'device_id' => $device_id,
|
|
'commands' => $commands
|
|
];
|
|
|
|
// 发送请求
|
|
$result = $this->httpPData($this->url . 'v1/Index/controlDevice',
|
|
$data, $header);
|
|
|
|
// 记录日志
|
|
$uid = defined('UID') ? UID : '';
|
|
platformLog($data, $result, 'zixishi_tuya_control_device_uid_' . $uid);
|
|
|
|
return $result;
|
|
}
|
|
} |