【问题标题】:How to implement web push notifications using FCM in php如何在 php 中使用 FCM 实现 Web 推送通知
【发布时间】:2017-01-12 22:02:04
【问题描述】:

我正在使用 Service Worker 处理网络推送通知。但是我在使用 FCM(Firebase 云消息传递)从服务器发送通知时感到震惊。这是我的 php 脚本,我不知道应该如何在服务人员中调用它。请指导我。

define( 'API_ACCESS_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$msg = array(
               'message'       => 'Wakeup Wakeup!!',
               'title'         => 'Wakeup call !',
            );
$fields = array(
          'registration_id'  => xxxxxxxxxx,
          'data'              => $msg
         );
$headers = array
           (
            'Authorization: key=' . API_ACCESS_KEY,
            'Content-Type: application/json'
            );

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, '//gcm-http.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;

【问题讨论】:

    标签: php push-notification service-worker


    【解决方案1】:

    您可以使用web-push library for PHP,顾名思义,它可以更轻松地通过 PHP 使用 Web Push 协议。

    【讨论】:

    • 我已经看过了,但我不知道如何使用它
    • 你是怎么用这个的?
    • 您可以按照存储库自述文件中的文档,从“需求”段落开始,然后是“安装”,然后是“使用”。
    猜你喜欢
    • 1970-01-01
    • 2022-07-18
    • 2013-12-05
    • 2017-11-12
    • 2020-07-10
    • 1970-01-01
    • 2018-01-14
    • 1970-01-01
    • 2021-09-14
    相关资源
    最近更新 更多