PHP code example of karunais13 / laravel-onesignal
1. Go to this page and download the library: Download karunais13/laravel-onesignal library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use OneSignal;
$params = [];
$params['android_accent_color'] = 'FFCCAA72'; // argb color value
$params['small_icon'] = 'ic_stat_distriqt_default'; // icon res name specified in your app
$message = "Test message to send";
$segment = "Testers";
OneSignal::addParams($params)->sendNotificationToSegment(
$message,
$segment
);
// or to all users
OneSignal::addParams($params)->sendNotificationToAll($message);
use OneSignal;
$message = "Test message to send";
$segment = "Testers";
OneSignal::setParam('priority', 10)->sendNotificationToSegment(
$message,
$segment
);
// You can chain as many parameters as you wish
OneSignal::setParam('priority', 10)->setParam('small_icon', 'ic_stat_onesignal_default')->setParam('led_color', 'FFAACCAA')->sendNotificationToAll($message);
use OneSignal;
OneSignal::sendNotificationToSegment(
"Test message with custom heading and subtitle",
"Testers",
null, null, null, null,
"Custom Heading",
"Custom subtitle"
);
use OneSignal;
$userId = "3232331-1722-4fee-943d-23123asda123";
$params = [];
$params['$params['contents'] = $contents;
$params['delayed_option'] = "timezone"; // Will deliver on user's timezone
$params['delivery_time_of_day'] = "2:30PM"; // Delivery time
OneSignal::sendNotificationCustom($params);