【问题标题】:Using Pusher API notify Particular User使用 Pusher API 通知特定用户
【发布时间】:2013-10-22 09:23:07
【问题描述】:

我有一个使用 jquery mobile 和 phonegap 的移动网络应用程序,另一个是 php 网站。我希望只向在线和移动应用程序上的特定用户发送通知,接收在 php 网站端以及在线用户的通知移动网络应用程序,所以我的问题是如何为特定用户设置频道,因为现在通知发送给所有用户,这对消息和连接毫无用处。

目前,我的代码向所有人发送通知,任何人都可以知道这个问题需要对我的代码进行更改。

在事件触发器上我有那个代码 php 站点。

$message = "User Response Has been Sent For Taxi On way";
            $pusher = new Pusher( APP_KEY, APP_SECRET, APP_ID );
            $data = array('message' => $message);
            $pusher->trigger( 'dispatcher_channel', 'dispatcher_Response', $data );

在移动网络应用上我有那个代码。

Pusher.log = function(message) {
          if (window.console && window.console.log) {
            window.console.log(message);
          }
        };

        var pusher = new Pusher('APP_KEY');
        var channel = pusher.subscribe('dispatcher_channel');
        channel.bind('dispatcher_Response', function(data) {
          alert(data.message);
          channel.bind('dispatcher_Response', function(data) {});
        });

【问题讨论】:

    标签: javascript php pusher


    【解决方案1】:

    尝试将用户名(我假设它是用户独有的)作为两端的频道名称的一部分。然后发布到该频道。

    【讨论】:

    • vidya 你的意思是不是在我的代码上使用 pusher.subscribe('dispatcher_channel');现在从用户名的两端替换 var username = "ali"; var channel = pusher.subscribe(用户名);
    • 类似 var channel = pusher.subscribe("channel_ " + username );
    • 根据stackoverflow.com/a/19197310/39904,这是正确的答案,也是目前实现用户特定通知的唯一方法。
    • 但是,它安全吗?如果我错了,请纠正我,但是,知道用户名的用户不能在没有人注意到的情况下订阅频道吗?
    • @user405205​​4 你说得对,更安全的是在用户电子邮件上使用 md5 或 sha1,pusher.subscribe("channel_")
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-12
    相关资源
    最近更新 更多