1

我正在尝试设置 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 应用程序的所有设备?我究竟做错了什么?

提前致谢。

4

1 回答 1

0

定义('PW_AUTH','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');定义('PW_APPLICATION','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');

    $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.     
于 2013-07-22T12:07:57.190 回答