我正在尝试设置pushwoosh来处理我的Android应用程序的通知。我使用PHP作为我的后备,现在想发送到一个特定的设备/令牌,但没有运气?
这样做时:
pwCall( 'createMessage', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
'notifications' => array(
array(
'send_date' => 'now',
'devices' => array('APA91BGJ1GCEV9R8QFIJIS_OPHJT2Q1GFJVQQZ9G6OGD0VUMUVPFTZIOUCX4-HOQZ9MK_EGUKP_GA3QATFHKIDALXMNDDW0UEO4LSFDWP4KBJFMKD3_4_24ACAJ5S_YMHG-ZLWTAWJA15GAXGTMO4HJLB02SJNDFSQ'),
'content' => 'This is a test message!',
'data' => array( 'custom' => 'json data' )
)
)
)
);
...它发送到连接到我的pushwoosh App的所有设备?我做错了什么?
提前致谢。
答案 0 :(得分:0)
define('PW_AUTH','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); define('PW_APPLICATION','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$query = mysql_query("Select * from xxxxx where id ='".xxxx."'");
while($res=mysql_fetch_array($query))
{
function doPostRequest($url, $data, $optional_headers = null) {
$params = array(
'http' => array(
'method' => 'GET',
'content' => $data
));
if ($optional_headers !== null)
$params['http']['header'] = $optional_headers;
$ctx = stream_context_create($params);
$fp = fopen($url, 'rb', false, $ctx);
if (!$fp)
throw new Exception("Problem with $url, $php_errmsg");
$response = @stream_get_contents($fp);
if ($response === false)
return false;
return $response;
}
function pwCall( $action, $data = array() ) {
$url = 'https://cp.pushwoosh.com/json/1.3/' . $action;
$json = json_encode( array( 'request' => $data ) );
$res = doPostRequest( $url, $json, 'Content-Type: application/json' );
// print_r( @json_decode( $res, true ) );
}
$div = $res['device_token'];
$username = $res['username'];
pwCall( 'createMessage', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
'notifications' => array(
array(
'send_date' => 'now',
'devices' => array($div),
'content' => $username.' has sent you an challenge!',
'data' => array( 'custom' => 'json data' )
)
)
)
);
}
$div = "Device Token,you can assign it dynamically from database or statically.