@soszrg
2018-05-31T10:43:37.000000Z
字数 4538
阅读 579
V3.1
/v3_1/schedule/task/
所有标明jwt认证的接口,需要在请求header中添加Authorization头域,值为:jwt token,如下示例:
Authorization: jwt eyJhbGciOiJ...
| code | 说明 |
|---|---|
| 10100 | token过期 |
| 10101 | token错误 |
POST /v3/schedule/task/
请求参数
| 参数名 | 类型 | 必须 | 说明 |
|---|---|---|---|
| device_id | string | 是 | 设备ID |
| period | string | 是 | 定时任务执行周期 |
| tasks | json array | 是 | 具体的任务信息 |
参数说明
period:
tasks:
[{"hour":"15","minute":"11","commands":"{\"switch\":1}"},{"hour":"17","minute":"13","commands":"{\"switch\":0}"}]
| 字段 | 类型 | 说明 |
|---|
hour | string | 执行时间的小时,比如三点
minute | string | 执行时间的分钟,比如十五分
commands | json string | 要执行的指令
定时任务示例
{"device_id":"7c1544595...","period":"0101010","tasks":[{"hour":"19","minute":"15","commands":"{\"switch\":1}"},{"hour":"22","minute":"30","commands":"{\"switch\":0}"}]}
返回值
{"meta":{"message":"create crontab ok.","code":0},"data":{"tasks":[{"crontab":{"hour":"19","minute":"15",},"commands":"{\"switch\":1}""name":"7f14bcea63..."},{"crontab":{"hour":"22","minute":"30"},"commands":"{\"switch\":0}""name":"7f1853b4632711e8...",}],"period":"1101011","enabled":true,"group_id":"7f1b5a64...","update_time":"2018-05-29 18:03:12","create_time":"2018-05-29 18:03:12"}}
字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| group_id | string | 任务ID(唯一ID)用于更新和获取任务 |
| enabled | bool | 任务是否开启 |
| update_time | string | 更新时间 |
| createtime | string | 创建时间 |
错误码
| 错误码 | 说明 |
|---|---|
| 10000 | 参数错误:参考Response的message字段 |
| 10350 | 用户与设备间没有绑定关系 |
GET /v3/schedule/task/<group_id>/
请求参数
| 参数名 | 类型 | 必须 | 说明 |
|---|---|---|---|
| group_id | string | 是 | 任务ID |
返回值
{"tasks":[{"crontab":{"hour":"15","minute":"11"},"name":"7f14bcea6327...","commands":"{"a":3}"},{"crontab":{"hour":"17","minute":"13"},"name":"7f1853b46327...","commands":"{"a":3}"}],"period":"1101011","enabled":true,"group_id":"7f1b5a64632711...","update_time":"2018-05-29 18:03:12","create_time":"2018-05-29 18:03:12"}
错误码
| 错误码 | 说明 |
|---|---|
| 10000 | 参数错误:参考Response的message字段 |
| 11600 | 找不到任务 |
PUT /v3/schedule/task/<group_id>/
请求参数
| 参数名 | 类型 | 必须 | 说明 |
|---|---|---|---|
| group_id | string | 是 | 任务ID |
| period | string | 是 | 定时任务执行周期 |
| enabled | bool | 是 | 任务的开启状态 |
| tasks | json array | 是 | 具体的任务信息 |
参数说明
period:
tasks:
[{"name": "faazbb...""hour":"15","minute":"11","commands":"{\"switch\":1}"},{"name":"faggzz...""hour":"17","minute":"13","commands":"{\"switch\":0}"}]
| 字段 | 类型 | 说明 |
|---|---|---|
| name | string | 任务名 |
| hour | string | 执行时间的小时,比如三点 |
| minute | string | 执行时间的分钟,比如十五分 |
| commands | json string | 要执行的指令 |
更新定时任务示例
{"period":"0101010","enabled": false"tasks":[{"hour":"20","minute":"15","commands":"{\"switch\":1}"},{"hour":"23","minute":"30","commands":"{\"switch\":0}"}]}
返回值
{"meta":{"message":"task update ok","code":0},"data":{"tasks":[{"crontab":{"hour":"15","minute":"11"},"name":"7f1853b4...","commands":"{"switch":1}"},{"crontab":{"hour":"17","minute":"13"},"name":"7f14bcea632711e...","commands":"{"switch":0}"}],"period":"1101011","enabled":false,"group_id":"7f1b5a64632...","update_time":"2018-05-29 18:03:12","create_time":"2018-05-29 18:03:12"}}
字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| name | string | 任务名称(唯一ID) |
| createtime | string | 创建时间 |
错误码
| 错误码 | 说明 |
|---|---|
| 10000 | 参数错误:参考Response的message字段 |
| 10350 | 用户与设备间没有绑定关系 |
| 11600 | 任务不存在 |
DELETE /v3/schedule/task/<group_id>/
请求参数
| 参数名 | 类型 | 必须 | 说明 |
|---|---|---|---|
| group_id | string | 是 | 任务ID |
返回值
{"meta":{"message":"delete ok.","code":0},"data":{}}
错误码
| 错误码 | 说明 |
|---|---|
| 10000 | 参数错误:参考Response的message字段 |
| 10350 | 用户与设备间没有绑定关系 |
| 11600 | 任务不存在 |
GET /v3/schedule/tasks/
请求参数
| 参数名 | 类型 | 必须 | 说明 |
|---|---|---|---|
| device_id | string | 是 | 设备ID |
返回值
{"meta":{"message":"task list info","code":0},"data":{"count":3,"next":null,"previous":null,"results":[{"tasks":[{"crontab":{"hour":"19","minute":"15"},"name":"ac5f4dbc64b...","commands":"{"switch":1}"},{"crontab":{"hour":"22","minute":"30"},"name":"ac61f1d...","commands":"{"switch":0}"}],"period":"0101010","enabled":true,"group_id":"ac64519a...","update_time":"2018-05-31 18:37:53","create_time":"2018-05-31 18:37:53"},{"tasks":[{"crontab":{"hour":"19","minute":"15"},"name":"abe2148c...","commands":"{"switch":1}"},{"crontab":{"hour":"22","minute":"30"},"name":"abe4a52...","commands":"{"switch":0}"}],"period":"0101010","enabled":true,"group_id":"abe70c94...","update_time":"2018-05-31 18:37:52","create_time":"2018-05-31 18:37:52"},{"tasks":[{"crontab":{"hour":"19","minute":"15"},"name":"ab5264e06...","commands":"{"switch":1}"},{"crontab":{"hour":"22","minute":"30"},"name":"ab5609886...","commands":"{"switch":0}"}],"period":"0101010","enabled":true,"group_id":"ab57e32a...","update_time":"2018-05-31 18:37:51","create_time":"2018-05-31 18:37:51"}]}}
错误码
| 错误码 | 说明 |
|---|---|
| 10000 | 参数错误:参考Response的message字段 |
| 11600 | 找不到任务 |