1

我想向注册用户发送 chrome 推送通知。我按照这个链接https://developers.google.com/web/fundamentals/getting-started/push-notifications/?hl=en开发了一个基本的推送通知和它工作正常。

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

4

1 回答 1

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);
        ?>
于 2016-05-18T11:55:36.607 回答