一个信号通过api发送通知

时间:2021-01-01 18:18:25

标签: php laravel push-notification notifications onesignal

我想通过 api 添加一个设备(用户)。用户已成功插入一个信号,但是当我尝试发送通知时,该用户或通过 API 添加的所有用户正在接收任何通知。 这是添加设备(用户)的代码:

$fields = [
            'app_id' => "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
            'device_type'  => 5,
            'identifier'   => 'ce777617da7f548fe7a9ab6febb56cf39fba6d382000c0395666288d961ee566',
            'timezone'     => '18000',
            'game_version' => '1.1',
            'device_os'    => '87',
            'device_model' => "Win32",
            'sdk' => "151105",
            ];

        $fields = json_encode($fields);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/players");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        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);

但是当通过一个信号中的默认订阅按钮添加设备(用户),然后通过 API 向该设备发送通知时,它收到通知。

这里是我保存的两个设备参数 第一个是通过不工作的 API,第二个是通过默认的 javascript 订阅按钮工作

(
                    [id] => xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx
                    [identifier] => YjYyNzliZWYtMjJhNC00M2JhLThlYmQtNjY2ZjcyYmFmMzc5
                    [session_count] => 1
                    [language] => en
                    [timezone] => 18000
                    [game_version] => 1.1
                    [device_os] => 87
                    [device_type] => 5
                    [device_model] => Win32
                    [ad_id] => 
                    [tags] => Array
                        (
                        )

                    [last_active] => 1609523086
                    [playtime] => 0
                    [amount_spent] => 0
                    [created_at] => 1609523086
                    [invalid_identifier] => 
                    [badge_count] => 0
                    [sdk] => 151105
                    [test_type] => 
                    [ip] => 39.37.185.28
                    [external_user_id] => 
                )

         

(
                [id] => xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx
                [identifier] => https://fcm.googleapis.com/fcm/send/e08NnzE3H40:APA91bGy3BnmRPDkEGDMH_33GgZBaDxYbdCxr17dIml1iJyn0VtWovlIgNS9Zq1yJZPCUSN-HEyGkVHashrZk_dNAmSgKKjXOxDs7xP2xPAOOedmZicwGaWx3fugd2Fov0ZZNR40hQw_
                [session_count] => 1
                [language] => en
                [timezone] => 18000
                [game_version] => 
                [device_os] => 87
                [device_type] => 5
                [device_model] => Win32
                [ad_id] => 
                [tags] => Array
                    (
                    )

                [last_active] => 1609523217
                [playtime] => 0
                [amount_spent] => 0
                [created_at] => 1609523217
                [invalid_identifier] => 
                [badge_count] => 0
                [sdk] => 151105
                [test_type] => 
                [ip] => 39.37.185.28
                [external_user_id] => 
            )

1 个答案:

答案 0 :(得分:0)

使用 Laravel 通知渠道来帮助你解决这个问题。您可以使用 OneSignal 渠道访问 OneSignal API。

https://laravel-notification-channels.com/onesignal/