2014-07-14 78 views
-2

阅读文档后,我试图写下面的源:附表urbanairship推送通知

$contents = array(); 
//$contents['badge'] = "+1"; 
$contents['alert'] = "Touchdown!"; 
//$contents['sound'] = "cat.caf"; 
$notification = array(); 
$notification= $contents; 

$audience['tag'] = "49ers"; 

$scheduled['scheduled_time'] = "2013-04-01T18:45:30"; 

$push['push'] = array("audience"=> $audience, "notification"=>$notification, "device_types"=>"all"); 
$response = array(); 
array_push($response, array("name" => "My schedule", "schedule"=> $scheduled)); 
array_push($response, $push); 


$json = json_encode($response); 
//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_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"; 
print_r($content); 
// Check if any error occured 
$response = curl_getinfo($session); 
if($response['http_code'] != 202) { 
$error = "Got negative response from server: " . $response['http_code'] . "\n"; 
} else { 

    $success = "Message has been sent successfully"; 
} 

我收到错误= 0 谁能帮助我吗?

谢谢。

+1

你调度消息2013 ....我假设需要被预定为将来计划的消息。 – dperconti

+0

感谢您的回复。试图把2016年,但仍然没有工作。在响应代码中获得0。 –

+0

你能否通过Urban Airship获得正常的推送通知? – dperconti

回答

1

我已经在@dperconti的帮助下找到了问题(非常感谢)。

我发布了一个解决方案,“如何安排城市楼梯推送”,以便其他人可能会发现它有帮助。

代码是:

define('APPKEY','xxxx'); // Your App Key 
define('PUSHSECRET', 'xxxx'); // Your Master Secret 
define('PUSHURL', 'https://go.urbanairship.com/api/schedules/'); 

$contents = array(); 
//$contents['badge'] = "+1"; 
$contents['alert'] = "Touchdown!"; 
//$contents['sound'] = "cat.caf"; 
$notification = array(); 
$notification= $contents; 

$audience = "all"; 

$scheduled['scheduled_time'] = "2016-04-01T18:45:30"; 

// $push['push'] = array("audience"=> $audience, "notification"=>$notification, "device_types"=>"all"); 
$response = array(); 
array_push($response, array("name" => "My schedule", "schedule"=> $scheduled, "push" => array("audience"=> $audience, "notification"=>$notification, "device_types"=>"all"))); 
// array_push($response, $push); 


$json = json_encode($response); 
echo "Payload: " . $json . "<br><br><br>"; //show the payload 

$session = curl_init(PUSHURL); 
curl_setopt($session, CURLOPT_USERPWD, APPKEY . ':' . PUSHSECRET); 
curl_setopt($session, CURLOPT_POST, 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"; 
print_r($content); 
// Check if any error occured 
$response = curl_getinfo($session); 
if($response['http_code'] != 202) { 
    $error = "Got negative response from server: " . $response['http_code'] . "\n"; 
} else { 

    $success = "Message has been sent successfully"; 
} 

curl_close($session);