PHP FCM push notification URL parameter cached Android

Viewed 14

I am using PHP to send push notifications via Firebase Cloud Messaging.

The URL of the payload changes depending on the parameters sent by the app to the PHP page. When the notification comes in and the user clicks it, it opens a browser with the URL sent to FCM via the PHP script below. However, every subsequent notification contains the identical URL - it does not change, even though the PHP script below receives a different URL. I have tried blocking caching using the typical PHP headers, but no luck.

<?php

function sendFCM() {

$url = "https://fcm.googleapis.com/fcm/send";
$token = $_GET['token'];
$type = $_GET['type'];
$id = $_GET['postID'];
$user = $_GET['user'];
$serverKey = '<api>';
$title = "Title";

if($type == "post")
{
    $body = "Somebody liked your post.";
}

if($type == "comment")
{
    $body = "Somebody commented on your post.";
}

$notification = array('title' =>$title , 'body' => $body, 'url' => 'https://www.example.com/specificPost?postID=' . $id . "&this=" . $user, 'icon' => 'logo');
$arrayToSend = array('to' => $token, 'data' => $notification, 'priority'=>'high');
$json = json_encode($arrayToSend);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: key='. $serverKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
//Send the request
$response = curl_exec($ch);
//Close request
if ($response === FALSE) {
die('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
}
?>

Here is the JS script calling the PHP code:

async function sendrequest(reportedUser, type, postID)
{

let { data, getTokenerror } = await supabase
  .from('users')
  .select('token')
  .match({email: reportedUser})
 
   fetch("https://locationofPHPCode.com/testpush.php?token=" + data[0].token + "&type=" + type + 
  "&postID=" + postID + "&user=" + emailAuth, {
   method: 'post',
   body: JSON.stringify("token"),
   mode: 'no-cors'
   }).then(data => {

   });

   }

Can somebody illuminate why the push notifications are behaving in this way?

0 Answers
Related