0

我正在尝试 Edujugon 推送通知 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();
4

3 回答 3

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'...]);
于 2018-07-20T10:26:37.913 回答
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;
    }
于 2019-01-03T07:31:06.573 回答
0

使用这个包LARAVEL-FCM易于使用

于 2018-07-20T15:08:12.993 回答