2014-07-14 80 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);