【问题标题】:Schedule urbanairship push notification安排urbanairship推送通知
【发布时间】:2014-07-14 06:53:40
【问题描述】:

阅读文档后,我尝试编写以下源代码:

$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。 谁能帮帮我?

谢谢。

【问题讨论】:

  • 您正在为 2013 年安排消息......我假设计划的消息需要安排在未来。
  • 感谢您的回复。试图把 2016 年,但仍然无法正常工作。在响应代码中获取 0。
  • 您能否通过 Urban Airship 获得正常的推送通知?
  • 是的,正常推送工作正常。
  • @dperconti 非常感谢它对我的帮助很大。

标签: php urbanairship.com


【解决方案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);

【讨论】:

    猜你喜欢
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多