2

我正在尝试通过推送 woosh 发送推送通知,如下所示:

有人帮我如何通过此代码在设备上发送推送通知

function pwCall( 'createMessage', 大批(

        'application' => PW_APPLICATION,          

        'auth' => PW_AUTH,

        "devices" => PW_DEVICETOKEN,

        'notifications' =>  array(

                    'send_date' =>'now', //gmdate('d-m-Y H:i', strtotime('2014-04-07 20:35')),

                    'content' => 'my custom notification testing ',

    'link' => 'http://pushwoosh.com/',

                    'content' => array("en" => "English","ru" =>"Русский","de"=>"Deutsch")

                    ),

                  'page_id' => 16863,

                  'link' => 'http://google.com',

                 'data' => array( 'custom' => 'json data' ),   
            )
    );

我收到错误,例如

数组([status_code] => 210 [status_message] => 无法解析日期 [response] =>)

4

4 回答 4

2
  1. 通知应该是 JSON 表示法的对象数组。在 PHP 中,它将是数组数组。这是因为您可以在一个请求中创建多个通知。通知字段的最终 JSON :

    "通知":[{ ... 通知属性... }, { ... 第二个通知属性... }, ...]

  2. 请求中只有 3 个根参数:应用程序(或applications_group)、身份验证通知。其他参数是通知的参数,不是请求的。

最后,您的 PHP 调用应如下所示:

pwCall("createMessage", array(
  "auth" => PW_AUTH,
  "application" => PW_APPLICATION,
  "notifications" => array(
    array(
      "send_date" => "now",
      "content" => array("en" => "English", "ru" =>"Русский", "de"=>"Deutsch"),
      "link" => "http://pushwoosh.com/",
      "page_id" => 16863,
      "devices" => array( PW_DEVICETOKEN ),
      "data" => array( "custom" => "json data" )
    )
  )
));

除了send_datecontent之外的所有通知字段都是可选的,可以省略

于 2014-04-14T16:46:46.093 回答
0

我们开发了一个 API 来轻松调用 Pushwoosh Web 服务。

这个 API 应该是一个高质量的 API,并且已经过全面测试(非常高的代码覆盖率)。

https://github.com/gomoob/php-pushwoosh

于 2014-09-23T15:03:03.747 回答
0

从外观上看,您的日期格式不正确。您正在传递一个由单词“now”组成的普通字符串。您想要做的是类似于以下内容的事情:

function pwCall("createMessage", array(
    "application"   => PW_APPLICATION,          
    "auth"          => PW_AUTH,
    "devices"       => PW_DEVICETOKEN,
    "notifications" => array(
        "send_date" => gmdate("Y-m-d H:i"),
        "content"   => "My custom notification",
        "link"      => "http://pushwoosh.com/",
        "content"   => array("en" => "English", "ru" =>"Русский", "de"=>"Deutsch")
    ),
    "page_i" => 16863,
    "link"   => "http://google.com",
        "data" => array("custom" => "json data"),   
    )
);
于 2014-04-14T09:51:19.397 回答
0
$push_auth = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$push_app_id = 'XXXXX-XXXXX';
$push_debug = false;
$title = ''; // pushwoosh title
$banner = ''; // pushwoosh banner
$send_date = 'now'; // pushwoosh date
$android_header = '';    // pushwoosh android header 
$android_custom_icon = '' pushwoosh notification icon;
sendpush('createMessage', array(
                    'application' => $push_app_id,
                    'auth' => $push_auth,
                    'notifications' => array(
                        array(
                            'send_date' => $send_date,
                            'content' => $title,
                            'android_header'=>$android_header,
                            'android_custom_icon' =>$android_custom_icon,
                            'android_badges' => 2,
                            'android_vibration' => 1,                
                            'android_priority' => 1,
                            'data' => array('custom' => 'json data'),
                        ),
                    )
        ));

function sendpush($method, $data) {
            $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, false);
            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') && self::$push_de) {
                print "[PW] request: $request\n";
                print "[PW] response: $response\n";
                print "[PW] info: " . print_r($info, true);
            }

            return $info;
    }
}
于 2017-05-24T10:57:13.017 回答