贝壳物联公开用户接口
一、概述
二、添加第三方应用
三、获取授权码
四、开放资源
1、用户信息 2、设备信息 3、数据接口 4、接口历史数据 5、定时器
五、发送实时消息
六、测试设置参考
为了方便用户自行开发APP或网站对接贝壳物联平台,特开放部分用户权限,包括设备、数据接口、报警、实时通讯等接口。
贝壳物联平台 充分信任 各位开发者的基础上授权采用OAuth2.0的User Credentials授权模式,即用户使用ID和密码直接登录第三方应用,无需显式授权认证,这样降低了开发流程上的难道。但为了 充分保护 用户安全,此处密码非用户登录贝壳物联的密码,是用户在后台获取的用户APIKEY。
在贝壳物联用户中心→个人信息→开发者出点击成为开发者,填写应用信息保存即可获取第三方应用ID(client_id)和密码(client_secret),此信息在获取授权时需用到。
地址:https://www.bigiot.net/oauth/token
请求方式:POST(application/x-www-form-urlencoded)
参数:
{
client_id:"应用ID",
client_secret:"应用密码",
username:"用户ID",
password:"用户apikey",
grant_type:"password"
}示例:
$ curl "https://www.bigiot.net/oauth/token" -d "grant_type=password&client_id=xxxx&client_secret=xxxx&username=x&passwor=xxxx"
请求信息正确返回值:
{"access_token":"219e53e4fea824e7cc86","expires_in":172800,"token_type":"Bearer","scope":null,"refresh_token":"8107bce9803527c448"}access_token——获取网站资源凭证
expires_in——凭证有效时间,单位秒
token_type——凭证类型
scope——备用字段
fresh_token——刷新当前token凭证,可用于延期当前凭证(暂不可用)
请求信息错误返回值:
{"error":"invalid_grant","error_description":"Invalid username and password combination"}不同错误描述部分有所不同。
注意:token有效期为2天,请在本地妥善储存使用,在到期或即将到期时再次获取。不可每次调用接口时就获取一次,或者频繁定期获取。定期获取可以一天一次。同一用户同一应用获取token频率长期超过12小时/次的,将会被停用。
每次请求开放资源时,都需携带在有效期内的access_token。
地址:https://www.bigiot.net/oauth/userinfo
请求方式:GET
参数:
{
access_token:"授权凭证,凭证内部已包含用户ID信息"
}示例:
$ curl https://www.bigiot.net/oauth/userinfo?access_token=xxxxxxxxxxxxx
请求信息正确返回值:
{"uid":"2","nickname":"xxxx","level":"8","score":"534","online":0,"image":"57de7787e3de9_769"}uid——用户ID
nickname——用户名
level——用户等级
score——用户积分
online——在线状态,0:不在线,1:在线
image——头像代码,可用于获取头像
请求信息错误返回值:
{"error":"invalid_grant","error_description":"xxxxxxxxxxxxxx xxxxxxx"}不同错误描述部分有所不同。
头像获取地址:https://www.bigiot.net/userimg/bigiot_xxxx_big.jpg
xxxx替换为image字段的值,bigiot_xxxx_big中的big也可以替换为centre、small,代表图片的三种不同尺寸。
地址:https://www.bigiot.net/oauth/dev
请求方式:GET
参数:
{
access_token:"授权凭证,凭证内部已包含用户ID信息",
id:要查询信息的设备ID,为0时获取用户名下所有设备信息
}示例:
$ curl https://www.bigiot.net/oauth/dev?access_token=xxxxxxxxxxxxx&id=0
请求所有设备信息正确返回值:
[{"id":"2","title":"first dev","description":"my first dev","open":"1","open_listen":"1","online":"0","encrypt":"0","image":"57dcec62826c1_890","lat":"0.0000000","lng":"0.0002000","online_time":"189573"},...]请求单个设备信息正确返回值:
{"id":"2","title":"first dev","description":"my first dev","open":"1","open_listen":"1","online":"0","encrypt":"0","image":"57dcec62826c1_890","lat":"0.0000000","lng":"0.0002000","online_time":"189573"}id——设备ID
title——设备名称
description——设备简介
open——是否公开,0:否,1:是
open_listen——是否公开监听,0:否,1:是
online——是否在线,0:否,1:是
encrypt——是否开启加密登录,0:否,1:是
image——头像代码,可用于获取头像
lat——设备所在经度
lng——设备所在维度
onlinetime——在线时长,单位:秒
请求信息错误返回值:
{"error":"invalid_grant","error_description":"xxxxxxxxxxxxxx xxxxxxx"}不同错误描述部分有所不同。
头像获取地址:https://www.bigiot.net/devimg/bigiot_xxxx_big.jpg
xxxx替换为image字段的值,bigiot_xxxx_big中的big也可以替换为centre、small,代表图片的三种不同尺寸。
地址:https://www.bigiot.net/oauth/myinputs
请求方式:GET
参数:
{
access_token:"授权凭证,凭证内部已包含用户ID信息"
}示例:
$ curl https://www.bigiot.net/oauth/myinputs?access_token=xxxxxxxxxxxxx
请求信息正确返回值:
[{"id":"1","did":"1","title":"\u5f00\u5173","type":"0","unit":"Lux","description":"\u7535\u706f\u5f00\u5173\u72b6\u6001","save":"1","save_interval":"10"},...]id——数据接口ID
did——所属设备ID
title——接口名称
type——接口类型,0:数字量,1:模拟量,2,定位接口,3:图片接口
unit——接口数据单位
description——设备简介
save——是否保存历史数据,0:否,1:是
save_interval——保存历史数据间隔,单位:分钟
请求信息错误返回值:
{"error":"invalid_grant","error_description":"xxxxxxxxxxxxxx xxxxxxx"}不同错误描述部分有所不同。
①获取接口历史数据
地址:https://www.bigiot.net/oauth/historydata
请求方式:GET
参数:
{
access_token:"授权凭证,凭证内部已包含用户ID信息",
id:"要查询的数据接口ID"
}示例:
$ curl https://www.bigiot.net/oauth/historydata?access_token=xxxxxxxxxxxxx&id=xx
请求信息正确返回值:(接口类型不同返回数据有所不同)
[{"value":"1","time":"1"},...]value——数值
time——数据上传时间
请求信息错误返回值:
{"error":"invalid_grant","error_description":"xxxxxxxxxxxxxx xxxxxxx"}不同错误描述部分有所不同。
②清空接口历史数据
地址:https://www.bigiot.net/oauth/delete_history_data
请求方式:POST
参数:
{
access_token:"授权凭证,凭证内部已包含用户ID信息",
id:"要清空数据的接口ID"
}示例:
$ curl "https://www.bigiot.net/oauth/delete_history_data" -d "access_token=xxxxxxxxxxxxx&id=xx"
请求信息正确返回值:
{"status":1}请求信息错误返回值:
{"status":0,"error":"删除失败"}不同错误描述部分有所不同。
地址:https://www.bigiot.net/oauth/timer
①获取定时器信息
请求方式:GET
参数:
{
access_token:"授权凭证,凭证内部已包含用户ID信息",
id:"要查询的定时器ID,取值为0时,获取名下所有定时器信息"
}示例:
$ curl https://www.bigiot.net/oauth/timer?access_token=xxxxxxxxxxxxx&id=xx
②修改定时器
请求方式:POST(application/x-www-form-urlencoded)
参数:
{
access_token:"授权凭证,凭证内部已包含用户ID信息",
id:"要修改的定时器ID",
title:"定时器名称",
enable:0/1, //0关闭,1开启
repeats:0/1,//0不重复提醒,1重复提醒
content:"命令内容",
toid:"命令发送目标,形如:D12",
week:"星期设置,形如:0,1,2,3,4,5,6",
hour:"小时设置,形如:0,1,2,...,21,22,23",
min:"分钟设置,形如:0,5,10,15,...,45,50,55"
}说明:access_token、id字段必填,其他字段根据修改需要填写。
示例:
$ curl "https://www.bigiot.net/oauth/timer" -d "access_token=xxxxxxxxxxxxx&id=xx&enable=0"
地址:https://www.bigiot.net/oauth/say
请求方式:POST(application/x-www-form-urlencoded)
参数:
{
access_token:"授权凭证,凭证内部已包含用户ID信息",
id:"发送目标通讯ID,可为设备或用户,形如:U2、D12,设备ID前加D,用户ID前加U",
c:"消息内容,如:play",
sign:"可选,用于信息标识"
}示例:
$ curl "https://www.bigiot.net/oauth/say" -d "access_token=xxxxxxxxxxxxx&id=D10&c=play&sign=room"
以Postman获取access_token设置为例,设置如下。
1、在Headers里设置Content-Type为application/x-www-form-urlencoded

2、在Body内设置请求参数,其中password保存原样,其他四个参数根据自己实际情况修改。设置完成点击send,返回结果如图中所示。
