Skip to content

Instantly share code, notes, and snippets.

@jonathanlking

jonathanlking/SMSPush

Last active Aug 29, 2015
Embed
What would you like to do?
<?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