У меня есть следующий код для отправки push-уведомлений на устройства iOS.
Я использовал php, я получаю сообщение «Уведомление отправлено», но не могу получить уведомление,
есть ли ошибка в моем коде,
<?php
define('APPKEY','xxxxxxxxxxxxxxxxxx');define('PUSHSECRET','xxxxxxxxxxxxxxxxxxx');
define('PUSHURL', 'https://go.urbanairship.com/api/push/');class PushNotification {
public function api($devicetokens,$messages,$devicename){$contents = array();
$contents['alert'] = $messages;
$notification = array();
$platform = array();
$devicetoken = array();
if($devicename ==1){
array_push($platform, "ios");
$notification['ios'] = $contents;
$devicetoken['device_token'] = $devicetokens;
$push = array("audience"=>$devicetoken, "notification"=>$notification, "device_types"=>$platform);
}else{
array_push($platform, "android");
$notification['android'] = $contents;
$devicetoken['apid'] = $devicetokens;
$push = array("audience"=>$devicetoken, "notification"=>$notification, "device_types"=>$platform);
}
$json = json_encode($push);
//echo "Payload: " . $json . "\n"; //show the payload
$session = curl_init(PUSHURL);
curl_setopt($session, CURLOPT_USERPWD, APPKEY . ':' . PUSHSECRET);
curl_setopt($session, CURLOPT_POST, True);
curl_setopt($session, CURLOPT_VERBOSE, True);
curl_setopt($session, CURLOPT_POSTFIELDS, $json);
curl_setopt($session, CURLOPT_HEADER, False);
curl_setopt($session, CURLOPT_RETURNTRANSFER, True);
curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'Accept: application/vnd.urbanairship+json; version=3;'));
$content = curl_exec($session);
// echo "Response: " . $content . "\n";
// Check if any error occured
$response = curl_getinfo($session);
if($response['http_code'] != 202) {
echo "Got negative response from server: " . $response['http_code'] . "\n";
} else {
echo "notification has been sent";
}
curl_close($session);
}
}
?>
и $ response выведите следующее
array(
'url' => 'https://go.urbanairship.com/api/push/',
'content_type' => 'application/vnd.urbanairship+json; version=3',
'http_code' => (int) 202,
'header_size' => (int) 375,
'request_size' => (int) 427,
'filetime' => (int) -1,
'ssl_verify_result' => (int) 0,
'redirect_count' => (int) 0,
'total_time' => (float) 0.030794,
'namelookup_time' => (float) 0.002246,
'connect_time' => (float) 0.003368,
'pretransfer_time' => (float) 0.017076,
'size_upload' => (float) 182,
'size_download' => (float) 152,
'speed_download' => (float) 4936,
'speed_upload' => (float) 5910,
'download_content_length' => (float) -1,
'upload_content_length' => (float) 0,
'starttransfer_time' => (float) 0.030735,
'redirect_time' => (float) 0,
'redirect_url' => '',
'certinfo' => array()
)
Задача ещё не решена.
Других решений пока нет …