Created
August 16, 2018 06:26
-
-
Save Mohsen322/0532f04e7ebe53bce4359538ec49e51d to your computer and use it in GitHub Desktop.
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
class OneSignal | |
{ | |
private $rest_key = 'YOUR_REST_KEY'; | |
private $app_id = 'YOUR_APP_ID'; | |
function lunchCURL($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', | |
'Authorization: Basic '.$this->rest_key)); | |
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); | |
return $response; | |
} | |
function sendPushToSingleUser($gcm_id, $notif_title, $notif_text){ | |
$app_id = $this->app_id; | |
$headings = array( // heading = Notification title | |
"en" => $notif_title | |
); | |
$contents = array( // content = Notification text - Alert | |
"en" => $notif_text | |
); | |
$fields = array( | |
'app_id' => $app_id, | |
'include_player_ids' => [$gcm_id], | |
'headings' => $headings, | |
'contents' => $contents | |
); | |
$fields = json_encode($fields); | |
return $this->lunchCURL($fields); //CURL | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment