1<?php
2 // Replace with the real server API key from Google APIs
3 $apiKey = "your api key";
4
5 // Replace with the real client registration IDs
6 $registrationIDs = array( "reg id1","reg id2");
7
8 // Message to be sent
9 $message = "Your message e.g. the title of post";
10
11 // Set POST variables
12 $url = 'https://android.googleapis.com/gcm/send';
13
14 $fields = array(
15 'registration_ids' => $registrationIDs,
16 'data' => array( "message" => $message ),
17 );
18 $headers = array(
19 'Authorization: key=' . $apiKey,
20 'Content-Type: application/json'
21 );
22
23 // Open connection
24 $ch = curl_init();
25
26 // Set the URL, number of POST vars, POST data
27 curl_setopt( $ch, CURLOPT_URL, $url);
28 curl_setopt( $ch, CURLOPT_POST, true);
29 curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
30 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
31 //curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields));
32
33 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
34 // curl_setopt($ch, CURLOPT_POST, true);
35 // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
36 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields));
37
38 // Execute post
39 $result = curl_exec($ch);
40
41 // Close connection
42 curl_close($ch);
43 // print the result if you really need to print else neglate thi
44 echo $result;
45 //print_r($result);
46 //var_dump($result);
47?>