PHP
9
Вклад в тег
// Server URL Google Firebase Cloud Messages
$SERVER_URL = '';
// Server key FCM/GCM
$API_ACCESS_KEY = '';
// Массив токенов
$arTokens = [];
// Отправляем
$headers = [
'Authorization: key=' . $API_ACCESS_KEY,
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, $SERVER_URL);
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 );
$fields = [
'registration_ids' => $arTokens,
'data' => [
'message' => $message
]
];
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch);
curl_close( $ch );