Skip to content

Instantly share code, notes, and snippets.

@jonathanlking
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanlking/8966085 to your computer and use it in GitHub Desktop.
Save jonathanlking/8966085 to your computer and use it in GitHub Desktop.
<?php
function sendNotification($title,$body)
{
$AppKey = "YourUrbanAirshipAppKey";
$MasterSecret = "YourUrbanAirshipMasterSecret";
$request = curl_init();
curl_setopt($request, CURLOPT_URL, "https://go.urbanairship.com/api/push/");
curl_setopt($request, CURLOPT_USERPWD, "<$AppKey>:<$MasterSecret>");
curl_setopt($request, CURLOPT_HTTPHEADER, array(
"Content-type: application/json",
"Accept: application/vnd.urbanairship+json; version=3;"
));
curl_setopt($request, CURLOPT_POSTFIELDS, '{"audience" : "all", "device_types" : "all", "notification" : {"$title": "$body"} }');
curl_setopt($request, CURLOPT_RETURNTRANSFER, TRUE);
$responce = curl_exec($request);
// Probably should check the responce code, to make sure it has gone through fine.
curl_close($request);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
$phoneNumber = $_POST["From"];
$body = $_POST["Body"];
// Send Push Notification
sendNotification("Alert!",$body);
// Log the SMS event
$dateStamp = date("F j, Y, g:i a");
$log = "SMS Received - $dateStamp - From $phoneNumber - '$body' \n\n";
file_put_contents('sms.log', $log, FILE_APPEND);
}
else if ($_SERVER['REQUEST_METHOD'] === 'GET')
{
$file = file_get_contents('sms.log', FILE_USE_INCLUDE_PATH);
echo($file);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment