Skip to content

Instantly share code, notes, and snippets.

@yudanta
Created August 4, 2014 12:23
Show Gist options
  • Save yudanta/6ecd7ac0388d8ea77769 to your computer and use it in GitHub Desktop.
Save yudanta/6ecd7ac0388d8ea77769 to your computer and use it in GitHub Desktop.
sample post to gcm
<?php
$apiKey = "api_key";
$messageData = array(
"code" => 1001,
"subject" => "hai kak zam",
"messages" => "hai kak zam",
);
$registrationIdsArray = array("gcm_id");
$headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $apiKey);
$data = array(
'data' => $messageData,
'registration_ids' => $registrationIdsArray
);
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send" );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($data) );
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment