我使用FCM创建了一个应用程序,每当我输入消息并点击发送时就会生成推送通知。现在我想要的不是点击发送,我想从数据库中获取一个值,然后将该值与原始时间进行比较,当它们变得相同时,它会生成一个通知。我想知道是否可以这样做?如果是,我认为应该是。怎么样?
这是用于发送推送通知的PHP代码:
<?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);
?>