Я пытаюсь отправить push-уведомления в свое приложение для Android, используя PHP-сервер с Zend framework, но я получаю HttpResponse как: запрос не может быть проанализирован как JSON или содержит недопустимые поля с кодом ошибки 400. Я использовал сервер код, приведенный в демонстрации Zend Framework, который выглядит следующим образом:
<?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']);
}
}