我正在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)
发送推送通知。我想根据schedule task
发送推文。计划任务由PHP代码完成。
那么,任何线索或想法如何以适当的时间表从我的服务器发送推送通知?
提前致谢。
答案 0 :(得分:1)
如果您可以在服务器上运行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);
?>