Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中使用ChromePushNotification_Php_Google Chrome Extension_Push Notification - Fatal编程技术网

如何在PHP中使用ChromePushNotification

如何在PHP中使用ChromePushNotification,php,google-chrome-extension,push-notification,Php,Google Chrome Extension,Push Notification,我需要向用户推送通知,当新任务分配给用户时,我计划使用“ChomePushNotification”,但我不知道如何在php中使用它来调用通知 有谁能给我一个如何在PHP中使用它的概述,如果一条记录插入到一个带有agent_id=123的表“Task”中,我需要向用户“123”发送通知“新任务分配…”第一步是使用javascript为用户提供订阅推送通知的选项 if ('serviceWorker' in navigator) { console.log('Service Worker

我需要向用户推送通知,当新任务分配给用户时,我计划使用“ChomePushNotification”,但我不知道如何在php中使用它来调用通知


有谁能给我一个如何在PHP中使用它的概述,如果一条记录插入到一个带有agent_id=123的表“Task”中,我需要向用户“123”发送通知“新任务分配…”

第一步是使用javascript为用户提供订阅推送通知的选项

if ('serviceWorker' in navigator) {
    console.log('Service Worker is supported');
    navigator.serviceWorker.register('sw.js').then(function(reg) {
        console.log(':^)', reg);
        reg.pushManager.subscribe({
            userVisibleOnly: true
        }).then(function(sub) {
            console.log('endpoint:', sub.endpoint);
        });
    }).catch(function(error) {
        console.log(':^(', error);
    });
}
下一步是使用cURL,使用以下cURL命令将请求发送到Google,可以从命令行发送,也可以将其外推到PHP cURL命令中

curl --header "Authorization: key=AIzaSyAc2e8MeZHA5NfhPANea01wnyeQD7uVY0c" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration\_ids\":[\"APA91bE9DAy6\_p9bZ9I58rixOv-ya6PsNMi9Nh5VfV4lpXGw1wS6kxrkQbowwBu17ryjGO0ExDlp-S-mCiwKc5HmVNbyVfylhgwITXBYsmSszpK0LpCxr9Cc3RgxqZD7614SqDokwsc3vIEXkaT8OPIM-mnGMRYG1-hsarEU4coJWNjdFP16gWs\"]}"
请注意,cURL示例直接取自的Google开发者页面,并使用了他们的示例哈希和键

有关更多信息,您可以通过查看Google文档查看如何发送推送通知的详细信息,网址为