跳到主要内容

历史消息 - PubSub (Websocket)

功能介绍

获取某个channel上发送的历史消息,您可以根据具体的参数来指定返回符合您期望的历史消息。

保留规则

套餐保留规则
免费应用免费保留1天内每个channel的最后30条消息
付费应用免费保留5天内每个channel的最后100条消息

资费

每调用1次,扣减1条消息数。

查询历史消息

参数说明

参数必填说明
channel必填要查询的channel
start可选要查询时间范围起始时间的毫秒数,默认为0,查询范围为从该channel上产生的第一条消息开始
end可选要查询时间范围起始时间的毫秒数,默认为当前时间,查询范围为该channel上截止当前此刻的所有消息
limit可选默认10,最大值为30

JavaScript查询

goeasy.pubsub.history({
channel: 'my_channel', //必需项
start: 1561347527648, //可选项,开始时间,默认为0,即从第一条消息开始查
end: 1561347706447, //可选项,结束时间,默认为当前时间
limit: 10, //可选项,返回的消息条数,默认为10条,最多30条
onSuccess: function (response) {
console.log("收到历史消息: " + JSON.stringify(response));
/**
response示例:
{
"code":200,
"content":{
"messages":[
{"time":1561347527649,"content":"my 001"}
{"time":1561347596077,"content":"my 002"}
{"time":1561347622613,"content":"my 003"}
{"time":1561347691826,"content":"my 004"}
{"time":1561347706447,"content":"my 005"}
]
}
}
**/
},
onFailed: function (error) { //获取失败
console.log("Failed to obtain history, code:" + error.code + ",error:" + error.content);
}
});

服务端Rest API查询

    Request:
URL: http(s)://<REST HOST>/v2/pubsub/history?appkey={appkey}&channel={channel}&start={start}&end={end}&limit={limit}
Method: GET
参数:
appkey //必需项,您的rest appkey
channel //必需项
start //可选项,开始时间,默认为0,即从第一条消息开始查
end //可选项,结束时间,默认为当前时间
limit //可选项,返回的消息条数,默认为10条,最多30条

Response JSON:
//response 示例:
{
"code":200,
"content":{
"messages":[
{"time":1561347527649,"content":"my 001"}
{"time":1561347596077,"content":"my 002"}
{"time":1561347622613,"content":"my 003"}
{"time":1561347691826,"content":"my 004"}
{"time":1561347706447,"content":"my 005"}
]
}
}

Webhook同步消息历史到服务器

通过启用消息历史的webhook功能,客户的服务器将可以实时接收GoEasy的消息发送记录

Webhook使用说明

详见GoEasy Webhook

消息同步请求数据格式

POST  /yourUrlPath   HTTP/1.1
Host: http://xxxx.xxxx.com/xxxx 客户服务端接口
Content-Type: application/x-www-form-urlencoded
x-goeasy-signature: xxxxxxxxxxxxx //请求签名,用于验证请求的合法性,防止欺骗攻击

参数:

content: [
{
"messageId": "32ece560afcb11eb847db1f7135a22af",
"timestamp": 1620457283818,
"channel": "my_channel",
"content": "Hello world!"
},
{
"messageId": "32ed3380afcb11eb847db1f7135a22af",
"timestamp": 1620457283822,
"channel": "my_channel",
"content": "你好,世界!"
},
{
"messageId": "32ed3382afcb11eb847db1f7135a22af",
"timestamp": 1620457283822,
"channel": "my_channel",
"content": "Hello, GoEasy Webhook!"
}
];