arrow_upward

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to develop Push Notification in PHP?
#7
If you are using Firebase push notification to send a notification in android then you can use this code.


PHP Code: (Select All)
<?php

function sendMessage($data$target$serverKey){
   //FCM api URL
   $rsp = [];
   $url 'https://fcm.googleapis.com/fcm/send';
   //api_key available in Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key
   $server_key $serverKey;
   $fields = array();
   $fields['data'] = $data;
   if(is_array($target)){
           $fields['registration_ids'] = $target;
       }else{
           $fields['to'] = $target;
   }
   //header with content_type api key
   $headers = array(
       'Content-Type:application/json',
       'Authorization:key='.$server_key
   
);
   
   $ch 
curl_init();
   curl_setopt($chCURLOPT_URL$url);
   curl_setopt($chCURLOPT_POSTtrue);
   curl_setopt($chCURLOPT_HTTPHEADER$headers);
   curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
   curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
   curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
   curl_setopt($chCURLOPT_POSTFIELDSjson_encode($fields));
   $result curl_exec($ch);
   if ($result === FALSE) {
       //die('FCM Send Error: ' . curl_error($ch));
   }
   curl_close($ch);
   
   
//print_r($result);
   return $result;


You can find complete tutorial to send Firebase push notification android


Messages In This Thread
RE: How to develop Push Notification in PHP? - by anehthakur - 03-26-2020, 03:15 AM

person_pin_circle Users browsing this thread: 1 Guest(s)
Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - Hyper Expert - Shadow Hosting - Bladenode - Hostlease - RackNerd - ReadyDedis - Limitless Hosting