This topic describes the processes and APIs of developing smart lock in the Cloud Development Platform. The smart lock cloud development applies to lock-related service implementation through customers’ self-built server, including but not limited to the WeChat mini program, Web system, and H5 application.
Before connecting to lock products of the vertical resources, you need to register as a developer in the Tuya Cloud Development Platform. For more information, see Quick Start.
The process of Tuya smart lock cloud development is shown as follows:
Communication protocol | Applicable lock category |
---|---|
Wi-Fi | Wi-Fi residential lock pro, Wi-Fi residential lock, and Wi-Fi safe. |
BLE | Bluetooth lock, including Bluetooth lock with gateway function. |
Zigbee | Zigbee residential lock pro and Zigbee residential lock. |
You can query interface call logs of the last seven days from the current date. You provide the interface request parameters and submit a ticket in the IoT Console. Generally, Tuya service team will respond to your ticket within two hours. For urgent problems, you can contact the project manager to speed up the process through offline channels.
The following table lists the APIs used by smart locks:
Request method | API | Description |
---|---|---|
POST | /v1.0/devices/{device_id}/door-lock/password-ticket | Get the temporary key for password encryption. |
GET | /v1.0/devices/{device_id}/door-lock/temp-password | Create a temporary password, and support a periodic password. |
POST | /v2.0/devices/{device_id}/door-lock/temp-password | Create an unnamed temporary password, and support a periodic password. |
POST | /v1.0/devices/{device_id}/door-lock/issue-password | Synchronize password. |
GET | /v1.0/devices/{device_id}/door-lock/temp-password/{password_id} | Get temporary password information. |
GET | /v1.0/devices/{device_id}/door-lock/temp-passwords | Get temporary password list. |
PUT | /v1.0/devices/{device_id}/door-lock/temp-passwords/{password_id}/modify-password | Modify temporary password. |
PUT | /v1.0/devices/{device_id}/door-lock/temp-passwords/{password_id}/freeze-password | Freeze temporary password. |
PUT | /v1.0/devices/{device_id}/door-lock/temp-passwords/{password_id}/unfreeze-password | Unfreeze temporary password. |
DELETE | /v1.0/devices/{device_id}/door-lock/temp-passwords/{password_id} | Delete temporary password. |
POST | /v1.0/devices/vdevo153459260090544/door-lock/offline-temp-password | Get offline password. |
GET | /v1.0/devices/{device_id}/door-lock/dynamic-password | Get dynamic password. |
POST | /v1.0/devices/{device_id}/user | Add device members (non-home members). |
PUT | /v1.0/devices/{device_id}/users/{user_id} | Modify device members (non-home members). |
DELETE | /v1.0/devices/{device_id}/users/{user_id} | Delete device members (non-home members). |
GET | /v1.0/devices/{device_id}/users/{user_id} | Query device member information (non-home members). |
GET | /v1.0/devices/{device_id}/users | Query member information list by the device ID (non-home members). |
POST | /v1.0/devices/{device_id}/device-lock/users/{user_id}/allocate | Assign the password to device members (non-home members). |
GET | /v1.0/devices/{device_id}/door-lock/user-types/{user_type}/users/{user_id}/assigned-keys | Get the list of unlocking methods that are bound to lock members (home members). |
GET | /v1.0/devices/{device_id}/door-lock/unassigned-keys | Get the list of unlocking methods that are not bound to lock members (home members). |
PUT | /v1.0/devices/{device_id}/door-lock/actions/entry | Enroll unlocking methods (home members). |
DELETE | /v1.0/devices/{device_id}/door-lock/user-types/{user_type}/users/{user_id}/unlock-types/{unlock_type}/keys/{unlock_no} | Delete unlocking methods (home members). |
PUT | /v1.0/devices/{device_id}/door-lock/unlock-types/{unlock_type}/actions/cancel | Cancel unlocking method enrollment (home members). |
/v1.0/devices/{device_id}/door-lock/unlock-types/{unlock_type}/keys/{unlock_no}/hijack | Set to anti-hijack unlocking (home members). | |
GET | /v1.0/devices/{device_id}/door-lock/open-logs | Query unlocking history. |
*GET | /v1.1/devices/{device_id}/door-lock/open-logs | Query unlocking history. |
GET | /v1.1/devices/{device_id}/door-lock/alarm-logs | Query unlock alarm history. |
GET | /v1.0/devices/{device_id} | Get device information. You get the local key to encrypt and decrypt the password. |
POST | /v1.0/devices/{device_id}/door-lock/issue-password | Get the password for device information synchronization. |
GET | /v1.0/devices/{device_id}/door-lock/media/url | Get the alarm image and video url in real time. |
GET | /v1.0/devices/{device_id}/door-lock/latest/media/url | Get the latest unlocking or alarm image. |
Description: APIs marked with an asterisk (*) only support the old version.
For more information, see the following documentation.
Documentation | Applicable function |
---|---|
Standard Command Set for Smart Lock | Lock settings, such as volume and language. |
Device Control | Get the command set of device. |
Error Code | View the global error codes that might be generated during function development. |
Note: In consideration of security, remote unlocking is not available. If you need this unlocking method, contact the responsible project manager to apply for relevant APIs.
Wi-Fi lock working flow:
Zigbee lock working flow:
Normal working flow of Zigbee lock:
Abnormal working flow of Zigbee lock:
Flowchart
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
POST /v1.0/devices/{device_id}/door-lock/password-ticket
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
Request example
POST /v1.0/devices/vdevo153459260090544/door-lock/password-ticket
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Temporary password information. |
Description of result
Parameter | Type | Description |
---|---|---|
ticket_id | String | Temporary key ID |
ticket_key | String | The temporary key can be used after performing AES decryption based on the cloud developer’s accessKey. |
expire_time | Long | Time available |
Return example of successful request
{
"result": {
"expire_time": 360,
"ticket_id": "9wxxoLM",
"ticket_key": "901CC35A67DA3429C38E9622xxxxx3EAE1CE333462356D257FD1D3E5C"
},
"success": true,
"t": 1592899848757
}
Return example of failed request
{
"success": false,
"code": 500, // Error code. For more information, see the error code documentation
"msg": "system error,please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
POST /v1.0/devices/{device_id}/door-lock/temp-password
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
name | String | BODY | Temporary password name | Yes |
password | String | BODY | The original password length of the Wi-Fi lock is seven, and that of the Zigbee lock and Bluetooth lock is six. AES-128/ECB/PKCS7Padding encryption algorithm is used in secure password transmission. The key is the original ticket_key after AES decryption based on the cloud developer’s accessKey. | Yes |
effective_time | Long | BODY | Valid time, 10-bit timestamp in seconds. | Yes |
invalid_time | Long | BODY | Invalid time, 10-bit timestamp in seconds. | Yes |
password_type | String | BODY | Password encryption type: ticket | Yes |
ticket_id | String | BODY | Temporary key ID | Yes |
phone | String | BODY | Mobile number | No |
type | Integer | BODY | Valid type of door lock password. 1 : one-time valid. 0 : always valid within the valid time. |
Required for Zigbee lock |
time_zone | String | BODY | Time zone. This field must be filled in if you use the periodic password function. | No |
schedule_list | List | BODY | The parameter list of periodic function | No |
schedule_list
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
effective_time | Long | BODY | Valid time on the current day, in minutes. | Yes |
invalid_time | Long | BODY | Invalid time on the current day, in minutes. | Yes |
working_day | Int | BODY | A week is represented by one byte. Bit0 to bit6 respectively represent Sunday to Saturday. | Yes |
Request example
POST /v1.0/devices/vdevo153459260090544/door-lock/temp-password
{
"password": "956FAD7xxxxxx09C68E168B77",
"password_type": "ticket",
"ticket_id": "xxxxxx",
"effective_time": 1579156726,
"invalid_time": 1579243126,
"name":"test",
"phone": 11233213,
"time_zone":"",
"schedule_list":[{
"effective_time": 720,
"invalid_time": 1080,
"working_day": 0
}]
}
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Temporary password information. |
Description of result
Parameter | Type | Description |
---|---|---|
id | Long | Temporary password number |
Return example of successful request
{
"success": true,
"t": 1542626129429,
"result": {
"id": 124367346
}
}
Return example of failed request
{
"success": false,
"code": 500, // Error code. For more information, see the error code documentation
"msg": "system error,please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
POST /v2.0/devices/{device_id}/door-lock/temp-password
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
password | String | BODY | The original password length of the Wi-Fi lock is seven, and that of the Zigbee lock and Bluetooth lock is six. AES-128/ECB/PKCS7Padding encryption algorithm is used in secure password transfer. The key is the original ticket_key after AES decryption based on the cloud developer’s accessKey. | Yes |
effective_time | Long | BODY | Valid time, 10-bit timestamp in seconds. | Yes |
invalid_time | Long | BODY | Invalid time, 10-bit timestamp in seconds. | Yes |
password_type | String | BODY | Password encryption type: ticket | Yes |
ticket_id | String | BODY | Temporary key ID | Yes |
phone | String | BODY | Mobile number | No |
type | Integer | BODY | Valid type of door lock password. 1 : one-time valid. 0 : always valid within the valid time. |
Required for Zigbee lock |
time_zone | String | BODY | Time zone. This field must be filled in if you use the periodic password function. | No |
schedule_list | List | BODY | The parameter list of periodic function | No |
schedule_list
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
effective_time | Long | BODY | Valid time on the current day, in minutes. | Yes |
invalid_time | Long | BODY | Invalid time on the current day, in minutes. | Yes |
working_day | Int | BODY | A week is represented by one byte. Bit0 to bit6 respectively represent Sunday to Saturday. | Yes |
Request example
POST /v2.0/devices/vdevo153459260090544/door-lock/temp-password
{
"password": "956FAD7xxxxxx09C68E168B77",
"password_type": "ticket",
"ticket_id": "xxxxxx",
"effective_time": 1579156726,
"invalid_time": 1579243126,
"phone": 11233213,
"time_zone":"",
"schedule_list":[{
"effective_time": 720,
"invalid_time": 1080,
"working_day": 0
}]
}
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Temporary password information. |
Description of result
Parameter | Type | Description |
---|---|---|
id | Long | Temporary password number |
Return example of successful request
{
"success": true,
"t": 1542626129429,
"result": {
"id": 124367346
}
}
Return example of failed request
{
"success": false,
"code": 500, // Error code. For more information, see the error code documentation
"msg": "system error,please contact the admin"
}
Applicable lock types
It applies to Zigbee lock.
After a password is created for the Zigbee lock, if the password status is still in “configuring”, this interface can be called to synchronize the “configuring” password in the server to the lock. For a single device, this interface can only be sent once within 60 seconds.
Interface address
POST /v1.0/devices/{device_id}/door-lock/issue-password
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
password_id | Long | BODY | Password ID. If it is left empty, all the passwords currently in configuring will be sent to the lock. | No |
Request example
POST /v1.0/devices/vdevo153459260090544/door-lock/issue-password
{
"password_id":""
}
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Boolean | Return result. |
Return example of successful request
{
"success": true,
"t": 1542626129429,
"result": true
}
Return example of failed request
{
"success": false,
"code": 500, // Error code. For more information, see the error code documentation
"msg": "system error,please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
GET /v1.0/devices/{device_id}/door-lock/temp-password/{password_id}
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
password_id | Long | URI | Password number | Yes |
Request example
GET /v1.0/devices/vdevo153459260090544/door-lock/temp-password/xxxx
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Temporary password information. |
Description of result
Parameter | Type | Description |
---|---|---|
password_id | Long | Temporary password number |
name | String | Temporary password name |
phase | Integer | Password status |
effective_time | Long | Valid time, 10-bit timestamp |
invalid_time | Long | Invalid time, 10-bit timestamp |
phone | String | Mobile number |
time_zone | String | Time zone |
delivery_status | Integer | Operation status. 1: in configuring 2: configuration succeeded 3: configuration failed 4: repeated password 5: password is full 6: valid time overlap. Return result for Zigbee lock |
schedule_list | List | The parameter list of periodic function |
schedule_list
Parameter | Type | Description |
---|---|---|
effective_time | Long | Valid time on the current day, in minutes. |
invalid_time | Long | Invalid time on the current day, in minutes. |
working_day | Int | A week is represented by one byte. Bit0 to bit6 respectively represent Sunday to Saturday. |
Phase description
Zigbee: 1: to be created. 2: normal. 3: frozen. 4: deleted. 5: creation failed. Wi-Fi: 0: deleted. 1: to be sent. 2: sent. 3: to be deleted. Bluetooth: 0: deleted. 1: to be sent. 2: sent. 3: to be deleted. 7: sent failed.
Return example of successful request
{
"success": true,
"t": 1542626129429,
"result": {
"password_id": 1001, //Primary key of the temporary password
"effective_time": 1530841779, //10-bit valid time
"invalid_time": 1530881779, //10-bit invalid time
"name": "Tenant A's password", //Temporary password name
"phase": 1, //Password status
"phone": "123547127362",
"time_zone":"Asia/Shanghai",
"delivery_status": 1
}
}
Return example of failed request
{
"success": false,
"code": 500, // Error code. For more information, see the error code documentation
"msg": "system error, please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
GET /v1.0/devices/{device_id}/door-lock/temp-passwords
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
Request example
GET /v1.0/devices/vdevo153459260090544/door-lock/temp-passwords
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Delete password information. |
Description of result
Parameter | Type | Description |
---|---|---|
password_id | Long | Temporary password number |
name | String | Temporary password name |
phase | Integer | Password status |
effective_time | Long | Valid time, 10-bit timestamp |
invalid_time | Long | Invalid time, 10-bit timestamp |
phone | String | Mobile number |
time_zone | String | Time zone |
delivery_status | Integer | Operation status. 1: in configuring 2: configuration succeeded 3: configuration failed 4: repeated password 5: password is full 6: valid time overlap. Return result for Zigbee lock |
schedule_list | List | The parameter list of periodic function |
schedule_list
Parameter | Type | Description |
---|---|---|
effective_time | Long | Valid time on the current day, in minutes. |
invalid_time | Long | Invalid time on the current day, in minutes. |
working_day | Int | A week is represented by one byte. Bit0 to bit6 respectively represent Sunday to Saturday. |
Phase description
Zigbee: 1: to be created. 2: normal. 3: frozen. 4: deleted. 5: creation failed. Wi-Fi: 0: deleted. 1: to be sent. 2: sent. 3: to be deleted. Bluetooth: 0: deleted. 1: to be sent. 2: sent. 3: to be deleted. 7: sent failed.
Return example of successful request
{
"success": true,
"t": 1542626129429,
"result": [
{
"password_id": 1001, //Primary key of the temporary password
"effective_time": 1530841779, //10-bit valid time
"invalid_time": 1530881779, //10-bit invalid time
"name": "Tenant A's password", //Temporary password name
"phase": 1, //Password status
"phone": "123547127362",
"time_zone":"Asia/Shanghai",
"delivery_status": 1
}
]
}
Return example of failed request
{
"success": false,
"code": 500, // Error code. For more information, see the error code documentation
"msg": "System exception. Contact the administrator"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock (password cannot be modified).
Interface address
PUT /v1.0/devices/{device_id}/door-lock/temp-passwords/{password_id}/modify-password
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
password_id | Long | URI | Password ID | Yes |
password | String | BODY | The original password length of the Wi-Fi lock is seven, and that of the Zigbee lock is six. The password of Bluetooth lock cannot be modified. AES-128/ECB/PKCS7Padding encryption algorithm is used in secure password transfer. The key is the original ticket_key after AES decryption based on the cloud developer’s accessKey. | Yes |
effective_time | Long | BODY | Valid time, 10-bit timestamp in seconds. | Yes |
invalid_time | Long | BODY | Invalid time, 10-bit timestamp in seconds. | Yes |
password_type | String | BODY | Password encryption type: ticket | Yes |
ticket_id | String | BODY | Temporary key ID | Yes |
phone | String | BODY | Mobile number | No |
type | Integer | BODY | Valid type of door lock password. 1 : one-time valid. 0 : always valid within the valid time. |
Required for Zigbee lock |
time_zone | String | BODY | Time zone. This field must be filled in if you use the periodic password function. | No |
schedule_list | List | BODY | The parameter list of periodic function | No |
schedule_list
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
effective_time | Long | BODY | Valid time on the current day, in minutes. | Yes |
invalid_time | Long | BODY | Invalid time on the current day, in minutes. | Yes |
working_day | Int | BODY | A week is represented by one byte. Bit0 to bit6 respectively represent Sunday to Saturday. | Yes |
Request example
PUT /v1.0/devices/vdevo153459260090544/door-lock/temp-passwords/{password_id}/modify-password
{
"phone":"",
"effective_time":"",
"invalid_time":"",
"password":"",
"password_type":"ticket",
"ticket_id":"xxx"
}
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Delete password information. |
Return example of successful request
{
"success": true,
"t": 1542626129429,
"result":true
}
Return example of failed request
{
"success": false,
"code": 500, // Error code. For more information, see the error code documentation
"msg": "system error,please contact the admin"
}
Applicable lock types
It applies to Zigbee lock.
Interface address
PUT /v1.0/devices/{device_id}/door-lock/temp-passwords/{password_id}/freeze-password
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
password_id | String | URI | Password ID | Yes |
Request example
PUT /v1.0/devices/vdevo153459260090544/door-lock/temp-passwords/xxx/freeze-password
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Delete password information. |
Return example of successful request
{
"success": true,
"t": 1542626129429,
"result":true
}
Return example of failed request
{
"success": false,
"code": 500, // Error code. For more information, see the error code documentation
"msg": "system error, please contact the admin"
}
Applicable lock types
It applies to Zigbee lock.
Interface address
PUT /v1.0/devices/{device_id}/door-lock/temp-passwords/{password_id}/unfreeze-password
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
password_id | String | URI | Password ID | Yes |
Request example
PUT /v1.0/devices/vdevo153459260090544/door-lock/temp-passwords/xxx/unfreeze-password
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Delete password information. |
Return example of successful request
{
"success": true,
"t": 1542626129429,
"result":true
}
Return example of failed request
{
"success": false,
"code": 500, // Error code. For more information, see the error code documentation
"msg": "system error, please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
DELETE /v1.0/devices/{device_id}/door-lock/temp-passwords/{password_id}
Request parameter
Parameter | Type | Parameter type | Description | Yes |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
password_id | String | URI | Password ID | Yes |
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Boolean | Return result |
Return example of successful request
{
"success": true,
"t": 1542626129429,
"result": true
}
Return example of failed request
{
"success": false,
"code": 500, // Error code. For more information, see the error code documentation
"msg": "system error, please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
GET /v1.0/devices/{device_id}/door-lock/dynamic-password
Request parameter
Parameter | Type | Parameter type | Description | Yes |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
Request example
GET /v1.0/devices/vdevo153459260090544/door-lock/dynamic-password
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Dynamic password information |
Description of result
Parameter | Type | Description |
---|---|---|
dynamic_password | String | Dynamic password |
Return example of successful request
{
"success": true,
"t": 1542626129429,
"result": {
"dynamic_password": ""
}
}
Return example of failed request
{
"success": false,
"code": 500, // Error code. For more information, see the error code documentation
"msg": "system error, please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock.
Interface address
POST /v1.0/devices/{device_id}/door-lock/offline-temp-password
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
effective_time | Long | BODY | Valid time, 10-bit timestamp | Yes |
invalid_time | Long | BODY | Invalid time, 10-bit timestamp | Yes |
name | String | BODY | Offline temporary password name | No |
type | Int | BODY | Password type: 0: multiple uses. 1: single use. 9: clear all passwords (return to single-use password). |
Yes |
lang | String | BODY | Language | Yes |
Request example
POST /v1.0/devices/vdevo153459260090544/door-lock/offline-temp-password
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Dynamic password information |
Description of result
Parameter | Type | Description |
---|---|---|
offline_temp_password | String | Offline temporary password |
Return example of successful request
{
"success": true,
"t": 1542626129429,
"result": {
"offline_temp_password": ""
}
}
Return example of failed request
{
"success": false,
"code": 500, // Error code. For more information, see the error code documentation
"msg": "system error, please contact the admin"
}
Note: This API only supports the old version.
Applicable lock types
It applies to Wi-Fi lock and Zigbee lock.
Interface address
GET /v1.0/devices/{device_id}/door-lock/open-logs
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
page_no | Integer | URL | Page number | Yes |
page_size | Integer | URL | Page size | Yes |
start_time | Long | URL | Start time | Yes |
end_time | Long | URL | End time | Yes |
Request example
GET /v1.0/devices/vdevo153459260090544/door-lock/open-logs? page_no=1&page_size=20&start_time=1543213146&end_time=1543213546
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Return result. |
Description of result
Parameter | Type | Description |
---|---|---|
total | Integer | The number of histories |
logs | List | List of unlocking history |
Description of logs
Parameter | Type | Description |
---|---|---|
status | List | List of lock status |
update_time | Long | Status changing time |
unlock_name | String | Unlock method name |
user_id | String | Member id |
nick_name | String | Member name |
Description of status
Parameter | Type | Description |
---|---|---|
code | String | Status code |
value | Object | Status value |
Description of status code
Parameter | Type | Description |
---|---|---|
unlock_finger | Long | Unlock with a fingerprint. The number assigned locally by the lock. |
unlock_password | Long | Unlock with a password. The number assigned locally by the lock. |
unlock_temporary | Long | Unlock with a temporary password, and the value is password ID. |
unlock_dynamic | Long | Unlock with a dynamic password, and the value is password ID. |
unlock_card | Long | Unlock with a card. The number assigned locally by the lock. |
unlock_face | Long | Unlock with face recognition. The number assigned locally by the lock. |
unlock_key | Long | Unlock with a mechanical key. The number assigned locally by the lock. |
Return example of successful request
{
"success":true,
"t":1542626129429,
"result":{
"total":1,
"logs":[
{
"status":{
"code":"unlock_finger",
"value":"123456"
},
"nick_name":"",
"unlock_name":"",
"update_time":1612098422000,
"user_id":"0"
}
]
}
}
Return example of failed request
{
"success": false,
"code": 500, // Error code. For more information, see the error code documentation
"msg": "system error, please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock and Zigbee lock.
Interface address
GET /v1.1/devices/{device_id}/door-lock/open-logs
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
page_no | Integer | URL | Page number | Yes |
page_size | Integer | URL | Page size | Yes |
start_time | Long | URL | Start time | Yes |
end_time | Long | URL | End time | Yes |
show_media_infos | Boolean | URL | whether to show media info or not | No |
Request example
GET /v1.1/devices/6cdb36b2e489885fa57lzm/door-lock/open-logs?page_no=1&page_size=3&start_time=1553053133000&end_time=1614008938000&show_media_info=true
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Return result. |
Description of result
Parameter | Type | Description |
---|---|---|
total | Integer | The number of histories |
logs | List | List of unlocking history |
Description of logs
Parameter | Type | Description |
---|---|---|
status | List | List of lock status |
update_time | Long | Status changing time |
unlock_name | String | Unlock method name |
user_id | String | Member id |
nick_name | String | Member name |
media_infos | List | media info |
Description of media_infos
Parameter | Type | Description |
---|---|---|
file_url | String | Full path of cover map |
file_key | String | file key |
media_url | String | media url |
media_key | String | media key |
Description of status
Parameter | Type | Description |
---|---|---|
code | String | Status code |
value | Object | Status value |
Description of status code
Parameter | Type | Description |
---|---|---|
unlock_finger | Long | Unlock with a fingerprint. The number assigned locally by the lock. |
unlock_password | Long | Unlock with a password. The number assigned locally by the lock. |
unlock_temporary | Long | Unlock with a temporary password, and the value is password ID. |
unlock_dynamic | Long | Unlock with a dynamic password, and the value is password ID. |
unlock_card | Long | Unlock with a card. The number assigned locally by the lock. |
unlock_face | Long | Unlock with face recognition. The number assigned locally by the lock. |
unlock_key | Long | Unlock with a mechanical key. The number assigned locally by the lock. |
Return example of successful request
{
"result": {
"logs": [
{
"media_infos": [
{
"file_key": "uwu5m7kvj45av47g",
"file_url": "https://..."
}
],
"nick_name": "",
"status": {
"code": "unlock_app",
"value": "0"
},
"unlock_name": "",
"update_time": 1613978384000,
"user_id": "0"
}
],
"total": 1
},
"success": true,
"t": 1614063791358
}
Return example of failed request
{
"success": false,
"code": 500,
"msg": "system error, please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock and Zigbee lock.
Interface address
GET /v1.1/devices/{device_id}/door-lock/alarm-logs
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
page_no | Integer | URL | Page no | Yes |
page_size | Integer | URL | Page size | Yes |
dp_codes | String | URL | Alarm function standard function code, separated by half-width commas (,), query general alarms by default | No |
show_media_info | Boolean | URL | Whether to show media or not | No |
Request example
GET /v1.1/devices/6ca87475b5bfbaa716felz/door-lock/alarm-logs?page_size=20&codes=doorbell&showMediaInfo=true&page_no=1
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Return result. |
Description of result
Parameter | Type | Description |
---|---|---|
total | Integer | The number of histories |
logs | List | List of unlocking history |
Description of logs
Parameter | Type | Description |
---|---|---|
status | List | List of lock status |
update_time | Long | Status changing time |
unlock_name | String | Unlock method name |
user_id | String | Member id |
nick_name | String | Member name |
media_infos | List | media info |
Description of media_infos
Parameter | Type | Description |
---|---|---|
file_url | String | Full path of cover map |
file_key | String | file key |
media_url | String | media url |
media_key | String | media key |
Description of status
Parameter | Type | Description |
---|---|---|
code | String | Status code |
value | Object | Status value |
Description of status code
Parameter | Type | Description |
---|---|---|
unlock_finger | Long | Unlock with a fingerprint. The number assigned locally by the lock. |
unlock_password | Long | Unlock with a password. The number assigned locally by the lock. |
unlock_temporary | Long | Unlock with a temporary password, and the value is password ID. |
unlock_dynamic | Long | Unlock with a dynamic password, and the value is password ID. |
unlock_card | Long | Unlock with a card. The number assigned locally by the lock. |
unlock_face | Long | Unlock with face recognition. The number assigned locally by the lock. |
unlock_key | Long | Unlock with a mechanical key. The number assigned locally by the lock. |
Return example of successful request
{
"result": {
"records": [
{
"media_infos": [
{
"file_key": "jxmgqs59gfr899qe",
"file_url": "https://ty-cn-storage60-1254153901.cos.tuyacn.com/"
}
],
"nick_name": "",
"status": [
{
"code": "alarm_lock",
"value": "wrong_password"
}
],
"update_time": 1613979671000
}
],
"total": 1
},
"success": true,
"t": 1614152402757
}
Return example of failed request
{
"success": false,
"code": 500,
"msg": "system error, please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
POST /v1.0/devices/{device_id}/user
Request parameter
Parameter | Parameter type | Description | Required |
---|---|---|---|
device_id | String | Device ID | Yes |
nick_name | String | User name | Yes |
sex | Integer | Gender1 : male 2 : female |
Yes |
birthday | Long | Date of birth (day, month, year) | No |
height | Integer | Height (cm) | No |
weight | Integer | Weight (g) | No |
contact | String | Contact info | No |
Response parameter
Name | Type | Description |
---|---|---|
t | Long | Return time |
success | Boolean | Success or not |
result | Object | Return result |
Description of result parameter
Name | Type | Description |
---|---|---|
user_id | String | The added user ID |
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
PUT /v1.0/devices/{device_id}/users/{user_id}
Request parameter
Parameter | Parameter type | Description | Required |
---|---|---|---|
device_id | String | Device ID | Yes |
user_id | String | The added user ID | Yes |
nick_name | String | User name | Yes |
sex | Integer | Gender1 : male 2 : female |
Yes |
birthday | Long | Date of birth (day, month, year) | No |
height | Integer | Height (cm) | No |
weight | Integer | Weight (g) | No |
Response parameter
Name | Type | Description |
---|---|---|
t | Long | Timestamp |
success | Boolean | Success or not |
result | Object | Return result |
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
DELETE /v1.0/devices/{device_id}/users/{user_id}
Request parameter
Parameter | Parameter type | Description | Required |
---|---|---|---|
device_id | String | Device ID | Yes |
user_id | String | User ID | Yes |
Response parameter
Name | Type | Description |
---|---|---|
t | Long | Timestamp |
success | Boolean | Success or not |
result | Object | Return result |
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
GET /v1.0/devices/{device_id}/users/{user_id}
Request parameter
Parameter | Parameter type | Description | Required |
---|---|---|---|
device_id | String | Device ID | Yes |
user_id | String | User ID | Yes |
Response parameter
Parameter | Parameter type | Description |
---|---|---|
device_id | String | Device ID |
nick_name | String | User name |
sex | Integer | Gender1 : male 2 : female |
birthday | Long | Date of birth (day, month, year) |
height | Integer | Height (cm) |
weight | Integer | Weight (g) |
contact | String | Contact info |
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
GET /v1.0/devices/{device_id}/users
Request parameter
Parameter | Parameter type | Description | Required |
---|---|---|---|
device_id | String | Device ID | Yes |
Response parameter
Parameter | Parameter type | Description |
---|---|---|
device_id | String | Device ID |
nick_name | String | User name |
sex | Integer | Gender1 : male 2 : female |
birthday | Long | Date of birth (day, month, year) |
height | Integer | Height (cm) |
weight | Integer | Weight (g) |
contact | String | Contact info |
Applicable lock types
|
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Request address
POST /v1.0/devices/{device_id}/device-lock/users/{user_id}/allocate
Request parameter
Parameter | Type | Description | Required |
---|---|---|---|
device_id | String | Device ID | Yes |
user_id | String | Device member ID | Yes |
No | String | Lock number | Yes |
type | String | Password type (fingerprint/password/card) | Yes |
Response parameter
Parameter | Type | Description |
---|---|---|
result | Boolean | Action result |
Example of successful response
{
"success": true,
"t": 1571898808491,
"result": true
}
Flowchart
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
GET /v1.0/devices/{device_id}/door-lock/user-types/{user_type}/users/{user_id}/assigned-keys
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
user_type | Integer | URI | Member type: 1 : home member 2 : non-home member |
Yes |
user_id | String | URI | Member ID | Yes |
unlock_type | String | URL | Unlocking type (fingerprint/password/card) | No |
Request example
GET /v1.0/devices/xxx/door-lock/user-types/2/users/xxx/assigned-keys? unlock_type=card
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Unlocking method information |
Description of result
Parameter | Type | Description |
---|---|---|
unlock_keys | List | List of unlocking method |
unlock_keys description
Parameter | Type | Description |
---|---|---|
unlock_no | Integer | Unlocking method ID (the flag bit of the key on the lock such as password, fingerprint, and card). |
unlock_type | String | Unlocking type (fingerprint/password/card) |
hijack | Boolean | Whether it is anti-hijack unlocking. |
Return example of successful request
{
"result":{
"unlock_keys":[
{
"unlock_no":3,
"unlock_type":"card",
"hijack":false
}
]
},
"success":true,
"t":1593843316481
}
Return example of failed request
{
"success":false,
"code":500, // Error code. For more information, see the error code documentation
"msg":"system error,please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
GET /v1.0/devices/{device_id}/door-lock/unassigned-keys
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
unlock_type | String | URL | Unlocking type (fingerprint/password/card) | No |
Request example
GET /v1.0/devices/xxxx/door-lock/unassigned-keys? unlock_type=card
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Unlocking method information |
Description of result
Parameter | Type | Description |
---|---|---|
unlock_keys | List | List of unlocking method |
unlock_keys description
Parameter | Type | Description |
---|---|---|
unlock_no | Integer | Unlocking method ID (the flag bit of the key on the lock such as password, fingerprint, and card). |
unlock_type | String | Unlocking type (fingerprint/password/card) |
Return example of successful request
{
"result":{
"unlock_keys":[
{
"unlock_no":3,
"unlock_type":"card"
}
]
},
"success":true,
"t":1593843316481
}
Return example of failed request
{
"success":false,
"code":500, // Error code. For more information, see the error code documentation
"msg":"system error,please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
PUT /v1.0/devices/{device_id}/door-lock/actions/entry
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
user_id | String | BODY | Member ID | Yes |
user_type | Integer | BODY | Member type:1 : home member 2 : non-home member |
Yes |
unlock_type | String | BODY | Unlocking method type | Yes |
password_type | String | BODY | Password encryption type: ticket (It is valid only if unlock_type is password and it is a Bluetooth lock.) | No |
ticket_id | String | BODY | Temporary key ID for password encryption (It is valid only if unlock_type is password and it is a Bluetooth lock.) | No |
password | String | BODY | Password (It is valid only if unlock_type is password and it is a Bluetooth lock.) | No |
Request example
PUT /v1.0/devices/xxx/door-lock/actions/entry
{
"unlock_type":"card",
"user_type":2,
"user_id":"000xxxwsn"
}
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | It indicates if the operation is successful. true : succeeded false : failed |
Return example of successful request
{
"result":true,
"success":true,
"t":1593843316481
}
Return example of failed request
{
"success":false,
"code":500, // Error code. For more information, see the error code documentation
"msg":"system error,please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
DELETE /v1.0/devices/{device_id}/door-lock/user-types/{user_type}/users/{user_id}/unlock-types/{unlock_type}/keys/{unlock_no}
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
user_type | Integer | URI | Member type: 1 : home member 2 : non-home member |
Yes |
user_id | String | URI | Member ID | Yes |
unlock_type | String | URI | Unlocking type (fingerprint/password/card) | Yes |
unlock_no | Integer | URI | Unlocking method ID (the flag bit of the key on the lock such as password, fingerprint, and card). | Yes |
Request example
DELETE /v1.0/devices/xxxx/door-lock/user-types/2/users/xxxx/unlock-types/fingerprint/keys/30
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | It indicates if the operation is successful. true : succeeded false : failed |
Return example of successful request
{
"result":true,
"success":true,
"t":1593843316481
}
Return example of failed request
{
"success":false,
"code":500, // Error code. For more information, see the error code documentation
"msg":"system error,please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
PUT /v1.0/devices/{device_id}/door-lock/unlock-types/{unlock_type}/actions/cancel
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
unlock_type | String | URI | Unlocking type (fingerprint/password/card) | Yes |
Request example
PUT /v1.0/devices/xxx/door-lock/unlock-types/card/actions/cancel
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | It indicates if the operation is successful. true : succeeded false : failed |
Return example of successful request
{
"result":true,
"success":true,
"t":1593843316481
}
Return example of failed request
{
"success":false,
"code":500, // Error code. For more information, see the error code documentation
"msg":"system error,please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Interface address
PUT /v1.0/devices/{device_id}/door-lock/unlock-types/{unlock_type}/keys/{unlock_no}/hijack
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
unlock_type | String | URI | Unlocking type (fingerprint/password/card) | Yes |
unlock_no | Integer | URI | Unlocking method ID (the flag bit of the key on the lock such as password, fingerprint, and card). | Yes |
Request example
PUT /v1.0/devices/xxx/door-lock/unlock-types/card/keys/130/hijack
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | It indicates if the operation is successful. true : succeeded false : failed |
Return example of successful request
{
"result":true,
"success":true,
"t":1593843316481
}
Return example of failed request
{
"success":false,
"code":500, // Error code. For more information, see the error code documentation
"msg":"system error,please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock, Zigbee lock, and Bluetooth lock.
Service data
Parameter | Type | Description |
---|---|---|
bizCode | String | Event type code |
devId | String | Device ID |
uuid | Integer | Device UUID |
bizData | Object | Unlocking method status |
ts | Long | Timestamp |
bizCode description
bizCode | Description |
---|---|
doorUnlockMethodStatus | Unlocking method status |
bizData description
code | Data type | Description |
---|---|---|
finish | Boolean | Whether the enrollment is completed |
operate | Integer | Operation. 1 : initiate operation. 2 : cancel operation. |
raised | Boolean | Whether it is initiated. |
totalPeriod | Integer | The total number of enrollments, which will be pushed separately and only once. |
period | Integer | The number of remaining enrollments. |
event | String | Event (unlockMethodEntry/unlockMethodDelete) |
Data format
{
"bizCode":"doorUnlockMethodStatus",
"bizData":{
"finish":false,
"operate":1,
"raised":true,
"totalPeriod":2,
"period":2,
"event":"unlockMethodEntry"
},
"uuid":"xxxx",
"devId":"xxxx"
}
Remote door unlock with snapshot picture process:
Remote door unlock with snapped pictures-real-time scene
- The user triggers the camera lock to open the door, and the door lock
captures the picture and reports it to the cloud service
- Cloud service stores image data and pushes relative storage location information to the client
- The client calls the cloud service to obtain the full path of image storage
- The client obtains the encrypted image data and decrypts it
- According to the obtained image information, the user judges to open the door or cancel, and call the corresponding interface
- The cloud service is issued to the camera lock, and the door is opened/cancelled
Remote door unlock with snapped pictures(non-real-time scene)
- The client calls the cloud service to query the image information of the most recent door opening/warning within 90s
- The client obtains the encrypted image data and decrypts it
- According to the obtained image information, the user judges to open the door or cancel, and call the corresponding interface
- The cloud service is issued to the camera lock, and the door is opened/cancelled
Image information is encrypted by AES/CBC/PKCS5Padding,The rules are as follows:
4 | 16 | 44 | Video |
---|---|---|---|
Placeholder | iv | Placeholder | Video |
The decryption demo is shown below:
package xxxxxxx;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Random;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class EncryptUtils {
private static final String DEFAULT_ALGORITHM = "AES";
private static final String DEFAULT_FULL_ALGORITHM = "AES/CBC/PKCS5Padding";
public static File encryptFile(String key, File originFile, String destPath) {
FileInputStream in = null;
FileOutputStream out = null;
File destFile = null;
try {
destFile = new File(destPath);
if (originFile.exists() && originFile.isFile()) {
if (!destFile.getParentFile().exists()) {
destFile.getParentFile().mkdirs();
}
destFile.createNewFile();
in = new FileInputStream(originFile);
out = new FileOutputStream(destFile, true);
byte[] iv = getIv();
Cipher cipher = initAESCipher(iv, key, Cipher.ENCRYPT_MODE);
CipherInputStream cipherInputStream = new CipherInputStream(in, cipher);
byte[] cache = new byte[1024];
int nRead;
out.write(new byte[4]);
out.write(iv);
out.write(new byte[4]);
out.write(new byte[40]);
out.flush();
while ((nRead = cipherInputStream.read(cache)) != -1) {
out.write(cache, 0, nRead);
out.flush();
}
cipherInputStream.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return destFile;
}
public static File decryptFile(String key, InputStream in, File destFile) {
FileOutputStream out = null;
try {
if (!destFile.getParentFile().exists()) {
destFile.getParentFile().mkdirs();
}
destFile.createNewFile();
out = new FileOutputStream(destFile);
byte[] iv = new byte[16];
in.skip(4);
int read = in.read(iv);
if (read != 16) {
throw new IOException("iv length error");
}
in.skip(44);
Cipher cipher = initAESCipher(iv, key, Cipher.DECRYPT_MODE);
CipherOutputStream cipherOutputStream = new CipherOutputStream(out, cipher);
byte[] buffer = new byte[1024];
int r;
while ((r = in.read(buffer)) >= 0) {
cipherOutputStream.write(buffer, 0, r);
}
cipherOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return destFile;
}
private static Cipher initAESCipher(byte[] iv, String sKey, int cipherMode) {
try {
IvParameterSpec zeroIv = new IvParameterSpec(iv);
SecretKeySpec key = new SecretKeySpec(sKey.getBytes(), DEFAULT_ALGORITHM);
Cipher cipher = Cipher.getInstance(DEFAULT_FULL_ALGORITHM);
cipher.init(cipherMode, key, zeroIv);
return cipher;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (InvalidAlgorithmParameterException e) {
e.printStackTrace();
}
return null;
}
public static byte[] getIv() {
StringBuilder uid = new StringBuilder();
Random rd = new SecureRandom();
for (int i = 0; i < 16; i++) {
int type = rd.nextInt(3);
switch (type) {
case 0:
uid.append(rd.nextInt(10));
break;
case 1:
uid.append((char) (rd.nextInt(25) + 65));
break;
case 2:
uid.append((char) (rd.nextInt(25) + 97));
break;
default:
break;
}
}
return uid.toString().getBytes();
}
}
Applicable lock types
It applies to Wi-Fi lock and Zigbee lock.
Interface address
GET /v1.0/devices/{device_id}/door-lock/media/url
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
bucket | Integer | URL | Page number | Yes |
file_path | Integer | URL | Page size | Yes |
media_bucket | Long | URL | Start time | Yes |
media_path | Long | URL | End time | Yes |
Request example
GET /v1.0/devices/6cdb36b2e489885fa57lzm/door-lock/media/url?bucket=ty-cn-storage60-1254153901&file_path=/3039e1-3053202d1d483fa63/cmmon/16139779690g
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Return result. |
Description of result
Parameter | Type | Description |
---|---|---|
file_url | String | file url |
media_url | String | media url |
Return example of successful request
{
"result": {
"file_url": "https://...",
"media_url": "https://..."
},
"success": true,
"t": 1614063791358
}
Return example of failed request
{
"success": false,
"code": 500,
"msg": "system error, please contact the admin"
}
Applicable lock types
It applies to Wi-Fi lock and Zigbee lock.
Interface address
GET /v1.0/devices/{device_id}/door-lock/latest/media/url
Request parameter
Parameter | Type | Parameter type | Description | Required |
---|---|---|---|---|
device_id | String | URI | Device ID | Yes |
file_type | Integer | URL | file type 1 remote unlocking 2 alarm | Yes |
Request example
GET /v1.0/devices/6cdb36b2e489885fa57lzm/door-lock/latest/media/url?file_type=1
Return parameter
Parameter | Type | Description |
---|---|---|
code | Integer | It indicates return error codes and is empty on success. |
success | Boolean | It indicates if the operation is successful. true : succeeded false : failed |
t | Long | Response time |
msg | String | The message of a failed request. It is empty on success. |
result | Object | Return result. |
Description of result
Parameter | Type | Description |
---|---|---|
file_url | String | Full path of image |
file_key | String | file key |
bucket | String | bucket |
file_path | String | Relative file path |
Return example of successful request
{
"result": {
"bucket": "ty-cn-storage60-1254153901",
"file_key": "u8kstrtjm7qun83q",
"file_path": "/3039e1-30532026.jpg",
"file_url": "https://ty-cn-storage60-1254153901.cos.tuyacn.com6"
},
"success": true,
"t": 1614147303662
}
Return example of failed request
{
"success": false,
"code": 500,
"msg": "system error, please contact the admin"
}