How can I send a Firebase Cloud Messaging notification without use the Firebase Console?

后端 未结 16 1495
南旧
南旧 2020-11-22 10:17

I\'m starting with the new Google service for the notifications, Firebase Cloud Messaging.

Thanks to this code https://github.com/firebase/quickstart-a

16条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 10:37

    Here is the working code in my project using CURL.

     'here is a message. message',
        'title'     => 'This is a title. title',
        'subtitle'  => 'This is a subtitle. subtitle',
        'tickerText'    => 'Ticker text here...Ticker text here...Ticker text here',
        'vibrate'   => 1,
        'sound'     => 1,
        'largeIcon' => 'large_icon',
        'smallIcon' => 'small_icon'
     );
    
     $fields = array
     (
        // use this to method if want to send to topics
        // 'to' => 'topics/all'
        'registration_ids'  => $registrationIds,
         'data'         => $msg
     );
    
     $headers = array
     (
        'Authorization: key=' . API_ACCESS_KEY,
        'Content-Type: application/json'
     );
    
     $ch = curl_init();
     curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
     curl_setopt( $ch,CURLOPT_POST, true );
     curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
     curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
     curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
     curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
     $result = curl_exec($ch );
     curl_close( $ch );
    
     echo $result;
    

提交回复
热议问题