Last active
April 14, 2025 07:07
OneSignal APi php kısmı
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$message="There is new news "; | |
$apiKey ="xxxx";//one signal api key | |
$AppID = "xxxx";////one signal api id | |
$content = array( | |
"en" => $message , | |
"tr" => $message | |
); | |
$fields = array( | |
'app_id' => $AppID, | |
'filters' => array(array("field" => "tag", "key" => "user_id", "relation" => "=", "value" => 10)), | |
//"value" => 10 kısmına mysql de bulunana user id yi de atayabilirsiniz | |
'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 ' . $apiKey . '')); | |
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); | |
} | |
// "value" => 10 yazan kısmı herkese farklı id vermek için kullanabilirsiniz. | |
//bu durumda OneSignalNotfiy.html dosyasında "user_id",10, yazan yeri değiştirmk gerekiyor. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment