简体   繁体   English

使用edujugon推送通知的Laravel Web推送通知

[英]Laravel Web Push notification using edujugon push-notification

I have a problem in my project. 我的项目有问题。 I am using edujugon push-notification for push notification of my app, I created push notification to android, ios devices successfully with title, body. 我将edujugon push-notification用于我的应用程序的推送通知,我成功创建了带有标题,正文的android,ios设备推送通知。 But when I integrate the notification in my web devices it does not show the title and body rather it shows the site is upgrated in backend . 但是,当我将通知集成到Web设备中时,它不显示标题和正文,而是显示the site is upgrated in backend Also I want to set an url in my web notification. 我也想在我的网络通知中设置一个URL。 But dont know how. 但是不知道如何。

Here is my code 这是我的代码

public static function sendPushNotification($devices, $pushData, $partner = false) {

    $android = $devices->where('type', 2)->pluck('token')->all();
    if (!empty($android)) {
        $push = new PushNotification('fcm');

        $push->setMessage(
            [
                'data' => $pushData,
            ]
        )
            ->setDevicesToken($android)
            ->send();
    }

    $ios = $devices->where('type', 1)->pluck('token')->all();

    if (!empty($ios)) {
        $push = new PushNotification('apn');

        $feedback = $push->setMessage(
                [
                    'aps' => [
                        'alert' => [
                            'title' => $pushData['title'],
                            'body' => $pushData['body'],
                        ],
                        'sound' => 'default',
                        'badge' => 1
                    ],
                    'data' => $pushData
                ]
        )->setDevicesToken($ios)->send()->getFeedback();
    }

    $web = $devices->where('type', 3)->pluck('token')->all();
    if (!empty($web)) {
        $push = new PushNotification('fcm');

        $push->setMessage($pushData)->setDevicesToken($web)->send();
    }
}

and my push data is 我的推送数据是

$pushData = [
    'title' => 'Test',
    'body' => 'Test',
];

Please help me solving this 请帮我解决这个问题

You should write this 你应该写这个

if (!empty($web)) {
            $push = new PushNotification('fcm');

            $push->setMessage(
                [
                    'notification' => $pushData,
                ]
            )->setDevicesToken($web)->send();
        }

Hopefully this will solve your problem. 希望这可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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