Goal:- to get unread messages on particular channel.
用户登录 upitch 网站。
一旦他进入消息页面,我们将维护 message_page_visited_count = 1
当用户从消息页面转到任何其他页面时,我们将更新 message_page_visited_count = 0
并更新时间戳。
现在我们使用 mysql 函数 strtotime("now")
来更新时间戳,类似这样。
$this->Userlink->updateAll(
array('pubnub_time_stamp' => strtotime("now")), array('Userlink.id' => $loggedInUser)
); // updating timestamp for logged in user 1455687812
这会将 1455687812
十位数字时间戳更新到我们的数据库中以供登录用户使用。
As discussed with the pubnub team, pubnub team said to add 7 zeros to the right end of my timestamp. Which turns to be
14556878120000000
我已经集成了php-sdk pubnub
include_once './vendor/autoload.php';
use Pubnub\Pubnub;
$publish_key = publish_key
$subscribe_key = subscribe_key
$pubnub = new Pubnub($publish_key, $subscribe_key);
我找到了像这样实现历史记录的方法。
history(
string $channel,
integer $count = 100,
boolean $include_token = null,
integer $start = null,
integer $end = null,
boolean $reverse = false)
通过实现:-
$result= $pubnub->history(
"2242_2272_1116", //my channel
null,
true,
null,
14556878120000000, //endtime token with 7 zeros
null);
echo "<pre>";
print_r($result);die;
通过打印为什么我会收到所有消息??而不是在给定的时间 token 后获取消息 ??
如果 pubnub 不接受添加 7 个零的原因,请建议我将时间戳 (1455687812) 转换为 pubnub 时间 token (17 位数字)。
或者请指出我在这里做错了什么?
在此先感谢您的帮助。
EDIT
我像这样获取消息及其时间标记...... //时间 token 和消息
14556879844588614 Really want some more levels
14556879769565496 The fact I can see
14556871094404310 Haunted
14556871091411782 Hello
14556870983775230 Hello
$result= $pubnub->history(
"2242_2272_1116",
null,
true,
null,
14556871094404310, null);
echo "<pre>";
print_r($result);die;
我正在传递第 3 条消息的时间标记,即 14556871094404310
并且消息是 Haunted 现在预期的输出是
14556879844588614 Really want some more levels
14556879769565496 The fact I can see
为什么它返回所有消息而不是 2 条消息?
注意:- 这次我没有添加任何零,而是使用了 pubnub 最初生成的时间 token 。
甚至做this还返回所有消息!
仍然没有运气。
最佳答案
我们在您的支持票中私下讨论了这个问题,最终归结为您使用的时间 token 和您在 PubNub 历史记录 API 中使用的参数。
给定的时间标记不是您要查找的消息的确切发布时间标记,因此结果可能与您预期的不同。
See the PubNub PHP Storage tutorial docs for full details和 consult PubNub Support寻求进一步帮助。
关于php - 在特定 channel pubnub php sdk上获取未读消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35451863/