Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Last active July 5, 2016 02:42
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 jirawatee/abf1677127a89b6dfd49ee8e8c221dd3 to your computer and use it in GitHub Desktop.
Save jirawatee/abf1677127a89b6dfd49ee8e8c221dd3 to your computer and use it in GitHub Desktop.
FCM - FCM.class.php
<?php
class FCM {
public function send_notification($token, $payload_notification, $payload_data) {
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
//'registration_ids' => $token,
//'condition' => "'logined' in topics || 'news' in topics",
'to' => '/topics/news',
'priority' => 'normal',
'notification' => $payload_notification,
'data' => $payload_data
);
$headers = array(
'Authorization: key=YOUR_SERVER_KEY',
'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);
// Disabling SSL Certificate support temporary
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
echo $result;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment