【发布时间】:2014-03-27 02:47:39
【问题描述】:
我已经使用 GCM 实现了推送通知。当我运行必要的文件以从本地服务器(在我的计算机上使用XAMPP 服务器)向设备发送消息时,一切都运行良好。但是当我将文件上传到我的实时服务器并运行文件时,我没有收到推送通知。我验证了所有文件,但没有得到。以下是我的php 代码:
send_message.php
<?php
if (isset($_REQUEST["regId"]) && isset($_REQUEST["message"]) && isset($_REQUEST["senderid"])) {
$regId = $_REQUEST["regId"];
$message = $_REQUEST["message"];
$senderid = $_REQUEST["senderid"];
include_once './GCM.php';
$gcm = new GCM();
$registatoin_ids = array($regId);
$message = array("message" => $message, "sender_id" => $senderid);
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;die;
}
?>
GCM.php
<?php
class GCM {
function __construct() {
}
public function send_notification($registatoin_ids, $message) {
// include config
include_once './config.php';
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
echo 'result';
echo json_encode($fields);
echo $result;
}
}
?>
我正在通过提供服务器 url 和必要的参数从浏览器执行 send_message.php 文件。在本地机器上,我收到推送通知,但是当我通过提供实时服务器url 执行相同的文件时,它没有给我任何输出。可能是什么问题?
【问题讨论】:
-
Anil,你能从 live url 访问吗?我的意思是,当您将代码放到实时服务器时,您可以使用实时 url 访问它吗?
-
是的,我可以访问它...
-
好,你能告诉我那个网址吗?
-
@Kedarnath:我认为,这里的问题出在 GCM.php 文件的 curl 部分...
-
是的,我认为 curl 在 XAamp 中有一些设置可以从实时位置打开它。
标签: android google-cloud-messaging