php - 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_segments
和include_player_ids
,您将发送给所有选定的玩家 id 以及所有选定的段。细分All
是指所有订阅者。
您可以阅读官方文档中的其他选项
推荐阅读
- github - 用于在 GitHub Desktop 中克隆存储库的 URL
- api - 如何在第一次迭代时测试 Postman 请求正文中未定义的分页变量?
- linux - sh:python3:不允许操作(kubernetes)
- php - 使用机车滚动后无法向下滚动
- node.js - 无法在 cPanel 上部署 Nodeapp
- r - menu() 不能在 R 中以非交互方式使用
- regex - 正则表达式通过删除模式(如果存在于末尾)来提取
- csv - 从 Google 表格中的在线 CSV 文件中检索特定或查询数据,而无需将整个 CSV 数据添加到表格中
- c++ - 链接:致命错误 LNK1104:无法打开文件 'external\jpeg-9d\Debug\jpeg.lib'
- rust - Rust 中双引号和单引号的区别