Skip to content

Instantly share code, notes, and snippets.

@AdrienGiboire
Created June 27, 2016 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdrienGiboire/1f60a031d1bfa1a49a8f7214fd53b8ab to your computer and use it in GitHub Desktop.
Save AdrienGiboire/1f60a031d1bfa1a49a8f7214fd53b8ab to your computer and use it in GitHub Desktop.
<?php
define('API_ACCESS_KEY', 'AIzaSyA18itgZWVpD0zJ9ynRFHkVlpEIVRhzQGw');
$to = 'dZ0oX5R8nU4:APA91bHDLDsBZk7P76bRqNkiwWEhksd58QywCy2c0v-8HPuuwLN4SHdkFE5CMmgk5N-kzvGzWvxUafAlgDVnNagc9ZJf0BAxrdhmbScbsYojEEg5T750FPfne6VkA0rkD3Ix8jJbwtON';
$notification = array
(
'body' => 'here is a message. message',
'title' => 'This is a title. title',
'sound' => 1
);
$data = array
(
'param1' => 'val1',
'param2' => 'val2',
'param3' => 'val3'
);
$fields = array
(
'to' => $to,
'data' => $data,
'priority' => 'normal',
'notification' => $notification
);
$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_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