// There are some changes in the code in the comment define (api key line) and paste it as my code in php. his working fine // comment on this: - define ('API_ACCESS_KEY', 'Api key from Fcm add here'); // comment or replace this line of code: - "Authorization: key =". API_ACCESS_KEY
// define ('API_ACCESS_KEY', 'Api key from Fcm add here');
$ apiKey = 'Api key from Fcm add here';
$ fcmUrl = ' https://fcm.googleapis.com/fcm/send ';
$ token = '235zgagasd634sdgds46436';
$notification = [ 'title' =>'title', 'body' => 'body of message.', 'icon' =>'myIcon', 'sound' => 'mySound' ]; $extraNotificationData = ["message" => $notification,"moredata" =>'dd']; $fcmNotification = [ //'registration_ids' => $tokenList, //multple token array 'to' => $token, //single token 'notification' => $notification, 'data' => $extraNotificationData ]; $headers = [ 'Authorization: key=' . $apiKey, 'Content-Type: application/json' ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$fcmUrl); 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($fcmNotification)); $result = curl_exec($ch); curl_close($ch); echo $result; ?>
abhinandan kalotra
source share