簡體   English   中英

使用 PHP 更改 web 推送通知發送上的 chrome 徽章

[英]Changing the chrome badge on web push notification sending with PHP

我的代碼在更改 web 推送通知上的徽章(小圖標)時遇到問題。

有一個很棒的站點,它顯示了實時示例並顯示了源代碼。 我不明白為什么他可以改變徽章而我沒有。 我在互聯網上進行了廣泛的搜索,但找不到解決方案。

這是我的 PHP 代碼:

<?php
$url = 'https://fcm.googleapis.com/fcm/send';

$YOUR_API_KEY = MY_KEY;

$YOUR_TOKEN_ID = THE_CLIENT_TOKEN;

$request_body = [
    'to' => $YOUR_TOKEN_ID,
    'notification' => [
        'title'         => 'Title test',
        'body'          => 'Body Test',
        'icon'          => 'https://tests.peter.sh/resources/icons/4.png',
        'click_action'  => 'https://www.google.com',
        'badge'         => 'https://i.imgur.com/9QFB20F.png',
        // 'badge'      => 'https://tests.peter.sh/resources/icons/11.png',
    ],
    'data' => [
        // 'Nick'           => 'Mario',
    ],
];

$fields = json_encode($request_body);

$request_headers = [
    'Content-Type: application/json',
    'Authorization: key=' . $YOUR_API_KEY,
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
curl_close($ch);

//echo $response;
?>

當我從“peter.sh”通知生成器站點發送通知時,我得到了這個徽章,就像我想要的一樣(在我的 android 手機上):

peter.sh 網站顯示的徽章,就像我希望它們顯示在我的

但是當我用我的代碼發送它時,我會得到常規的 chrome 徽章

當我無法將它們從 chrome 徽章更改為我的徽章時,我的網站上顯示的徽章

為什么徽章不會根據我的代碼更改? 我正在發送徽章屬性...

請在此處查看有關如何在 chrome PWA 上制作徽章的完整說明。 它指定徽章圖像的圖像格式以及所需的消息負載。 https://stackoverflow.com/a/66688393/11222505

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM