Skip to content

Instantly share code, notes, and snippets.

@mmohiudd
Created July 27, 2012 16:49
Show Gist options
  • Save mmohiudd/3189102 to your computer and use it in GitHub Desktop.
Save mmohiudd/3189102 to your computer and use it in GitHub Desktop.
Urban Airship test script
<?php
send_push($_REQUEST['alert'], $_REQUEST['appkey'], $_REQUEST['appmaster']);
function send_push($alert, $appkey, $appmaster) {
$badge = 1; // default is 1
$auth = $appkey . ":" . $appmaster;
$url = "https://go.urbanairship.com/api/push/broadcast/";
$data_string = json_encode(array(
"aps" => array(
"badge" => (int)$badge,
"alert" => $alert,
"sound" => "default"
),
"android" => array(
"alert" => $alert
),
"blackberry" => array(
"content-type"=> "text/plain",
"body"=> $alert
)
)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $auth);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$xmlResponse = curl_exec($ch);
curl_close($ch);
echo $xmlResponse;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment