我使用 Laravel 進行身份驗證,使用 druapl 進行內容管理,現在使用 firebase 向移動設備發送通知……當我在 druapl 中發布新內容時,如何向所有移動設備發送通知?這是我在 Laravel 中的發送功能
public function sendNotification($device_token, $message)
{
$SERVER_API_KEY = 'myKey';
$data = [
"to" => $device_token, // for single device id
"notification" => $message
];
$dataString = json_encode($data);
$headers = [
'Authorization: key=' . $SERVER_API_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_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
uj5u.com熱心網友回復:
您應該從每個用戶設備獲取令牌 ID,并通過他們的設備令牌作為陣列發送通知。添加一個名為 devices 的新表,將 user_id 和 device_token 作為列,然后每個新用戶打開您的應用程式,他的設備令牌將發送到您的服務器,然后您應該將收到的令牌作為新記錄保存到設備表中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/344441.html
