<?php
function signUp($email, $password) {
    $url = 'https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY]';
    $data = json_encode([
        'email' => $email,
        'password' => $password,
        'returnSecureToken' => true
    ]);
    $options = [
        'http' => [
            'header'  => "Content-type: application/json\r\n",
            'method'  => 'POST',
            'content' => $data,
        ],
    ];
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    return json_decode($result);
}
$response = signUp('[email protected]', 'user_password');
print_r($response);
?>
<?php
function signIn($email, $password) {
    $url = 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=[API_KEY]';
    $data = json_encode([
        'email' => $email,
        'password' => $password,
        'returnSecureToken' => true
    ]);
    $options = [
        'http' => [
            'header'  => "Content-type: application/json\r\n",
            'method'  => 'POST',
            'content' => $data,
        ],
    ];
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    return json_decode($result);
}
$response = signIn('[email protected]', 'user_password');
print_r($response);
?>
<?php
function verifyIdToken($idToken) {
    $url = 'https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=[API_KEY]';
    $data = json_encode([
        'idToken' => $idToken
    ]);
    $options = [
        'http' => [
            'header'  => "Content-type: application/json\r\n",
            'method'  => 'POST',
            'content' => $data,
        ],
    ];
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    return json_decode($result);
}
$response = verifyIdToken('ID_TOKEN_FROM_CLIENT');
print_r($response);
?>
<?php
function sendNotification($to, $title, $body) {
    $url = 'https://fcm.googleapis.com/fcm/send';
    $apiKey = 'YOUR_SERVER_KEY';
    $fields = json_encode([
        'to' => $to,
        'notification' => [
            'title' => $title,
            'body' => $body
        ]
    ]);
    $headers = [
        'Authorization: key=' . $apiKey,
        'Content-Type: application/json'
    ];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('Curl failed: ' . curl_error($ch));
    }
    curl_close($ch);
    return $result;
}
$response = sendNotification('DEVICE_TOKEN', 'Test Title', 'Test Body');
print_r($response);
?>