簡體   English   中英

PhoneGap-Android:從我的服務器通過Urban Airship推送通知

[英]PhoneGap-Android: Push Notification by Urban Airship from my server

我在Android PhoneGap應用程序中工作,我需要使用push notification by Urban Airship 我在我的應用程序中集成了( Development+Debug )Urban Airship推送通知,並從Urban Airship網站發送測試推送,並成功接收推送到所有設備。

但是我需要從我的windows(IIS installed) server(push text and sent time will vary upon server time)發送推送通知windows(IIS installed) server(push text and sent time will vary upon server time) 我想根據我的schedule task發送推文。 計划任務由PHP代碼完成。

那么,任何線索或想法如何以適當的時間表從我的服務器發送推送通知?

提前致謝。

如果您可以在您的服務器上運行PHP,請按照此文檔將您帶到那里 - Urban Airship Simple PHP我已經使用過它並且效果很好!

您需要將其中的大部分內容包含在一個函數中,然后通過適當的計划調用該函數。

編輯:添加代碼

<?php
 define('APPKEY','XXXXXXXXXXXXXXX'); // Your App Key
 define('PUSHSECRET', 'XXXXXXXXXXXXXXX'); // Your Master Secret
 define('PUSHURL', 'https://go.urbanairship.com/api/push/');

 $contents = array();
 $contents['badge'] = "+1";
 $contents['alert'] = "PHP script test";
 $contents['sound'] = "cat.caf";
 $notification = array();
 $notification['ios'] = $contents;
 $platform = array();
 array_push($platform, "ios");

 $push = array("audience"=>"all", "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_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 "Wow, it worked!\n";
 }

 curl_close($session);
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM