【问题标题】:Received HttpResponse 400 from PHP server using Zend framework使用 Zend 框架从 PHP 服务器接收到 HttpResponse 400
【发布时间】:2012-08-05 06:15:38
【问题描述】:

我正在尝试使用带有 Zend 框架的 PHP 服务器向我的 android 应用程序发送推送通知,但我得到的 HttpResponse 为:请求无法解析为 JSON 或包含无效字段,错误代码为 400。 我使用了Zend框架demo中给出的服务端代码,如下:

<?php
require_once 'Zend/Mobile/Push/Gcm.php';
require_once 'Zend/Mobile/Push/Message/Gcm.php';

$regId = $_POST["registrationid"];

$message = new Zend_Mobile_Push_Message_Gcm();
$message->setId(time());
$message->addToken($regId);
$message->setData(array(
    'foo' => 'bar',
    'bar' => 'foo',
));

$gcm = new Zend_Mobile_Push_Gcm();
$gcm->setApiKey('my api key');

try {
    $response = $gcm->send($message);
} catch (Zend_Mobile_Push_Exception $e) {
    // all other exceptions only require action to be sent or implementation of exponential backoff.
    die($e->getMessage());
}

// handle all errors and registration_id's
foreach ($response->getResults() as $k => $v) {
    if ($v['registration_id']) {
        printf("%s has a new registration id of: %s\r\n", $k, $v['registration_id']);
    }
    if ($v['error']) {
        printf("%s had an error of: %s\r\n", $k, $v['error']);
    }
    if ($v['message_id']) {
        printf("%s was successfully sent the message, message id is: %s", $k, $v['message_id']);
    }
}

【问题讨论】:

    标签: php android zend-framework google-cloud-messaging


    【解决方案1】:

    我手头没有确切的 URL,我正在手机上尝试,但我最近在我的博客中提到了这个。见http://www.rogerethomas.com 您需要的是使用浏览器 API 密钥,而不是服务器密钥。不要问为什么,但 Google 的文档似乎有错误。

    编辑:这是我对另一个类似问题的回答的最新链接: GCM with PHP (Google Cloud Messaging)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-20
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多