Kirim notifikasi push ke android dan ios menggunakan firebase PHP + FCM. Dalam tutorial ini, Anda akan mempelajari cara mengirim notifikasi push ke android dan ios menggunakan firebase PHP FCM Show Tutorial ini akan menjelaskan setiap hal adalah contoh yang sangat sederhana dan mudah untuk mengirim notifikasi push ke android di php menggunakan google firebase fcm Kirim Push Notification ke Android dan iOS menggunakan PHP + FCM FirebaseCukup ikuti beberapa langkah untuk mengirim notifikasi push ke ios menggunakan PHP firebase fcm
Langkah 1 – Buat Indeks. File phpPada langkah ini, buat file php yang diberi nama index. php. Dan kemudian tambahkan kode berikut ke dalamnya <!DOCTYPE html> <html> <head> <title>PHP Send Push Notification To Android & IOS using Google FCM Example</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> </head> <body> <div class="container"> <br> <div class="row"> <div class="col-md-9"> <form action="send-notification.php" method="post" accept-charset="utf-8"> <div class="form-group"> <label for="formGroupExampleInput">Device Type</label> <select class="form-control" id="device_type" name="device_type" required=""> <option value="">Select Device type</option> <option value="Android">Android</option> <option value="Iphone">Iphone</option> </select> </div> <div class="form-group"> <label for="formGroupExampleInput">Notification Id</label> <input type="text" name="nId" class="form-control" id="formGroupExampleInput" placeholder="Please enter notification id" required=""> </div> <div class="form-group"> <button type="submit" id="send_form" class="btn btn-success">Submit</button> </div> </form> </div> </div> </div> </body> </html> Langkah 2 – Buat fcm. File phpPada langkah ini, buat file bernama fcm. php dan tambahkan kode berikut untuk notifikasi push ke dalamnya Perhatikan bahwa, Pastikan untuk menentukan Kunci API Server Firebase untuk mengirim permintaan ke firebase <?php class FCM { function __construct() { } /** * Sending Push Notification */ public function send_notification($registatoin_ids, $notification,$device_type) { $url = 'https://fcm.googleapis.com/fcm/send'; if($device_type == "Android"){ $fields = array( 'to' => $registatoin_ids, 'data' => $notification ); } else { $fields = array( 'to' => $registatoin_ids, 'notification' => $notification ); } // Firebase API Key $headers = array('Authorization:key=Your Firebase Server API Key Here','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 temporarly curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $result = curl_exec($ch); if ($result === FALSE) { die('Curl failed: ' . curl_error($ch)); } curl_close($ch); } } ?>_ Langkah 3 – Buat notifikasi-kirim. File phpPada langkah ini, buat notifikasi-kirim. php dan tambahkan kode berikut ke dalamnya <?php //save crop image in php if(isset($_POST["nId"])) { $regId =$_POST["nId"]; $dType =$_POST["device_type"]; // INCLUDE YOUR FCM FILE include_once 'fcm.php'; $arrNotification= array(); $arrNotification["body"] ="PHP Push Notification"; $arrNotification["title"] = "PHP Push Notification"; $arrNotification["sound"] = "default"; $arrNotification["type"] = 1; $fcm = new FCM(); $result = $fcm->send_notification($regId, $arrNotification,$dType); print_r($result); } ?> Langkah 4 – Jalankan AplikasiPada langkah ini, buka terminal Anda dan jalankan perintah berikut untuk menjalankan aplikasi ini dengan cepat cd project_directory php -S localhost:8000 Sekarang Anda dapat membuka URL berikut di browser Anda http://localhost:8000_ KesimpulanDalam tutorial ini, Anda telah mempelajari cara mengirim notifikasi push ke ios dan android menggunakan php fcm Tutorial PHP yang DirekomendasikanDirekomendasikan. -PHP 8 Paginasi dengan Contoh Bootstrap Direkomendasikan. -Registrasi Pengguna dengan Verifikasi Email di PHP Direkomendasikan. -Cara Menambahkan Captcha di Formulir Pendaftaran PHP Direkomendasikan. Formulir Kontak -PHP dengan Contoh Validasi jQuery Direkomendasikan. -PHP Cookie Set, Dapatkan Dan Hapus Contoh Direkomendasikan. -Pilih Sisipkan Perbarui Hapus Catatan menggunakan PHP dan MySQL Direkomendasikan. -Masukkan Perbarui Hapus di PHP pada Halaman yang Sama Direkomendasikan. -Cara Mengambil Data Dari Database di PHP menggunakan Ajax Direkomendasikan. -Dapatkan Negara, Kota, lintang, bujur dari alamat IP menggunakan PHP Direkomendasikan. -PHP. Fungsi Meledak dan Meledak Direkomendasikan. -Ajax Image Upload Menggunakan PHP dan jQuery Tanpa Refresh Halaman Direkomendasikan. -Kirim Ulang Kata Sandi Tautan Email PHP Direkomendasikan. -Pangkas dan Simpan Gambar Menggunakan jQuery Croppie dan PHP Direkomendasikan. -PHP Tampilkan Semua Contoh Kesalahan Direkomendasikan. - Contoh Pelengkapan Otomatis Google Places PHP Direkomendasikan. -PHP Pindahkan dan Salin File Dari Satu Folder ke Folder Lain Direkomendasikan. - Contoh Tutorial Pengunggahan File Dropzone PHP Direkomendasikan. -PHP Signature Pad menggunakan Contoh Jquery Ajax Direkomendasikan. -Tutorial Contoh PHP Google Firebase CRUD Direkomendasikan. -PHP Temukan Lokasi Terdekat menggunakan Latitude dan Longitude Contoh |