Back

Send Notification code in PHP

Copy Below Code View As A Text File Show Text Only Show API Edit Code
                            

<?php $message = 'Hello Dolly'; if ($message == '') { return false; } $url = 'https://fcm.googleapis.com/fcm/send'; $msg = array( //'title' => 'Web Title', 'body' => $message ); $data = array( 'click_action' => 'FLUTTER_NOTIFICATION_CLICK', 'sound' => 'default', 'type' => 'prize', 'status' => 'done' ); //$tokens=[$token]; $tokens = ['mobile_tocket1','mobile_tocket2']; $fields = array( 'registration_ids' => $tokens, 'notification' => $msg, 'data' => $data ); $headers = array( 'Authorization: key=AAAAIID3fVg:apitocket', 'Content-Type: application/json' ); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://fcm.googleapis.com/fcm/send", CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode($fields), CURLOPT_HTTPHEADER => $headers, )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } ?>