<?php

include_once('../conexao.php');
$query = $pdo->prepare("SELECT * FROM token");
$query->execute();
$res = $query->fetchAll(PDO::FETCH_ASSOC);
for ($i=  0; $i < count($res); $i++) { 
	foreach ($res[$i] as $key => $value) {
	}


	$token = $res[$i]['token'];

	$payload = array(
		'to' => $token,
		'sound' => 'default',
		'title' => 'titulo',
		'body' => 'conteudo',
	);

	$curl = curl_init();

	curl_setopt_array($curl, array(
		CURLOPT_URL => "https://exp.host/--/api/v2/push/send",
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => "",
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 30,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => "POST",
		CURLOPT_POSTFIELDS => json_encode($payload),
		CURLOPT_HTTPHEADER => array(
			"Accept: application/json",
			"Accept-Encoding: gzip, deflate",
			"Content-Type: application/json",
			"cache-control: no-cache",
			"host: exp.host"
		),
	));

	$response = curl_exec($curl);
	$err = curl_error($curl);

	curl_close($curl);

	if ($err) {
		echo "cURL Error #:" . $err;
	} else {
		echo $response;
	}

}

?>