50% Off/-

50% Off/-

Php

50% Off/-

50% Off/-

Web

50% Off/-

50% Off/-

OneSignal Push Notification Send to Specific User in PHP

14-05-2017
$content = array(
"en" => $message//mesaj burasi
);
$fields = array(
'app_id' => "e3b90484-e534-4a11-9b87-3b9c2fbd413",
'included_segments' =>  array("Active Users", "Inactive Users"),
'data' => array("foo" => "bar"),
'filters' => array(array('field' => 'tag', 'key' => 'userId', 'relation' => '=', 'value' => $userId)),
'contents' => $content
);

$fields = json_encode($fields);
print("\nJSON sent:\n");
print($fields);

$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 ZjY5MjA3ZGYtYjY2Yy00YjVjJjYjctMzZhMWFiODdmMTEz'));
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);

By using filters parameters stated in line 8, we send notification to only one user with related user id.

© 2019 Tüm Hakları Saklıdır. Codesenior.COM