2

I made an application using FCM where a push notification is generated everytime I typed in message and hit send. now what I want is instead of hitting send, I want to fetch a value from the database and then compare that value with orginal time and when they become same, it generates a notification.I want to know is it possible to do so? and if it is, which i think should be. then how?

this is php code for sending push notification:

<?php

require "connection.php";
$message = $_POST['message'];
$title = $_POST['title'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "*******mykey***********";
$sql = "select fcm_token from lociinfo";
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_row($result);
$key = $row[0];


$headers = array(
              'Authorization:key=' .$server_key,
              'content-Type:application/json'
                );

$fields = array('to' =>$key , 'notification'=>array('title'=> $title,
                                  'body'=>$message));

$payload = json_encode($fields);

$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL , $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);


$result = curl_exec($curl_session);
mysqli_close($conn);
?>
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
shahtaj khalid
  • 476
  • 7
  • 24

0 Answers0