function send_notification($token, $title, $body) { $SERVER_API_KEY = "AAAAiyOcU6g:APA91bEAzf_3qesFfsIYTD1UzDz6mjUF_Ivgl5fw4KZkBwJ7tpyUv-g0h4H8RdB5_0649YAZgPCNrsoQNfI8QqwyDdhuC93W-6__G3CMV5GQVo8jLn8ehHOQ0eSW4N9Kn4gGx5WuCu84"; $header = [ 'Authorization: Key=' . $SERVER_API_KEY, 'Content-Type: Application/json' ]; $payload = [ 'registration_ids' => [$token], 'notification' => [ 'title' => $title, 'body' => $body ] ]; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_URL => "https://fcm.googleapis.com/fcm/send", CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode( $payload ), CURLOPT_HTTPHEADER => $header )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { return response()->json([ "code" => 1, "message" => "cURL Error #:" . $err ]); } else { return response()->json([ "code" => 0, "message" => trans('message.successful'), "response" => $response ]); } } $result = send_notification($this->letter->m_sender->token_fcm, 'Thông báo', 'Đã tiếp nhận yêu cầu gửi thư của bạn');