Skip to content

Instantly share code, notes, and snippets.

@GideonBabu
Created September 28, 2018 07:40
Show Gist options
  • Save GideonBabu/f136a204a0461c060682a563691714d8 to your computer and use it in GitHub Desktop.
Save GideonBabu/f136a204a0461c060682a563691714d8 to your computer and use it in GitHub Desktop.
PHP Script to send push notification to android
<?php
define( 'API_ACCESS_KEY', 'AIzaSyA7TJAvFZrD_asZM92xoWM5u5MD-uMyYH0' );
$registrationIds = array(
"cQ8E8TvwQxg:APA91bHGxk5NBPze0_zOTQLif9s5VpOYzCyEvPmFlP3PD5FI6_5LyIVNkTKlfpSS9wy4SpO5iIX7Jdvp3nNLMYvCk6IbNRE_ykplP-Es8ebuJPF_tHhhzVS6TjWS5gDlC0Fp8JIkckNy",
"d5ttcEFtdg8:APA91bGu7QvkTkGKi4l6GviGCYgSQsv0bRLmgxlbJCDmM6iBmcOT5XAtwyQ1vprQCeTIkAvXwxb_IlitoQF335ynDyrvZXRTaN8HgDe8WFf__RI06ahec1yx0EbwkuzUI5h_s5WWP_tl"
);
$msg = array
(
'body' => 'The Chennai Silks',
'title'=> 'Welcome to TCS!',
// 'icon'=> 'myicon',
'sound' => 'default'
);
$fields = array
(
'to'=> $registrationIds,
'notification'=> $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
//curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment