Laravel推送通知和消息传递 [英] Laravel Push Notification and Messaging

查看:643
本文介绍了Laravel推送通知和消息传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用laravel用后端离子写前端. 我想做的是,当用户订购应用程序时,我想向应用程序发送通知,并从应用程序中与用户进行消息传递.

I'm trying to write front-end with the back-end ionic with laravel. What I want to do is that when the user orders the application, I want to send notifications to the application and messaging with the user from the application.

为此,我已经审查了/laravel-push-notification包;

For this, I have reviewed the / laravel-push-notification package;

但是,它对我不起作用,因为我需要动态消息传递.你能帮忙吗?我不想使用 https://pusher.com

However, it did not work for me because I needed a dynamic messaging. Can you help with this? I do not want to use https://pusher.com

推荐答案

我还使用以下代码在laravel中集成了推送通知,希望对您有所帮助:

I have also integrated push notification in laravel using below code, hope it helps you :

function sendPushNotification($fcm_token, $title, $message, $id="") {  
        $push_notification_key = Config::get('settings.PUSH_NOTIFICATION_KEY');    
        $url = "https://fcm.googleapis.com/fcm/send";            
        $header = array("authorization: key=" . $push_notification_key . "",
            "content-type: application/json"
        );    

        $postdata = '{
            "to" : "' . $fcm_token . '",
                "notification" : {
                    "title":"' . $title . '",
                    "text" : "' . $message . '"
                },
            "data" : {
                "id" : "'.$id.'",
                "title":"' . $title . '",
                "description" : "' . $message . '",
                "text" : "' . $message . '",
                "is_read": 0
              }
        }';

        $ch = curl_init();
        $timeout = 120;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

        // Get URL content
        $result = curl_exec($ch);    
        // close handle to release resources
        curl_close($ch);

        return $result;
    }

这篇关于Laravel推送通知和消息传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆