Urban Airship - 将PUSH发送到1个特定设备(设备令牌) [英] Urban Airship - send PUSH to 1 specific device (device token)
本文介绍了Urban Airship - 将PUSH发送到1个特定设备(设备令牌)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我想通过Urban Airship定位一个特定的设备令牌,但无论我做什么,我的所有设备都会收到针对特定设备令牌的消息。
<这是我的PHP代码 - 任何帮助都像往常一样非常感谢!
define('APPKEY','XXXXXXXXXXXXXX');
define('PUSHSECRET','XXXXXXXXXXXXX'); // Master Secret
define('PUSHURL','https://go.urbanairship.com/api/push/broadcast/');
$ msg =这是用于我的iPad 3的消息;
$ devicetokens = array();
$ devicetokens [0] = $ devicetoken;
$ contents = array();
$ contents ['badge'] =1;
$ contents ['alert'] = $ msg;
$ contents ['sound'] =默认;
$ push = array(aps=> $ contents,device_tokens=> $ devicetokens);
// var_dump($ push);
$ json = json_encode($ push);
$ 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'));
$ content = curl_exec($ session);
// var_dump($ content); //仅用于测试发送的内容
//检查是否发生任何错误
$ response = curl_getinfo($ session);
解决方案
您使用的网址是广播。要向特定设备发送通知,您应使用的网址是https://go.urbanairship.com/api/push/
So I want to target one specific device token via Urban Airship, but no matter what I do, all of my devices get the message intended for a specific device token.
Here's my PHP code - any help is as usual greatly appreciated!
define('APPKEY','XXXXXXXXXXXXXX');
define('PUSHSECRET', 'XXXXXXXXXXXXX '); // Master Secret
define('PUSHURL', 'https://go.urbanairship.com/api/push/broadcast/');
$msg = "This is a message intended for my iPad 3";
$devicetokens = array();
$devicetokens[0] = $devicetoken;
$contents = array();
$contents['badge'] = "1";
$contents['alert'] = $msg;
$contents['sound'] = "default";
$push = array("aps" => $contents, "device_tokens" =>$devicetokens);
//var_dump($push);
$json = json_encode($push);
$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'));
$content = curl_exec($session);
//var_dump($content); // just for testing what was sent
// Check if any error occured
$response = curl_getinfo($session);
解决方案
The URL you're using is for broadcasting. To send notification to specific devices, the url you should use is 'https://go.urbanairship.com/api/push/'
这篇关于Urban Airship - 将PUSH发送到1个特定设备(设备令牌)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文