Last Updated on : 2025-07-21 07:43:09download
The integration of the WeChat ecosystem is rather complex. Developers need to be familiar with the corresponding technologies and have relevant integration experience. Therefore, it’s suggested to contact Tuya for consultation and assessment before deciding whether to start the SDK development.
The @ray-js/wechat-ms-basic
SDK integrates basic capabilities that enable users to unlock a door remotely, retrieve the streaming URL of a live video, get the first frame of a video, and determine the device type through the lock miniapp.
yarn add @ray-js/wechat-ms-basic
// or
npm install @ray-js/wechat-ms-basic
getUser
This API cannot query the details of the members with whom the device is shared.
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
user_id | string or number | The user ID. The value defaults to 0, which represents the current user. | false |
Response parameters
Parameter | Type | Description |
---|---|---|
avatar_url | string | The avatar URL. |
lock_user_id | number | The lock user ID. |
nick_name | string | The nickname. |
user_contact | string | The contact information. |
user_id | string | The user ID. |
user_type | number |
|
Sample request
import MsBasicApi from '@ray-js/wechat-ms-basic';
MsBasicApi.getUser(device_id)
.then(response => {
console.log(response);
})
.catch(error => console.log(error));
Sample response
{
user_type: 50,
avatar_url: 'https://images.tuyacn.com/xxxxxxx.png',
user_id: '5958862',
nick_name: 'Alice',
user_contact: 'xxxxxx@tuya.com',
lock_user_id: 1
}
getRemoteUnlockTicket
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
Response parameters
Parameter | Type | Description |
---|---|---|
ticket_id | string | The ID of the temporary key. |
ticket_key | string | The temporary key. |
expire_time | number | The amount of time left before the key expires. |
getRemoteUnlock
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
ticket_id | string | The ID of the authorization key, which is gotten through getRemoteUnlockTicket . |
true |
Response parameters
Return a boolean value to indicate whether the door is unlocked remotely.
This SDK will be deprecated in the future.
passwordFree
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
open | bool | Lock/Unlock | true |
ticket_id | string | The ID of the authorization key, which is gotten through getRemoteUnlockTicket . |
true |
Response parameters
Return a boolean value to indicate whether the door is locked or unlocked remotely.
rejectRemoteUnlock
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
Response parameters
Return a boolean value to indicate whether the remote unlocking request is denied.
getLastDpCache
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
Response parameters
Return DPs in JSON format.
getHardwareType
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
Response parameters
Parameter | Type | Description |
---|---|---|
code | string | The category code. videolock represents smart video locks. |
hardware | string | The hardware type. |
getLatestDp212
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
Response parameters
Parameter | Type | Description |
---|---|---|
file_key | string | The encryption key. |
file_url | string | The full file URL. |
angle | number | The angle of rotation. |
getDecryptUrl
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
encrypted_url | string | The file URL. It is obtained by base64-encoding file_url gotten through getLatestDp212 . |
true |
secret_key | string | The file key. It is the same as file_key gotten through getLatestDp212 . |
true |
Response parameters
Parameter | Type | Description |
---|---|---|
url | string | The image URL, which must be base64-decoded. |
Example
import MsBasicApi from '@ray-js/wechat-ms-basic';
const result = await MsBasicApi.getLatestDp212(device_id);
const { file_key, file_url, angle } = result;
const encodeUrl = await MsBasicApi.getDecryptUrl({
device_id,
encrypted_url: MsBasicApi.base64encode(file_url),
secret_key: file_key,
});
const imgUrl = MsBasicApi.base64decode(encodeUrl);
getLockMediaStream
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
Response parameters
Parameter | Type | Description |
---|---|---|
url | string | The streaming URL. |
getRotateAngle
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
Response parameters
Parameter | Type | Description |
---|---|---|
angle | number | The angle of rotation. |
getDevSkill
Get the skill, which includes information such as the width and height of a video stream.
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
Response parameters
Return a string, which must be converted to JSON format.
Sample response
'{"cloudGW":1,"cloudP2P":1,"audios":[{"channels":1,"dataBit":16,"codecType":106,"sampleRate":8000}],"videos":[{"streamType":2,"profileId":"","width":1280,"codecType":2,"sampleRate":90000,"height":720}],"p2p":4}';
Determine whether it is an H.264 device: videos[0].codecType === 2 && videos[0].streamType === 2
getRtcConfig
Get the RTC configuration, which includes the skill.
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
Response parameters
Parameter | Type | Description |
---|---|---|
skill | string | The skill, which is the same as the skill gotten through getDevSkill . |
getTicket
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
uid | string | The user ID. | true |
Response parameters
Parameter | Type | Description |
---|---|---|
ticket | string | The ticket. |
expire_time | number | The expiration time. |
getMediaUrl
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
file_type | number | The file type. Valid values:
|
true |
Response parameters
Parameter | Type | Description |
---|---|---|
file_url | string | The full path of the cover image. |
file_key | string | The file decryption key. |
bucket | string | The full path of the cover image. |
file_path | string | The relative path of the file. |
getDecryptUrlByDpData
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
dp_data | sting | The encrypted DP data. | true |
Response parameters
Return a string, which must be base64-decoded.
getProductConfig
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
props | sting | One or multiple property names. If there are multiple property names, separate them with commas (,). If this parameter is left empty, all property names are returned. | true |
Response parameters
Return a value in JSON format.
getCapabilityTag
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | The device ID. | true |
Response parameters
Parameter | Type | Description |
---|---|---|
isHas100w | boolean | Indicates whether the device has the capability to handle videos with a resolution of 1 megapixel. |
isHas200w | boolean | Indicates whether the device has the capability to handle videos with a resolution of 2 megapixels. |
isSpecialDevice
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
device_id | string | Device ID | true |
Response parameters
Boolean
Example
import MsBasicApi from '@ray-js/wechat-ms-basic';
MsBasicApi.isSpecialDevice(device_id)
.then(response => {
console.log(response);
})
.catch(error => console.log(error));
Example
true
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback