在特定频道pubnub php sdk上获取未读消息

时间:2016-02-17 08:54:11

标签: php mysql cakephp pubnub

  

目标: - 在特定频道上获取未读消息。

用户登录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个十位数的时间戳更新到我们的数据库中,以便登录用户。

  

正如pubnub团队讨论的那样,pubnub团队表示要添加7个零   我的时间戳的右端。哪个变为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;

通过打印为什么我收到所有消息?而不是在给定时间标记之后获取消息??

原因可以添加7个零不被pubnub接受如果这样建议我将我的时间戳(1455687812)转换为 pubnub时间令牌(17位)。

或者请指出我在这里做错了什么?

提前感谢您的帮助。

  

修改

我获取消息及其时间标记这样的东西..     // TIMETOKENS和MESSAGES

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,消息是闹鬼现在预期的输出将是

14556879844588614  Really want some more levels
14556879769565496  The fact I can see

为什么它会返回所有消息而不是2条消息?

注意: - 这次我没有添加任何零,并使用pubnub最初生成的timetoken。

即使this也返回所有消息!

仍然没有运气。

1 个答案:

答案 0 :(得分:0)

我们在您的支持服务单中私下讨论了这个问题,它只是归结为您使用的时间段以及您在PubNub历史记录API中使用的参数。

给定的timetoken并不是您所寻找的消息的确切发布时间,因此结果可能不是您所期望的。

See the PubNub PHP Storage tutorial docs for full detailsconsult PubNub Support以获得进一步的帮助。

相关问题