OneSignal推送通知发送给所有用户,而不是一个玩家



我正试图通过存储在数据库中的player_id向一台设备发送推送通知。但抱怨它尝试不断发送给所有用户我不知道我的代码出了什么问题

$fields = array(
'app_id' => 'XXXXXXXXXXXXXXXXXXXX',
'include_player_ids ' => $player_ids,
'included_segments' => array(
'All'
),
'data' => $data,
'headings' => $title,
'contents' => $content,
'web_buttons' => []
);
$fields = json_encode($fields);
if($player_ids) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);

只删除'included_segments' => array('All'),

如果您同时填写included_segmentsinclude_player_ids,您将向所有选定的玩家ID以及所有选定的分段发送。分段All表示所有订户。

你可以阅读官方文件上的其他选项

我需要删除included_segmentsweb_buttons它们不仅仅是included_segments,当我试图删除included_segments时,它会给我{"errors":["You must include which players, segments, or tags you wish to send this notification to."]}的错误我也不需要'Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

最新更新