Basic Module SDK

Last Updated on : 2024-10-11 02:16:04download

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.

Installation

yarn add @ray-js/wechat-ms-basic
// or
npm install @ray-js/wechat-ms-basic

Query user details

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
  • 0: unknown type
  • 10: administrator
  • 20: common home member
  • 30: member
  • 50: home owner

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
}

Get a key to unlock a door remotely

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.

Unlock a door remotely

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.

Deny a remote unlocking request

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.

Get the latest DPs of a device

getLastDpCache

Request parameters

Parameter Type Description Required
device_id string The device ID. true

Response parameters

Return DPs in JSON format.

Get the hardware type of a device

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.

Query the most recent data reported by DP 212

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.

Get the URL of the encrypted first frame

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);

Get the streaming URL of a live video

getLockMediaStream

Request parameters

Parameter Type Description Required
device_id string The device ID. true

Response parameters

Parameter Type Description
url string The streaming URL.

Get the angle of rotation

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.

Get the skill

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

Get the RTC configuration

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.

Get a ticket

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.

Get the cover image of the most recent remote unlocking or alert

getMediaUrl

Request parameters

Parameter Type Description Required
device_id string The device ID. true
file_type number The file type. Valid values:
  • 1: remote unlocking
  • 2: alert
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.

Get the URL of the decrypted DP data

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.

Get the NG backend configuration

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.

Check whether a device has advanced capabilities

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.