【发布时间】:2016-03-29 11:59:47
【问题描述】:
我最近切换了服务器,但我的 Google Cloud 消息传递代码不再有效。我没有太多的服务器经验,我试图在整个互联网上寻找合适的解决方案,但没有成功。
我有一个 GoDaddy 服务器(工作),我已经设置并切换到 linode 服务器上的灯组。我一定错过了服务器配置中的某些内容,导致发送 gcm 的代码在 godaddy 上工作但在 apache linode 服务器上不起作用。
注册 id 没有问题,但无法发送 gcm 消息。我正在使用 php 脚本发送它们,我知道这不是问题。
是否需要设置任何设置才能使 Google Cloud Messaging 正常工作?
访问日志:
###.###.###.### - - [23/Dec/2015:12:47:40 -0500] "POST /test/test.php HTTP/1.1" 500 372 "-" "Mozilla/5.0 (Macin
错误日志:
empty
我遵循了这些教程:
https://www.linode.com/docs/getting-started
https://www.linode.com/docs/websites/lamp/lamp-on-ubuntu-14-04
https://www.linode.com/docs/databases/mysql/install-mysql-phpmyadmin-on-ubuntu-12-04
https://www.linode.com/docs/security/ssl/ssl-apache2-debian-ubuntu
https://www.linode.com/docs/websites/apache/apache-web-server-ubuntu-12-04
GCM.php
<?php
class GCM {
function __construct() {
}
public function send_notification($registatoin_ids, $message, $google) {
$url = 'https://gcm-http.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
$headers = array(
'Authorization: key=' . $google,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
echo $result;
}
}
?>
test.php
<?php
include_once './gcm.php';
$message = $_POST['msg'];
$reg = $_POST['regid'];
$registation_ids = array();
array_push($registation_ids, $reg);
$googleAPIKey = "GOOGLE_API_KEY";
$gcm = new GCM();
$messages = array("message" => $message, "analyticsId" => "someid");
$result = $gcm->send_notification($registation_ids, $messages, $googleAPIKey);
echo $result;
?>
打开了 php 日志,仍然没有。我仍然只在 linode 服务器上收到 500 内部错误。
【问题讨论】:
标签: android apache web-services google-cloud-messaging linode