从 mysql 表中获取所有用户的 fcm 令牌
$token_ids = Userdevices::pluck('fcm_token')->toArray();
$this->send_admin_notification($token_ids,"title","body message","image url");
向所有用户发送通知
public function send_admin_notification($token_ids ,$title, $message,$imageURL){
$authorization_key = "AAAADnklIkA:APA91...";
$finalPostArray = array('registration_ids' => $token_ids,
'notification' => array('body' => $message,
'title' => $title,
"image"=> $imageURL),
"data"=> array("click_action"=> "FLUTTER_NOTIFICATION_CLICK",
"sound"=> "default",
"status"=> "done"));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://fcm.googleapis.com/fcm/send");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($finalPostArray)); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: key='.$authorization_key));
$server_output = curl_exec ($ch);
curl_close ($ch);
//echo $server_output;
}