简体   繁体   中英

Push to 1 specific device using pushwoosh

I am trying to setup pushwoosh to handle my notifications for my Android App. I am using PHP as my backened and now want to send to one specific device/token, but with no luck?

When doing this:

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' )
            )
        )
    )
);

... it sends to all devices connected to my pushwoosh App? What am I doing wrong?

Thanks in advance.

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.     

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM