Last active
August 29, 2015 13:56
-
-
Save jonathanlking/8966085 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 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