I have implemented push notification using GCM. Everything is working perfect when I run necessary files to send messages to device from my local server (on my computer with XAMPP
server). But when I upload files to my live server and when I run the files, I'm not getting push notification. I verified all the files but I'm not getting. Below is my php
code:
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;
}
}
?>
I'm executing send_message.php file from my browser by providing server url
and necesasry parameters. On local machine, I'm getting push notification, but while I executing the same file by providing live server url
, it is not giving me any output. What can be the issue?