Created
April 23, 2019 07:12
-
-
Save sakilimran/9f9afd367444ed9c884a27ba9132bad9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// API access token from Google API's Console | |
//define('ACCESS_TOKEN', 'ya29.GlvmBr9UH4KLL_Do6pHGOoZ7ksfURRHAqRh3dPWcMiYjNov4hhse_m147qlSwVZIqty989V73iQrtSD3DVT6AVaNtYFEQbQeq1EuUHhRMBTf1Go6lXTPPMzQX6-Q'); | |
// API access key from Google API's Console | |
define('API_KEY', 'AIzaSyDB5KH7JaT5zRDq8QyRYOt3xMN4fyBaY_c'); | |
// Firebase project id | |
define('PROJECT_ID', 'skitto-testbed'); | |
class FCM | |
{ | |
public function subscribe_to_topic($topic_name) | |
{ | |
$registration_tokens = ['fA3c_wLqvvs:APA91bHpmnkV8vkIPMJ4S6CxN_boB1dXvq2hzlkq0aRQ5FLnznPxpBMGTCpNTfz92sWvUADJ15D0aVPdHJv7ryI7pVLOv-wRMYid9jc1T4F9MrkLM8dZn7J-1ByF3LqqlnNp88iWHz3B']; | |
$fields = array( | |
"to" => "/topics/" . $topic_name, | |
"registration_tokens" => $registration_tokens | |
); | |
$headers = array | |
( | |
'Content-Type: application/json', | |
'Authorization: key=' . API_KEY | |
); | |
#Send Response To FireBase Server | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'https://iid.googleapis.com/iid/v1:batchAdd'); | |
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; | |
} | |
public function unsubscribe_from_topic($topic_name) | |
{ | |
$registration_tokens = ['fA3c_wLqvvs:APA91bHpmnkV8vkIPMJ4S6CxN_boB1dXvq2hzlkq0aRQ5FLnznPxpBMGTCpNTfz92sWvUADJ15D0aVPdHJv7ryI7pVLOv-wRMYid9jc1T4F9MrkLM8dZn7J-1ByF3LqqlnNp88iWHz3B']; | |
$fields = array( | |
"to" => "/topics/" . $topic_name, | |
"registration_tokens" => $registration_tokens | |
); | |
$headers = array | |
( | |
'Content-Type: application/json', | |
'Authorization: key=' . API_KEY | |
); | |
#Send Response To FireBase Server | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'https://iid.googleapis.com/iid/v1:batchRemove'); | |
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; | |
} | |
public function getDeviceDetails($registration_token) | |
{ | |
$headers = array | |
( | |
'Content-Type: application/json', | |
'Authorization: key=' . API_KEY | |
); | |
#Send Response To FireBase Server | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'https://iid.googleapis.com/iid/v1/'.$registration_token.'?details=true'); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
echo $result; | |
} | |
} | |
$push_notification = new FCM(); | |
$push_notification->subscribe_to_topic('movies'); | |
$push_notification->unsubscribe_from_topic('movies'); | |
$push_notification->getDeviceDetails('dJzcCivdti0:APA91bHe3gY7axI2rOtQWei6TWbL8n3jz-hRZPRjQdVc0wcTGrSy-HWPP_ZabaVaDCTkV4EdjUTdYjgFlMx69-OMPXFZafdeSGZzuiUDG0LzuwpYGelpbLUtvmBRbd_4ZXGFytV8Mq-k'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment