Skip to content

Instantly share code, notes, and snippets.

@yudanta
Created August 18, 2014 15:19
Show Gist options
  • Save yudanta/fe08735a509a6e6eb089 to your computer and use it in GitHub Desktop.
Save yudanta/fe08735a509a6e6eb089 to your computer and use it in GitHub Desktop.
GCM php
<?php
$url = "https://android.googleapis.com/gcm/send";
$api_key = "<api key>";
$client_id = array("gcm_id");
$headers = array(
"Content-type: application/json",
"Authorization: key=" . $api_key,
);
$data = array(
'msgid' => 2020,
'ncode' => 1001,
'sender' => 'Ydn',
'send_date' => '2014-08-10 10:11:12',
'subject' => 'test pake php',
'messages' => 'haee yudan',
'extras' => array("idJob"=>1, "idTicket"=>10, "ticket_no"=>"BCA_IN_AAAB"),
);
$postdata = array(
'data' => $data,
'registration_ids' => $client_id,
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => json_encode($postdata)
));
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment