【问题标题】:web push notification body not displaying网络推送通知正文未显示
【发布时间】:2019-08-06 11:20:30
【问题描述】:

我正在使用 php web push 发送通知

这里是php代码

$notifContent888 = array(
       'title' => 'test tiltle',
       'body' => 'This is the body content',
       'icon' => 'https://png.pngtree.com/element_origin_min_pic/16/08/05/1057a3fae73b91b.jpg',
);


$pay_load9988=json_encode($notifContent888);

$subscription_new = Subscription::create([
                'endpoint' => $endpoint,
                'publicKey' => $publicKey_99,
                'authToken' => $authToken,
                'contentEncoding' => $contentEncoding,
]);

$webPush = new WebPush($auth);

$webPush->sendNotification($subscription_new, $pay_load9988, true);

这里是 service worker js 部分

if (event.data) {
    var payload = event.data.json();
    var title = payload.title;
    var body  = payload.body;
    var icon  = payload.icon;
    console.log(payload); 
    event.waitUntil(sendNotification(title, {
        body: body,
        icon: icon,
        data: {} 
}

我可以在 console.log 中看到所有数据都很好,但我只收到默认标题和正文的通知,并且不显示图标。我可以在控制台中看到正文和图标,如果我用正文替换标题,我可以看到正文内容,但我不知道只有一部分发生了什么我只能通过有效负载发送通知的第一部分,无论我在 sendNotification 之后提到什么(标题

这里只有标题

找出错误的任何帮助都会很棒。这是payload的加密问题吗??

【问题讨论】:

    标签: php push-notification


    【解决方案1】:

    使用sendNotification 时,您不需要加密数据,因为sendNotification 已经为您加密了。见:https://www.npmjs.com/package/web-push

    所以你应该像这样改变你的代码:

    $notifContent888 = array(
           'title' => 'test tiltle',
           'body' => 'This is the body content',
           'icon' => 'https://png.pngtree.com/element_origin_min_pic/16/08/05/1057a3fae73b91b.jpg',
    );
    
    $subscription_new = Subscription::create([
                    'endpoint' => $endpoint,
                    'publicKey' => $publicKey_99,
                    'authToken' => $authToken,
                    'contentEncoding' => $contentEncoding,
    ]);
    
    $webPush = new WebPush($auth);
    
    $webPush->sendNotification($subscription_new, $notifContent888, true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-22
      • 2019-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多