【问题标题】:Changing the chrome badge on web push notification sending with PHP使用 PHP 更改 Web 推送通知发送上的 chrome 徽章
【发布时间】:2020-07-31 01:08:07
【问题描述】:

我的代码在更改网络推送通知上的徽章(小图标)时遇到问题。

this wonderful site 显示了实时示例并显示了源代码。 我不明白为什么他能改变徽章而我没有。我在 Internet 上进行了广泛搜索,但找不到解决方案。

这是我的 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 手机上):

The badges as shown by peter.sh site, and just as I want them to be displayed on mine

但是当我将它与我的代码一起发送时,我会得到 常规 chrome 徽章

The badges as shown on my site when I can't change them from chrome badges to mine

为什么徽章没有根据我的代码改变?我正在发送徽章属性...

【问题讨论】:

  • 您是否尝试过使用其他图像?您是否尝试在您的域中托管图像?
  • 是的。就像你在我的代码中看到的那样,我尝试了一些 url-s...
  • 有人可以帮忙吗? ://
  • 你解决了吗?
  • 不……还没有……:(……

标签: javascript php firebase curl service-worker


【解决方案1】:

请在此处查看有关如何使 chrome PWA 上的徽章工作的完整说明。它指定徽章图像的图像格式以及所需的消息负载。 https://stackoverflow.com/a/66688393/11222505

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 2014-05-06
    • 2012-04-02
    • 1970-01-01
    • 2012-06-24
    相关资源
    最近更新 更多