Skip to content

Instantly share code, notes, and snippets.

@stnc
Last active February 7, 2018 12:43
Show Gist options
  • Save stnc/e0758f7e2291f54e433c595a92d6b4f8 to your computer and use it in GitHub Desktop.
Save stnc/e0758f7e2291f54e433c595a92d6b4f8 to your computer and use it in GitHub Desktop.
OneSignal APi php kısmı
<?php
$message="Türkiye ile ABD savaşa girecek mi ?";
$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