我想向注册用户发送chrome推送通知。我关注了这个链接https://developers.google.com/web/fundamentals/getting-started/push-notifications/?hl=en开发一个基本的推送通知,效果很好。
现在,我通过在终端中运行带有订阅id的curl脚本来向用户发送通知。使用此功能,我可以向单个用户发送通知。我想发送给多个用户。我怎样才能做到这一点?
试试这个:-
<?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);
?>