【问题标题】:Push notification with pusher beam, unable to send data/payload使用推送梁推送通知,无法发送数据/有效负载
【发布时间】:2021-04-26 08:27:16
【问题描述】:

我正在使用以下 php sdk 来生成推送梁推送通知。但是 sdk 文档中没有提供有关如何发送数据/有效负载的信息。通知是正确发送的 bean,但我无法发送数据:请指导我如何发送数据:它在光束控制台中显示 hasData 为 false,请检查:

我正在使用的php sdk:https://github.com/pusher/push-notifications-php

我的代码如下所示:

$pushNotification = new PushNotifications([
                'instanceId' => env('BEAM_INSTANCE_ID'),
                'secretKey' => env('BEAM_PRIMARY_KEY')
            ]);
            $pushNotification->publishToInterests(
                ['message-notification'],
                [
                    "apns" => [
                        "aps" => [
                            "alert" => "Message Received",
                        ],
                    ],
                    "fcm" => [
                        "notification" => [
                            'title' => 'some title',
                            'body' => 'some body',
                            'data' => 'some data', //passing data here but not working
                         ],
                    ],
                ]
            );

【问题讨论】:

    标签: php push-notification pusher laravel-notification


    【解决方案1】:

    我搞定了,我们可以通过以下方式传递数据:

    $publishResponse = $pushNotifications->publishToInterests(
      ["donuts"],
      [
        "apns" => [
          "aps" => [
            "alert" => "Hello!",
          ],
        ],
        "fcm" => [
          "notification" => [
            "title" => "Hello!",
            "body" => "Hello, world!",
          ],
          "data" => [                      // <==== pass data here
             "name" => "adam",
             "type" => "user",
          ],
        ],
      ]
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-31
      • 2016-07-19
      • 2017-05-31
      • 1970-01-01
      • 2015-04-10
      • 2018-09-21
      • 2019-08-16
      • 1970-01-01
      相关资源
      最近更新 更多