服务端API

接口1 登录

输入

Path : http://haoshuo.love:2012/login
HTTP Method : POST
Params :haoshuo

haoshuo = {
"appid":"test",
"username":"2", //用户id
"pass":"123" //密码
}

输出

{
"uid":1, //用户id
"token":"04fa0cf760226c402c42f73d23869bad" //token
}

接口2 单聊

输入

Path : http://haoshuo.love:2012/p
HTTP Method : POST
Params :haoshuo

haoshuo =
{
"appid":"test",
"fromid":1, //发送者uid
"datatype":1, //1单聊,2群里
"toid":1, //接受者uid
"content":"my test 66", //消息内容
"token":"25d9dc7d4ca06048567da02527defc48", //token
"restart":"all" //保留字段,固定传all
}

输出

{"type":"ok"}

接口3 群聊

输入

Path : http://haoshuo.love:2012/gp
HTTP Method : POST
Params :haoshuo

haoshuo =
{
"appid":"test",
"fromid":1, //发送者uid
"datatype":2, //1单聊,2群里
"toid":1, //群组 id
"content":"my group msg", //消息内容
"token":"1zz", //token
"restart":"all" //保留字段,固定传all
}

输出

{"type":"ok"}

接口4 消息监听

输入

Path : http://haoshuo.love:2012/cget/stream?seq=1&cname=xxxxx&token=xxxxx (http chunk)

Path : http://haoshuo.love:2012/cget/poll?seq=1&cname=xxxxx&token=xxxxx (长连接)

输出

{
"type":"data",
//data: 正常的消息.
//noop: 心跳消息.
//429: Error message, too many channels/subscribers.
//401: Error message, token error.
"content":" //消息数据
{"msgs":
[ { "content":"my test 66", //消息内容 "fromid":"1", //发送者uid "toid":"2", //接受者uid 或者群组id "datatype":1, //1单聊,2群聊 "msgid":"1", //消息id }, { "content":"my test 66",//消息内容 "fromid":"1", //发送者uid "toid":"2", //接受者uid 或者群组id "datatype":1, //1单聊,2群聊 "msgid":"2", //消息id } ],
"endid":"301", //最近消息id即最大消息id
"toid":2 //接受者uid 或者群组id
}"
}

接口5 新消息拉取

输入

Path : http://haoshuo.love:2012/pull
HTTP Method : POST
Params :haoshuo

haoshuo =
{
"appid":"test",
"uid":1, //用户id
"token":"36296ee15676aa5805d428692140bc25" //token
}

输出

{
"msgs":
[ { "fromid":"1", //发送者uid "datatype":1, //1单聊,2群里 "content":"my test 66", //消息内容 "msgid":"230", //消息id "toid":"1" //接受者uid 或者群组id }, { "fromid":"1", "datatype":1, "content":"my test 66", "msgid":"231", "toid":"1"}, ],
"endid":"240",
"uid":1
}

接口6 消息接收确认(ack)

输入

Path : http://haoshuo.love:2012/ack
HTTP Method : POST
Params :haoshuo

haoshuo =
{
"appid":"test",
"uid":2, //用户id
"endid":243, //最近消息id即最大消息id
"token":"1ddc9e8e3815735f453acc880fbf69a0"
}

输出

{"type":"ok"}

接口7 退出登录接口

输入

Path : http://haoshuo.love:2012/logout
HTTP Method : POST
Params :haoshuo

haoshuo =
{
"appid":"test",
"uid":1, //用户id
"token":"39ce62ea55f98c1d33d5bdb00fdb698f" //token
}

输出

{
"uid":1, //用户id
"msg":"ok"
}

文章导航