58 lines
1.8 KiB
PHP
58 lines
1.8 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']);
|
|
|
|
$filename="gcm_test_all.txt";
|
|
|
|
$datetime = date('Y-m-d H:i:s');
|
|
$a=0;
|
|
$b=0;
|
|
$dataArray = array('latitude'=>number_format((float)$a, 2, '.', ''),
|
|
'longitude'=>number_format((float)$b, 2, '.', ''),
|
|
'counter'=>43,
|
|
'datetime'=>$datetime,
|
|
'type'=>'eqn');
|
|
|
|
//extract users for notifications
|
|
$sql2=mysql_query("SELECT reg_id FROM gcm LEFT JOIN subscriptions ON gcm.user_id = subscriptions.user_id ORDER BY top_100 DESC, top_1000 DESC, top_10000 DESC, subscriptions.date limit 1000");
|
|
|
|
|
|
|
|
$counter=0;
|
|
$num_rows2 = mysql_num_rows($sql2);
|
|
$arrival_time=microtime(true);
|
|
$chunck=$num_rows2.','.strval($arrival_time)."\r\n";
|
|
file_put_contents($filename,$chunck,FILE_APPEND);
|
|
|
|
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,
|
|
'dry_run' => true,
|
|
'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);
|
|
$arrival_time=date('m/d/Y h:i:s', time());;
|
|
$chunck=$i.','.strval($arrival_time)."\r\n";
|
|
file_put_contents($filename,$chunck,FILE_APPEND);
|
|
$counter=0;
|
|
$regidArray=array();
|
|
}
|
|
}
|
|
mysql_close();
|
|
?>
|