Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Replace with real BROWSER API key from Google APIs
- $apiKey = "your-api-key";
- // Replace with real client registration IDs. Put the correct registration id you are getting from app. If you are using eclipse check your logcat you will get it there.
- $registrationIDs = array( "regid" );
- // Message to be sent
- $message = "Your Message Here";
- // Set POST variables.
- $url = 'https://android.googleapis.com/gcm/send';
- $fields = array(
- 'registration_ids' => $registrationIDs,
- 'data' => array( "message" => $message ) /*Make sure that message is the key you are using in GCMIntentService.java onMessage() -> extras.getString("message");*/
- );
- $headers = array(
- 'Authorization: key=' . $apiKey,
- '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 );
- curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
- // Execute post
- $result = curl_exec($ch);
- // Close connection
- curl_close($ch);
- // Echo success or failure
- echo $result;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement