定制 evilhalba/tuyapiphp-fork 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

evilhalba/tuyapiphp-fork

最新稳定版本:1.2

Composer 安装命令:

composer require evilhalba/tuyapiphp-fork

包简介

Tuya cloud api home management php client

README 文档

README

This is a simple php client to interact with devices that support the tuya api.

A version of the lib for nodejs is hosted here: https://github.com/ground-creative/tuyacloudnodejs

If you are looking for a more ready to use solution or u need to control devices from different brands, you can use this tool with nodejs.

Requirements

I believe all is needed is php curl for the requests.

Installation

With composer:

Add the package to your composer.json file

"require": 
{

        "tuyapiphp/tuyapiphp": "*"
}

and run composer update

Stand Alone:

You must require all the needed classes manually, or you can use an autoloader like this one.

Basic Usage

Use these setup instructions for how to find the needed parameters.

Create new instance

$config =
[
	'accessKey' 	=> 'xxxxxxxxxxxxxxxxx' ,
	'secretKey' 	=> 'xxxxxxxxxxxxxxxxx' ,
	'baseUrl'		=> 'https://openapi.tuyaus.com'
];

$tuya = new \tuyapiphp\TuyaApi( $config );

Get an access token

$data = $tuya->token->get_new( );	

Example device operations

$app_id = 'xxxxxxxxxxxxxxxxxxxx';

$device_id = 'xxxxxxxxxxxxxxxxxxx';

// Get a token
$token = $tuya->token->get_new( )->result->access_token;

// Get list of devices connected with tuya/smart life app
$tuya->devices( $token )->get_app_list( $app_id );

// Get device status
$tuya->devices( $token )->get_status( $device_id );

// Set device name
$tuya->devices( $token )->put_name( $device_id , [ 'name' => 'FAN' ] );

// Send command to device
$payload = [ 'code' => 'switch_1' , 'value' => false ];
$tuya->devices( $token )->post_commands( $device_id , [ 'commands' => [ $payload ] ] );

Example camera stream

$app_id = 'xxxxxxxxxxxxxxxxxx';

$camera_id = 'xxxxxxxxxxxxxxxxxxxx';

$tuya = new \tuyapiphp\TuyaApi( $config );

// Get a token
$token = $tuya->token->get_new( )->result->access_token;

// Get camera stream link
$stream = $tuya->devices( $token )->post_stream_allocate( $app_id , $camera_id , [ 'type' => 'rtsp' ] );
        

Use the returned url to open the stream: ffplay -i rtsps://xxxxxxxxx

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 18
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2025-12-07