首页 > 解决方案 > 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);

标签: phplaravelpush-notificationonesignal

解决方案


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

如果您同时填写included_segmentsinclude_player_ids,您将发送给所有选定的玩家 id 以及所有选定的段。细分All是指所有订阅者。

您可以阅读官方文档中的其他选项


推荐阅读