2014-07-14 6 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

.... 내가 예약 된 메시지가 미래를 계획 할 필요가 있으리라 믿고있어. – dperconti

+0

답변 해 주셔서 감사합니다. 2016 년을 열 으려고했지만 여전히 작동하지 않습니다. 응답 코드에서 0을 얻습니다. –

+0

Urban Flyship을 통해 정상적인 푸시 알림을받을 수 있습니까? – dperconti

답변

1

@dperconti의 도움으로 문제를 파악했습니다 (대단히 감사합니다).

다른 사람들이 도움이 될 수 있도록 '도시 계획 추진 계획'에 대한 해결책을 게시하고 있습니다.

코드는 다음과 같습니다 당신은 2013 메시지를 예약하고

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);