Skip to content

Instantly share code, notes, and snippets.

@patidardhaval
Created December 25, 2018 11:49
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 patidardhaval/5203f2dae4e2c79055c3c959669b981c to your computer and use it in GitHub Desktop.
Save patidardhaval/5203f2dae4e2c79055c3c959669b981c to your computer and use it in GitHub Desktop.
<!-- Firebase App is always required and must be first -->
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-app.js"></script>
<!-- Add additional services that you want to use -->
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-messaging.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-functions.js"></script>
<!-- Comment out (or don't include) services that you don't want to use -->
<!-- <script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-storage.js"></script> -->
<script>
// Initialize Firebase
var config = {
apiKey: "*****",
authDomain: "webfcm-e49d8.firebaseapp.com",
databaseURL: "https://webfcm-e49d8.firebaseio.com",
projectId: "webfcm-e49d8",
storageBucket: "webfcm-e49d8.appspot.com",
messagingSenderId: "849978943949"
};
firebase.initializeApp(config);
const messaging = firebase.messaging();
messaging.usePublicVapidKey("BA2eLLCr3TsohmhQsZxROr-io6mjyv3I8uYmy3q_Dm42UaaXWyNX4JDMyO_jnvgBSPe--EprGGYp1_Zhi76qZC8");
messaging.requestPermission().then(function() {
console.log('Notification permission granted.');
// TODO(developer): Retrieve an Instance ID token for use with FCM.
// ...
}).catch(function(err) {
console.log('Unable to get permission to notify.', err);
});
messaging.onMessage(function(payload) {
console.log('Message received. ', payload);
// ...
});
messaging.getToken();
</script>
<?php
$request = new HttpRequest();
$request->setUrl('https://fcm.googleapis.com/fcm/send');
$request->setMethod(HTTP_METH_POST);
$request->setHeaders(array(
'Postman-Token' => 'ee3a89ba-c548-43e9-ba13-f759468fbc53',
'cache-control' => 'no-cache',
'Authorization' => 'key=AAAAxeaxac0:APA91bEjOcOXWbVr-mYk0PQLxLcZnDWesnUX-q79SMVvRT5zK_zzF0HiJKKlPTAsH-I8zuaoM501xOZ9eetwj6yV6XoLOLern3Y7D9D3xBZVZiActPbpk-xVk1bmP_lTgHcE8v35BEG9',
'Content-Type' => 'application/json',
));
$request->setBody('{
"notification": {
"title": "Firebase",
"body": "Firebase is awesome",
"click_action": "http://localhost",
"icon": ""
},
"to": "cL4acO_Di5I:APA91bGr5_Z0KUOVbybGtLS_mB_RXHAecOE62RVHoXqH8ivORKRUGvNwg2t_h5eu2wpsLetuqFHoRxD6jjspb7DcQX5K85xhSyWy6JNiuX-Sa0YKnhTE8P7q3ytHW1Up0ugW8uSsEUdc"
}');
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment