Created
March 13, 2018 19:29
-
-
Save debugsito/4f8b02574817b74a9c63e239889368c6 to your computer and use it in GitHub Desktop.
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(){ | |
$content = array( | |
"en" => 'Mensaje' | |
); | |
$fields = array( | |
'app_id' => "a637b4c4-7a04-4f54-a168-4cdf5b2d94f7", | |
'include_player_ids' => array("c59b1015-3e0e-4bbe-ab6e-20187337f668","76ece62b-bcfe-468c-8a78-839aeaa8c5fa","8e0f21fa-9a5a-4ae7-a9a6-ca1f24294b86"), //estos son los token de los celulares a enviar | |
'data' => array("foo" => "bar"), | |
'headings' => array( | |
"en" => 'Titulo' | |
), | |
'subtitle' => array( | |
"en" => 'Subtitlo' | |
), | |
'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 YzNhY2QyNDctNTAxNi00NWY5LThmOWEtY2YyMGY0MWNkN2Y3')); | |
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