send notification to all users php

Admin
1 minute read
0

 


Topic according send all device push notification in php simple one page code.


            $title = "send title here";

            $image =base_url().'/public/uploads/news/'.$result['path'];
            $topic ="news"; // news | all
            $API_ACCESS_KEY = 'AAAAIjwpj4Y:APA91bF00KkPSL5Y8Y2bmsqHTOc1JZRSO5t6urNeCmq2GB3M3BT4_s0rwEIofmcvWZvykey9r84a68GNqzPaqwiupO0JFuRlrPDjI-bbJxt4GFthM2VKri2C5qY3nYrc_RmLt8ICunNU';
            $msg = array
            (
                'title' => $title,
                'body' => '',
                'image' => $image
            );

$fields = array('to' => '/topics/' . $topic, 'priority' => 'high', 'data' => $msg);
$headers = array
(
'Authorization: key=' . $API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
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));
$pushResult = curl_exec($ch);
curl_close($ch);
 
 
    
  echo 'Notification Successfully Sent.';
  
    
   

Post a Comment

0 Comments
Post a Comment (0)
Our website uses cookies to fast experience.
Accept !