Created
October 6, 2016 00:55
-
-
Save JKalash/838b8c860df5a1e4c22f183681fd4d9f to your computer and use it in GitHub Desktop.
Sample Push
This file contains 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 | |
function sendMessage(){ | |
$text = "Hello Message"; | |
$content = array("en" => $text); | |
$fields = array( | |
'app_id' => "9df877a0-ceed-4a6f-8237-a62364d3babf", | |
'included_segments' => array('All'), | |
'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 ZDg1ZjBhOGMtYTc2Ny00MTJjLWFhYjYtNmNkYTI4MzE5ODc3')); | |
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; | |
} | |
$response = sendMessage(); | |
$return["allresponses"] = $response; | |
$return = json_encode( $return); | |
print("\n\nJSON received:\n"); | |
print($return); | |
print("\n"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment