I am working on a php script to send the notification to the CGM server and I am working from this example:
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;
}
But I am not certain what the values should be for the variables: CURLOPT_POSTFIELDS , CURLOPT_SSL_VERIFYPEER , CURLOPT_RETURNTRANSFER , CURLOPT_HOST , CURLOPT_URL
Would anyone happen to know what the values for these should be?
Thank you!
” CURLOPT_POSTFIELDS ” this field is required to push number of fields in json encoding format. “CURLOPT_SSL_VERIFYPEER” this field is required if your third party server is HTTPS over SSL. “CURLOPT_RETURNTRANSFER” This field gives you reply from gcm server. “CURLOPT_HOST , CURLOPT_URL” this field is for HOST name and URL you have to define of your third party server.
That is de code that I have implemented :
As per my experience this links will help you :
GCM with PHP (Google Cloud Messaging)
http://www.sherif.mobi/2012/07/gcm-php-push-server.html
https://groups.google.com/forum/#!topic/android-gcm/hjk5PUYlTp0