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

后端 未结 16 1499
南旧
南旧 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 11:00

    this solution from this link helped me a lot. you can check it out.

    The curl.php file with those line of instruction can work.

     "cNf2---6Vs9", "notification" => array( "title" => "Shareurcodes.com", "body" => "A Code Sharing Blog!","icon" => "icon.png", "click_action" => "http://shareurcodes.com"));
    $data_string = json_encode($data);
    echo "The Json Data : ".$data_string;
    $headers = array ( 'Authorization: key=' . API_ACCESS_KEY, 'Content-Type: application/json' );
    $ch = curl_init(); curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
    curl_setopt( $ch,CURLOPT_POST, true );
    curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
    curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch,CURLOPT_POSTFIELDS, $data_string);
    $result = curl_exec($ch);
    curl_close ($ch);
    echo "

     

    "; echo "The Result : ".$result;

    Remember you need to execute curl.php file using another browser ie not from the browser that is used to get the user token. You can see notification only if you are browsing another website.

提交回复
热议问题