如何将Chrome推送通知发送到多个设备

时间:2016-05-18 07:59:40

标签: php push-notification google-cloud-messaging chrome-gcm

我想向注册用户发送Chrome推送通知。我按照此链接https://developers.google.com/web/fundamentals/getting-started/push-notifications/?hl=en开发基本推送通知,它运行正常。

目前,我正在通过在终端中运行带有订阅ID的curl脚本向用户发送通知。使用此功能,我可以向单个用户发送通知。我想发送给多个用户。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:2)

试试这个: -

<?php

$data = ["registration_ids" => ["regid1","regid2",...,"regidn"]];
    $dataString = json_encode($data);

    $curl = curl_init('https://android.googleapis.com/gcm/send');
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($curl, CURLOPT_POSTFIELDS, $dataString);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json',
        'Authorization: key=YOUR_API_KEY'   
    ]);

    $result = curl_exec($curl);
    print_r($result);
        ?>