├── README.md
├── fcm_page.html
├── firebase-messaging-sw.js
└── send_notification.php
/README.md:
--------------------------------------------------------------------------------
1 | "# FirebaseWebPushNotification"
2 |
3 | Firebase Push Notification Example for Browser
4 |
--------------------------------------------------------------------------------
/fcm_page.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | Firebase Web Push Notification Example
9 |
10 |
11 |
12 |
13 |
72 |
73 |
--------------------------------------------------------------------------------
/firebase-messaging-sw.js:
--------------------------------------------------------------------------------
1 | importScripts('https://www.gstatic.com/firebasejs/7.14.6/firebase-app.js');
2 | importScripts('https://www.gstatic.com/firebasejs/7.14.6/firebase-messaging.js');
3 |
4 | var firebaseConfig = {
5 | apiKey: "YOUR_API_KEY",
6 | authDomain: "YOUR_FIREBASE_DOMAIN_NAME",
7 | databaseURL: "YOUR_FIREBASE_DATBASE_URL",
8 | projectId: "YOUR_FIREBASE_PROJECT_ID",
9 | storageBucket: "YOUR_FIREBASE_STORAGE_BUCKET END WITH appspot.com",
10 | messagingSenderId: "YOUR SENDER ID",
11 | appId: "YOUR APP ID",
12 | measurementId: "YOUR MEASUREMENT ID"
13 | };
14 |
15 | firebase.initializeApp(firebaseConfig);
16 | const messaging=firebase.messaging();
17 |
18 | messaging.setBackgroundMessageHandler(function (payload) {
19 | console.log(payload);
20 | const notification=JSON.parse(payload);
21 | const notificationOption={
22 | body:notification.body,
23 | icon:notification.icon
24 | };
25 | return self.registration.showNotification(payload.notification.title,notificationOption);
26 | });
--------------------------------------------------------------------------------
/send_notification.php:
--------------------------------------------------------------------------------
1 | $_REQUEST['token'],
7 | "notification"=>array(
8 | "body"=>$_REQUEST['message'],
9 | "title"=>$_REQUEST['title'],
10 | "icon"=>$_REQUEST['icon'],
11 | "click_action"=>"https://google.com"
12 | )
13 | );
14 |
15 | $headers=array(
16 | 'Authorization: key=YOUR_SERVER_KEY',
17 | 'Content-Type:application/json'
18 | );
19 |
20 | $ch=curl_init();
21 | curl_setopt($ch,CURLOPT_URL,$url);
22 | curl_setopt($ch,CURLOPT_POST,true);
23 | curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
24 | curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
25 | curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fields));
26 | $result=curl_exec($ch);
27 | print_r($result);
28 | curl_close($ch);
29 | }
30 | sendNotification();
--------------------------------------------------------------------------------