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



我的代码在更改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网站显示的徽章,正如我希望它们显示在我的上一样

但当我把它和我的代码一起发送时,我会得到常规铬徽章

当我无法将徽章从铬徽章更改为我的时,我的网站上显示的徽章

为什么徽章不按我的代码更改?我正在发送徽章属性。。。

请参阅此处,了解如何在镀铬PWA上制作徽章的完整说明。它指定徽章图像的图像格式以及所需的消息有效载荷。https://stackoverflow.com/a/66688393/11222505

最新更新