貝殼物聯(lián)公開(kāi)用戶接口
一、概述
1、用戶信息 2、設(shè)備信息 3、數(shù)據(jù)接口 4、接口歷史數(shù)據(jù) 5、定時(shí)器
為了方便用戶自行開(kāi)發(fā)APP或網(wǎng)站對(duì)接貝殼物聯(lián)平臺(tái),特開(kāi)放部分用戶權(quán)限,包括設(shè)備、數(shù)據(jù)接口、報(bào)警、實(shí)時(shí)通訊等接口。
貝殼物聯(lián)平臺(tái) 充分信任 各位開(kāi)發(fā)者的基礎(chǔ)上授權(quán)采用OAuth2.0的User Credentials授權(quán)模式,即用戶使用ID和密碼直接登錄第三方應(yīng)用,無(wú)需顯式授權(quán)認(rèn)證,這樣降低了開(kāi)發(fā)流程上的難道。但為了 充分保護(hù) 用戶安全,此處密碼非用戶登錄貝殼物聯(lián)的密碼,是用戶在后臺(tái)獲取的用戶APIKEY。
在貝殼物聯(lián)用戶中心→個(gè)人信息→開(kāi)發(fā)者出點(diǎn)擊成為開(kāi)發(fā)者,填寫(xiě)應(yīng)用信息保存即可獲取第三方應(yīng)用ID(client_id)和密碼(client_secret),此信息在獲取授權(quán)時(shí)需用到。
地址:http://m.placeboworld.cn/oauth/token
請(qǐng)求方式:POST(application/x-www-form-urlencoded)
參數(shù):
{
client_id:"應(yīng)用ID",
client_secret:"應(yīng)用密碼",
username:"用戶ID",
password:"用戶apikey",
grant_type:"password"
}示例:
$ curl "http://m.placeboworld.cn/oauth/token" -d "grant_type=password&client_id=xxxx&client_secret=xxxx&username=x&passwor=xxxx"
請(qǐng)求信息正確返回值:
{"access_token":"219e53e4fea824e7cc86","expires_in":172800,"token_type":"Bearer","scope":null,"refresh_token":"8107bce9803527c448"}access_token——獲取網(wǎng)站資源憑證
expires_in——憑證有效時(shí)間,單位秒
token_type——憑證類型
scope——備用字段
fresh_token——刷新當(dāng)前token憑證,可用于延期當(dāng)前憑證(暫不可用)
請(qǐng)求信息錯(cuò)誤返回值:
{"error":"invalid_grant","error_description":"Invalid username and password combination"}不同錯(cuò)誤描述部分有所不同。
注意:token有效期為2天,請(qǐng)?jiān)诒镜赝咨苾?chǔ)存使用,在到期或即將到期時(shí)再次獲取。不可每次調(diào)用接口時(shí)就獲取一次,或者頻繁定期獲取。定期獲取可以一天一次。同一用戶同一應(yīng)用獲取token頻率長(zhǎng)期超過(guò)12小時(shí)/次的,將會(huì)被停用。
每次請(qǐng)求開(kāi)放資源時(shí),都需攜帶在有效期內(nèi)的access_token。
地址:http://m.placeboworld.cn/oauth/userinfo
請(qǐng)求方式:GET
參數(shù):
{
access_token:"授權(quán)憑證,憑證內(nèi)部已包含用戶ID信息"
}示例:
$ curl http://m.placeboworld.cn/oauth/userinfo?access_token=xxxxxxxxxxxxx
請(qǐng)求信息正確返回值:
{"uid":"2","nickname":"xxxx","level":"8","score":"534","online":0,"image":"57de7787e3de9_769"}uid——用戶ID
nickname——用戶名
level——用戶等級(jí)
score——用戶積分
online——在線狀態(tài),0:不在線,1:在線
image——頭像代碼,可用于獲取頭像
請(qǐng)求信息錯(cuò)誤返回值:
{"error":"invalid_grant","error_description":"xxxxxxxxxxxxxx xxxxxxx"}不同錯(cuò)誤描述部分有所不同。
頭像獲取地址:http://m.placeboworld.cn/userimg/bigiot_xxxx_big.jpg
xxxx替換為image字段的值,bigiot_xxxx_big中的big也可以替換為centre、small,代表圖片的三種不同尺寸。
地址:http://m.placeboworld.cn/oauth/dev
請(qǐng)求方式:GET
參數(shù):
{
access_token:"授權(quán)憑證,憑證內(nèi)部已包含用戶ID信息",
id:要查詢信息的設(shè)備ID,為0時(shí)獲取用戶名下所有設(shè)備信息
}示例:
$ curl http://m.placeboworld.cn/oauth/dev?access_token=xxxxxxxxxxxxx&id=0
請(qǐng)求所有設(shè)備信息正確返回值:
[{"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"},...]請(qǐng)求單個(gè)設(shè)備信息正確返回值:
{"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——設(shè)備ID
title——設(shè)備名稱
description——設(shè)備簡(jiǎn)介
open——是否公開(kāi),0:否,1:是
open_listen——是否公開(kāi)監(jiān)聽(tīng),0:否,1:是
online——是否在線,0:否,1:是
encrypt——是否開(kāi)啟加密登錄,0:否,1:是
image——頭像代碼,可用于獲取頭像
lat——設(shè)備所在經(jīng)度
lng——設(shè)備所在維度
onlinetime——在線時(shí)長(zhǎng),單位:秒
請(qǐng)求信息錯(cuò)誤返回值:
{"error":"invalid_grant","error_description":"xxxxxxxxxxxxxx xxxxxxx"}不同錯(cuò)誤描述部分有所不同。
頭像獲取地址:http://m.placeboworld.cn/devimg/bigiot_xxxx_big.jpg
xxxx替換為image字段的值,bigiot_xxxx_big中的big也可以替換為centre、small,代表圖片的三種不同尺寸。
地址:http://m.placeboworld.cn/oauth/myinputs
請(qǐng)求方式:GET
參數(shù):
{
access_token:"授權(quán)憑證,憑證內(nèi)部已包含用戶ID信息"
}示例:
$ curl http://m.placeboworld.cn/oauth/myinputs?access_token=xxxxxxxxxxxxx
請(qǐng)求信息正確返回值:
[{"id":"1","did":"1","title":"\u5f00\u5173","type":"0","unit":"Lux","description":"\u7535\u706f\u5f00\u5173\u72b6\u6001","save":"1","save_interval":"10"},...]id——數(shù)據(jù)接口ID
did——所屬設(shè)備ID
title——接口名稱
type——接口類型,0:數(shù)字量,1:模擬量,2,定位接口,3:圖片接口
unit——接口數(shù)據(jù)單位
description——設(shè)備簡(jiǎn)介
save——是否保存歷史數(shù)據(jù),0:否,1:是
save_interval——保存歷史數(shù)據(jù)間隔,單位:分鐘
請(qǐng)求信息錯(cuò)誤返回值:
{"error":"invalid_grant","error_description":"xxxxxxxxxxxxxx xxxxxxx"}不同錯(cuò)誤描述部分有所不同。
①獲取接口歷史數(shù)據(jù)
地址:http://m.placeboworld.cn/oauth/historydata
請(qǐng)求方式:GET
參數(shù):
{
access_token:"授權(quán)憑證,憑證內(nèi)部已包含用戶ID信息",
id:"要查詢的數(shù)據(jù)接口ID"
}示例:
$ curl http://m.placeboworld.cn/oauth/historydata?access_token=xxxxxxxxxxxxx&id=xx
請(qǐng)求信息正確返回值:(接口類型不同返回?cái)?shù)據(jù)有所不同)
[{"value":"1","time":"1"},...]value——數(shù)值
time——數(shù)據(jù)上傳時(shí)間
請(qǐng)求信息錯(cuò)誤返回值:
{"error":"invalid_grant","error_description":"xxxxxxxxxxxxxx xxxxxxx"}不同錯(cuò)誤描述部分有所不同。
②清空接口歷史數(shù)據(jù)
地址:http://m.placeboworld.cn/oauth/delete_history_data
請(qǐng)求方式:POST
參數(shù):
{
access_token:"授權(quán)憑證,憑證內(nèi)部已包含用戶ID信息",
id:"要清空數(shù)據(jù)的接口ID"
}示例:
$ curl "http://m.placeboworld.cn/oauth/delete_history_data" -d "access_token=xxxxxxxxxxxxx&id=xx"
請(qǐng)求信息正確返回值:
{"status":1}請(qǐng)求信息錯(cuò)誤返回值:
{"status":0,"error":"刪除失敗"}不同錯(cuò)誤描述部分有所不同。
地址:http://m.placeboworld.cn/oauth/timer
①獲取定時(shí)器信息
請(qǐng)求方式:GET
參數(shù):
{
access_token:"授權(quán)憑證,憑證內(nèi)部已包含用戶ID信息",
id:"要查詢的定時(shí)器ID,取值為0時(shí),獲取名下所有定時(shí)器信息"
}示例:
$ curl http://m.placeboworld.cn/oauth/timer?access_token=xxxxxxxxxxxxx&id=xx
②修改定時(shí)器
請(qǐng)求方式:POST(application/x-www-form-urlencoded)
參數(shù):
{
access_token:"授權(quán)憑證,憑證內(nèi)部已包含用戶ID信息",
id:"要修改的定時(shí)器ID",
title:"定時(shí)器名稱",
enable:0/1, //0關(guān)閉,1開(kāi)啟
repeats:0/1,//0不重復(fù)提醒,1重復(fù)提醒
content:"命令內(nèi)容",
toid:"命令發(fā)送目標(biāo),形如:D12",
week:"星期設(shè)置,形如:0,1,2,3,4,5,6",
hour:"小時(shí)設(shè)置,形如:0,1,2,...,21,22,23",
min:"分鐘設(shè)置,形如:0,5,10,15,...,45,50,55"
}說(shuō)明:access_token、id字段必填,其他字段根據(jù)修改需要填寫(xiě)。
示例:
$ curl "http://m.placeboworld.cn/oauth/timer" -d "access_token=xxxxxxxxxxxxx&id=xx&enable=0"
地址:http://m.placeboworld.cn/oauth/say
請(qǐng)求方式:POST(application/x-www-form-urlencoded)
參數(shù):
{
access_token:"授權(quán)憑證,憑證內(nèi)部已包含用戶ID信息",
id:"發(fā)送目標(biāo)通訊ID,可為設(shè)備或用戶,形如:U2、D12,設(shè)備ID前加D,用戶ID前加U",
c:"消息內(nèi)容,如:play",
sign:"可選,用于信息標(biāo)識(shí)"
}示例:
$ curl "http://m.placeboworld.cn/oauth/say" -d "access_token=xxxxxxxxxxxxx&id=D10&c=play&sign=room"
以Postman獲取access_token設(shè)置為例,設(shè)置如下。
1、在Headers里設(shè)置Content-Type為application/x-www-form-urlencoded

2、在Body內(nèi)設(shè)置請(qǐng)求參數(shù),其中password保存原樣,其他四個(gè)參數(shù)根據(jù)自己實(shí)際情況修改。設(shè)置完成點(diǎn)擊send,返回結(jié)果如圖中所示。
