DMS 永久存储 API http + json
注:每个接口加上http头 Authorization:dms <DMS的s_key>
注:< > 是表示填入的
<topic> topic 内容使用encodeURIComponent编码然后设置
如:topic = a/b encodeURIComponent("a/b") = "a%2Fb"
错误CODE
http code:
401 : StatusUnauthorized, 认证失败
500: StatusInternalServerError 内部服务出错
404:NotFind
历史数据
获取
http://api.dms.aodianyun.com/v1/historys/<topic>/<start>/<num_message>
GET
curl -i -H "Authorization: dms demo" \
"http://api.dms.aodianyun.com/v1/historys/demo_game/0/10"
成功返回 HTTP/1.1 200 OK
[
{
"msg": "hi",
"qos": 0,
"retain": false,
"time": 1423276134,
"_id":""
}
]
失败返回 HTTP/1.1 httpCode 内容为json格式 {'error':""}
获取 V2版本
http://api.dms.aodianyun.com/v2/historys?skip=<int>&num=<int>&topic=<string>&startTime=<int>&endTime=<int>
GET
curl -i -H "Authorization: dms demo" \
"http://api.dms.aodianyun.com/v2/historys?skip=0&num=10&topic=demo_stock"
成功返回 HTTP/1.1 200 OK
[
{
"topic":<your_topic>
"msg": "hi",
"qos": 0,
"retain": false,
"time": 1423276134,
"_id":""
}
]
失败返回 HTTP/1.1 httpCode 内容为json格式 {'error':""}
删除
使用获取回来的_id进行删除
DELETE http://api.dms.aodianyun.com/v1/historys/<topic>/<id>
curl -i -H "Authorization: dms demo" \
"http://api.dms.aodianyun.com/v1/historys/demo_game/5562b3222af868f041b4a8a4" -X DELETE
成功返回 HTTP/1.1 204 No Content
失败返回 HTTP/1.1 httpCode 内容为json格式 {'error':""}
推送消息
POST http://api.dms.aodianyun.com/v1/messages/<topic>
{
body:"msg"
}
body 是要推送出去的消息
curl -i -H "Authorization: dms demo" \
-H 'Content-Type: application/json' \
"http://api.dms.aodianyun.com/v1/messages/topic" -X POST -d'{"body":"123456"}'
成功返回 HTTP/1.1 204 No Content
失败返回 HTTP/1.1 httpCode 内容为json格式 {'error':""}
推送消息到某个用户
POST http://api.dms.aodianyun.com/v1/messages/p2p/<clientId>
{
body:"msg"
}
body 是要推送出去的消息
curl -i -H "Authorization: dms demo" \
-H 'Content-Type: application/json' \
"http://api.dms.aodianyun.com/v1/messages/p2p/you_client_id" -X POST -d'{"body":"123456"}'
成功返回 HTTP/1.1 204 No Content
失败返回 HTTP/1.1 httpCode 内容为json格式 {'error':""}
获取TOPIC中的在线用户
GET http://api.dms.aodianyun.com/v1/topics/<topic>/users?skip=0&num=1
默认skip num 为0 只返回用户数量
{
list:['clientid',"clientid1",...],//用户IDS
total:number //用户数量
}
body 是要推送出去的消息
curl -i -H "Authorization: dms demo" \
-H 'Content-Type: application/json' \
"http://api.dms.aodianyun.com/v1/topics/go/users?skip=0&num=10"
成功返回 HTTP/1.1 204 No Content
失败返回 HTTP/1.1 httpCode 内容为json格式 {'error':""}