Этот код в PHP, Urbanairship
, curl
работал для меня:
define ('URBAN_APP_MASTERKEY', XXXXXX);
define ('URBAN_APIKEY',XXXXX);
define ('URBAN_APP_SECRETKEY',XXXXXX);
define('PUSHURL', 'https://go.urbanairship.com/api/push/');
$contents = array();
$contents['badge'] = "1";
$contents['alert'] = "Howdy, doody";
$contents['sound'] = "cat.caf";
$devices = array('device_tokens');
$push = array("aps" => $contents);
$push['device_tokens'] = $devices;
$json = json_encode($push);
$url = PUSHURL;
echo $json; //display the actual content
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, URBAN_APIKEY . ':' . URBAN_APP_MASTERKEY);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
$output = curl_exec($ch);
if($response['http_code'] != 200)
{
echo "Got negative response from server, http code: ".
$response['http_code'] . "\n";
}
else
{
echo "Wow, it worked!\n";
}
curl_close($ch);