【问题标题】:Send notification to specific device using Pushwoosh and Php使用 Pushwoosh 和 Php 向特定设备发送通知
【发布时间】:2015-03-17 16:52:50
【问题描述】:

有没有人成功使用 Pushwoosh 远程 api 向特定设备发送自定义通知?我已经查看了他们的文档来进行设置,但是通知一直发送到所有设备。我在这里做错了什么?提前致谢。

<?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


          )
        );
?>

【问题讨论】:

    标签: php push-notification pushwoosh


    【解决方案1】:

    您必须将设备列表指定到通知数组中。请参阅下面的正确请求(也可以在此处获得 Pushwoosh API 文档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
                                  )
                          ),
                  )
                );
        ?>
    

    【讨论】:

    • 从哪里获得设备 ID?是注册设备方法上设置的“push_token”吗?
    • 是的,您可以使用 registerDevice 方法中的 hwid 或 pushtoken。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-15
    相关资源
    最近更新 更多