49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
$ini = parse_ini_file("conf.ini", true);
|
|
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
|
|
mysql_select_db($ini['db']['db']);
|
|
|
|
|
|
$dataArray = array('latitude'=>45,
|
|
'longitude'=>10,
|
|
'magnitude'=>4,
|
|
'place'=>'Italy',
|
|
'provider'=>'INGV',
|
|
'depth'=>10,
|
|
'data'=>'2017-06-21 18:49:00',
|
|
'difference'=>10,
|
|
'type'=>'official');
|
|
//extract users for notifications
|
|
$sql2=mysql_query("select reg_id from gcm where user_id=-3433561141690823682");
|
|
$counter=0;
|
|
$num_rows2 = mysql_num_rows($sql2);
|
|
for ($i = 0; $i < $num_rows2; $i++)
|
|
{
|
|
$regidArray[$counter]=mysql_result($sql2,$i,"reg_id");
|
|
$counter=$counter+1;
|
|
if ($counter==999 or $i==($num_rows2-1))
|
|
{
|
|
$headers = array(
|
|
'Authorization: key=AIzaSyAYaXDEapyd-mF9V9LNW1dmuoS-ea9GwWI',
|
|
'Content-Type: application/json');
|
|
$fields = array(
|
|
'registration_ids' => $regidArray,
|
|
'priority' => 'high',
|
|
'data' => $dataArray);
|
|
|
|
$context = stream_context_create(array(
|
|
'http' => array(
|
|
'method' => 'POST',
|
|
'header' => $headers,
|
|
'content' => json_encode($fields))));
|
|
$response = file_get_contents('https://android.googleapis.com/gcm/send', FALSE, $context); //
|
|
var_dump($response);
|
|
|
|
$counter=0;
|
|
$regidArray=array();
|
|
}
|
|
}
|
|
|
|
mysql_close();
|
|
?>
|