Firebase fcm web推送通知-未打开url(使用单击操作)

Firebase fcm web推送通知-未打开url(使用单击操作),firebase,firebase-cloud-messaging,web-push,Firebase,Firebase Cloud Messaging,Web Push,如标题中所述,我无法在单击通知时重定向到url。这是我的密码。 //Index.php <html> <meta charset="utf-8"/> <title>Firebase Messaging </title> <link rel="manifest" href="manifest.json"> <script src="https://code.jquery.com/jquery-3.3.1.min.js"&g

如标题中所述,我无法在单击通知时重定向到url。这是我的密码。 //Index.php

 <html>
 <meta charset="utf-8"/>
 <title>Firebase Messaging </title>
 <link rel="manifest" href="manifest.json">
 <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
 <style>
    div {
       margin-bottom: 15px;
       }
 </style>
 <body>
 <div id="token"></div>
 <div id="msg"></div>
 <div id="notis"></div>
 <div id="err"></div>
 <script src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script>
 <script>
    MsgElem = document.getElementById("msg")
    TokenElem = document.getElementById("token")
    NotisElem = document.getElementById("notis")
    ErrElem = document.getElementById("err")
    var config = {
        //some PRIVATE value
      };
      firebase.initializeApp(config);
    const messaging = firebase.messaging();
    messaging
        .requestPermission()
        .then(function () {
            console.log("Notification permission granted.");


            return messaging.getToken()
        })
        .then(function(token) {
            sendToken(token);
            setTokenSentToServer(true);
        })
        .catch(function (err) {
            ErrElem.innerHTML =  ErrElem.innerHTML + "; " + err
            console.log("Unable to get permission to notify.", err);
        });
        messaging.onMessage(function(payload) {
        console.log("Message received. ", payload);
        notificationTitle = payload.data.title;
        notificationOptions = {
            body: payload.data.body,
            icon: payload.data.icon,
            click_action: payload.data.url,
            };
       var notification= new 
   Notification(notificationTitle,notificationOptions);
        });
    function setTokenSentToServer(sent)
    {
        window.localStorage.setItem('sentToServer', sent ? 1 : 0);
    }
    //this is ajax to send token to send.php
    function sendToken(token)
    {
        $.ajax({
            url: 'action.php',
            method: 'POST',
            data: 'tokens=' + token,
            }).done(function(result){
            console.log(result);
            })

    }
   </script>
    </body>
 </html>
通知进展得很顺利,但每当我点击它时,它都不会重定向。有人能帮我解决这个问题吗。 提前谢谢

   <?php
 if(isset($_POST['tokens']))
      { if(isset($_COOKIE["tokens"]))
        {$tokens=$_POST['tokens'];
      }
 else
     {
         $tokens=$_POST['tokens'];
         setcookie("tokens", $tokens, time() + (86400 * 30), "/");
      }

   }
  header("Location: send.php");
 ?>
<?php
$tokens= array($_COOKIE["tokens"]);

$msg=[
'title'=>'Title',
'body'=>'description.',
'icon'=>'logo.jpg',
'url'=>"https://google.com"
 ];
 $payload=[
 'registration_ids'=>$tokens,
 'data'=>$msg
 ];
 $curl = curl_init();

  curl_setopt_array($curl, array(
  CURLOPT_URL => "https://fcm.googleapis.com/fcm/send",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS =>json_encode($payload),
  CURLOPT_HTTPHEADER => array(
      "authorization: key=/*the key*/",
       "cache-control: no-cache",
       "content-type: application/json",

  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} 
else
echo $response;

?> 
   importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-app.js');
   importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase- 
messaging.js');

// Initialize the Firebase app in the service worker by passing in the
// messagingSenderId.
   firebase.initializeApp({
   'messagingSenderId': 'MY_SENDER_ID'
     });
// Retrieve an instance of Firebase Messaging so that it can handle background
 // messages.
   const messaging = firebase.messaging();
  messaging.setBackgroundMessageHandler(function(payload) {
  console.log('[firebase-messaging-sw.js] Received background message ',payload);
  // Customize notification here
  const notificationTitle = payload.data.title;
  const notificationOptions = {
   body: payload.data.body,
   icon: payload.data.icon,
   click_action: payload.data.url,
  };

  return self.registration.showNotification(notificationTitle,
  notificationOptions);
  });