2015-03-11 7 views
4

Имеет ли какой-либо успех в использовании Push-Push-пула api для отправки пользовательских уведомлений на конкретное устройство? Я перечислил их документацию, чтобы настроить это, но уведомление продолжает выходить на все устройства. Что я здесь делаю неправильно? Заранее спасибо.Отправлять уведомления на конкретное устройство с использованием Pushwoosh и Php

<?php 


define('PW_AUTH', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); 
define('PW_APPLICATION', 'XXXXXX-XXXXXX'); 
define('PW_DEBUG', true); 

function pwCall($method, $data = array()) { 


    $url = 'https://cp.pushwoosh.com/json/1.3/' . $method; 
    $request = json_encode(['request' => $data]); 

    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); 
    curl_setopt($ch, CURLOPT_HEADER, true); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request); 

    $response = curl_exec($ch); 
    $info = curl_getinfo($ch); 
    curl_close($ch); 

    if (defined('PW_DEBUG') && PW_DEBUG) { 
     print "[PW] request: $request\n"; 
     print "[PW] response: $response\n"; 
     print "[PW] info: " . print_r($info, true); 
    } 
} 
pwCall('createMessage', array(
        'application' => PW_APPLICATION, 
        'auth' => PW_AUTH, 
        'notifications' => array(
          array(

           'send_date' => 'now', 
           'content' => 'Send this content to user', 

         ) 


       ), 

        'devices' => array('2lksdflkje96a4389f796173fakeae938device95ajkdh8709843') //Optional. Not more than 1000 tokens in an array. If set, message will only be delivered to the devices in the list. Ignored if the applications group is used 


     ) 
     ); 
?> 

ответ

2

Необходимо указать список устройств в массиве уведомлений. Пожалуйста, обратитесь к правильному запросу ниже (также доступна документация по API Pushwoosh здесь https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-Method-messages-create)

<?php 
    define('PW_AUTH', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); 
    define('PW_APPLICATION', 'XXXXXX-XXXXXX'); 
    define('PW_DEBUG', true); 

    function pwCall($method, $data = array()) { 
     $url = 'https://cp.pushwoosh.com/json/1.3/' . $method; 
     $request = json_encode(['request' => $data]); 

     $ch = curl_init($url); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 
     curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); 
     curl_setopt($ch, CURLOPT_HEADER, true); 
     curl_setopt($ch, CURLOPT_POST, true); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $request); 

     $response = curl_exec($ch); 
     $info = curl_getinfo($ch); 
     curl_close($ch); 

     if (defined('PW_DEBUG') && PW_DEBUG) { 
      print "[PW] request: $request\n"; 
      print "[PW] response: $response\n"; 
      print "[PW] info: " . print_r($info, true); 
     } 
    } 
    pwCall('createMessage', array(
         'application' => PW_APPLICATION, 
         'auth' => PW_AUTH, 
         'notifications' => array(
           array(
            'send_date' => 'now', 
            'content' => 'Send this content to user', 
            'devices' => array('2lksdflkje96a4389f796173fakeae938device95ajkdh8709843') //Optional. Not more than 1000 tokens in an array. If set, message will only be delivered to the devices in the list. Ignored if the applications group is used 
          ) 
        ), 
      ) 
      ); 
    ?> 
+0

Где вы получаете идентификатор устройства? что «push_token» установлен на методе регистрационного устройства? – useless

+1

Да, вы можете использовать hwid или pushtoken из метода registerDevice. – FallDi

+0

'hwid' работает для меня, просто сообщая. –

 Смежные вопросы

  • Нет связанных вопросов^_^