【问题标题】:Google Cloud Messaging over XMPP protocol (server working with PHP and XMPPHP). How does it work?基于 XMPP 协议的 Google Cloud Messaging(使用 PHP 和 XMPPHP 的服务器)。它是如何工作的?
【发布时间】:2013-06-14 09:32:43
【问题描述】:

也许您已经听说过。它是在一个月前的 Google IO 上宣布的。 Google Cloud Messaging 只是下游(服务器 --> 电话),但现在借助增强的 CCS(云连接服务器),您可以通过 XMPP 协议通过持久的 TCP 连接向上游发送消息。我已经设计了一个适用于 GCM 和 HTTP 的应用程序。它使用 gcm 库和包含在其中的类(如 GCMRegistrar)。此类现在已弃用,Google 建议改用 GoogleCloudMessaging API。

现在一切都有些不同了。您有 Google 文档,他们很好地解释了如何设计您的 Android 应用程序。但是我的服务器有问题,因为我以前从未使用过 XMPP。他们在这里给出了 Python 代码: http://developer.android.com/google/gcm/gs.html 但我对Python一无所知。所以我进行了调查,然后我找到了 XMPPHP 库。然后,您可以使用 PHP 并使用该库连接 XMPP 并发送/接收消息。

我没有使用它的经验,它对我不起作用。如何打开与 Google XMPP 服务器的 XMPP 连接?

我找到了这种打开连接的方法(这里你使用库):

$conn = new XMPPHP_XMPP($host, $port, $user, $password, $resource, $server, $printlog, $loglevel);

有谁知道我必须在此处传递哪些参数才能与 Google CCS 连接?

我也想知道:

如何通过 XMPP 向设备发送消息? 如何接收来自设备的消息??

【问题讨论】:

  • $conn = new XMPPHP_XMPP('gcm.googleapis.com', '5235', '@gcm.googleapis.com', 'apikey', '', $server, 'true', '信息');
  • 我认为它现在可以工作了,我应该让这个连接打开吗?您知道如何向设备发送消息以测试一切正常吗?我已经准备好使用广播接收器的 Android 应用程序
  • 你能给我提供最新的gcm服务器代码吗?

标签: php android xmpp google-cloud-messaging xmpphp


【解决方案1】:

我遇到了同样的问题,尝试使用 XMPPHP,但后来发现 JAXL 库并切换到它。见unable to connect to Google Cloud Connection Server。 JAXL 允许您使用特殊的调试模式'log_level' => JAXL_DEBUG 查看它发送的内容。然后我看到谷歌给我发了这个:

<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><temporary-auth-failure/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Project 1945693724760 not whitelisted.</text></failure>

这就是我无法发送任何通知的原因。您应该首先在此处注册 CCS:https://services.google.com/fb/forms/gcm/

【讨论】:

    猜你喜欢
    • 2014-03-02
    • 2016-11-05
    • 2013-03-12
    • 2014-12-25
    • 2014-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多