【问题标题】:Setting up an Apache Server (ubuntu 12.04) for GCM (Linode)为 GCM (Linode) 设置 Apache 服务器 (ubuntu 12.04)
【发布时间】: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


    【解决方案1】:

    我将回答我自己的问题,因为我得到了它的工作。

    我从未安装过 PHP curl。

    http://jesselau.com/2013/04/26/how-to-add-curl-to-linode-ubuntu/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-01
      • 2012-09-18
      • 1970-01-01
      • 2015-04-27
      • 2012-06-21
      • 2012-12-09
      • 2017-06-26
      • 1970-01-01
      相关资源
      最近更新 更多