用firebase和php推送通知

I have a problem with firebase and php for push notifications the push notification appears on the user mobile but the push itself if clicked on the user mobile does nothing.

I expect it to lead to the page of the content but the push doesnt get to the user

var config = {
    apiKey: "AIzaSyAXavmNUsgT7UgRIQEdweFXIhBrYTGPvOY",
    authDomain: "tech-miz.firebaseapp.com",
    databaseURL: "https://tech-miz.firebaseio.com",
    projectId: "tech-miz",
    storageBucket: "tech-miz.appspot.com",
    messagingSenderId: "942114086591"
};

firebase.initializeApp(config);
// Retrieve Firebase Messaging object.
const messaging = firebase.messaging();
messaging.requestPermission()
.then(function() {
    console.log('Notification permission granted.');
    // TODO(developer): Retrieve an Instance ID token for use with FCM.
    /*if(isTokenSentToServer()){
        console.log("Token already saved");

    } else {
        getRegToken();
    }*/
    getRegToken();
})
.catch(function(err) {
    console.log('Unable to get permission to notify.', err);
});

function getRegToken() {
    // Get Instance ID token. Initially this makes a network call, once retrieved
    // subsequent calls to getToken will return from cache.
    messaging.getToken()
    .then(function(currentToken) {
        if (currentToken) {
        //sendTokenToServer(currentToken);
        // console.log(currentToken);

        saveToken(currentToken);
        setTokenSentToServer(true);
        //updateUIForPushEnabled(currentToken);
        } else {
            // Show permission request.
            console.log('No Instance ID token available. Request permission to generate one.');
        // Show permission UI.
            setTokenSentToServer(false);
        }
    })
    .catch(function(err) {
        console.log('An error occurred while retrieving token. ', err);
        // showToken('Error retrieving Instance ID token. ', err);
        setTokenSentToServer(false);
    });
}

function setTokenSentToServer(sent) {
    window.localStorage.setItem('sentToServer', sent ? 1 : 0);
}
function isTokenSentToServer() {
    return window.localStorage.getItem('sentToServer') == 1;
}
function saveToken(currentToken){
   $.ajax({
       type: "POST",
       url: "blog/ajax/save.push.notification.php",
       data: "token=" + currentToken,
       success: function (response) {
           console.log(response);
       }
   });
}

I need the push notification to be clickable and lead the user to the page where the push notification is notifying the user about

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐