Edujugon推送通知

时间:2018-07-20 09:35:29

标签: android laravel android-push-notification

我正在尝试Edujugon Push Notification laravel;所有配置均正确。 我的推送通知代码是

$ push = new PushNotification('fcm');

    $push->setMessage([
    'notification' => [
            'title'=>'This is the title',
            'body'=>'This is the message',
            'sound' => 'default'
            ],
    'data' => [
            'extraPayLoad1' => 'value1',
            'extraPayLoad2' => 'value2'
            ]
    ])        
    ->setApiKey('AAAAv7w78uY:APA91bF73GY1AcZvBh84K2matRxFwWB0VQysqlDzsLBtrmVRbRN0e6T2Lxasiv-sNfWaNQwqgltTaiaL0rZVC5TKzwfZRgrxb30B4jkl2bzJ9DViZsbGVdQMNOJ78FtOfwcUCgvUj_XC7jLdargjnfKQAD0ecbWMlA')
    ->setDevicesToken('fj6Sx3zYjhM:APA91bE3cas4LPX-T9jJ-7YgKrMIYOiD5Brjf9AgqvCUsSN7OygZEX3qhQ1F4RxCZfsvSCHNV9gq15NL26k62KBuWqpX4G9nrSQHT3ddabCTRwinqbmpt53gtdCgakaW5LvSxA1t1-iiZS8at8pW7W9o5Gyv2mBSEw');
    $push = $push->send();

3 个答案:

答案 0 :(得分:0)

请参阅https://packagist.org/packages/edujugon/push-notification

$push->setMessage([
    'notification' => [
            'title'=>'This is the title',
            'body'=>'This is the message',
            'sound' => 'default'
            ],
    'data' => [
            'extraPayLoad1' => 'value1',
            'extraPayLoad2' => 'value2'
            ]
    ])
    ->setApiKey('Server-API-Key')
    ->setDevicesToken(['deviceToken1','deviceToken2','deviceToken3'...]);

答案 1 :(得分:0)

已使用此软件包LARAVEL-FCM易于使用

答案 2 :(得分:0)

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

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;
    }