153 lines
5.7 KiB
PHP
153 lines
5.7 KiB
PHP
<?php
|
|
set_include_path(get_include_path() . PATH_SEPARATOR . '/usr/share/php5/google-api-php-client/src');
|
|
$ini = parse_ini_file("conf.ini", true);
|
|
|
|
|
|
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
|
|
mysql_select_db($ini['db']['db']);
|
|
|
|
if ($ini['db']['log']=="1"){
|
|
$arrival_time=microtime(true);
|
|
$filename=basename(__FILE__);
|
|
$filename="log_".$filename.".txt";
|
|
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
|
|
file_put_contents($filename,$chunck,FILE_APPEND);
|
|
}
|
|
|
|
session_start();
|
|
|
|
require_once '/usr/share/php5/google-api-php-client/autoload.php';
|
|
require_once '/usr/share/php5/google-api-php-client/src/Google/Client.php';
|
|
require_once '/usr/share/php5/google-api-php-client/src/Google/Service/AndroidPublisher.php';
|
|
|
|
$client_id = '421988011821-vlj6u2tfr1jihfjt2oibsrdqtqss26el.apps.googleusercontent.comm';
|
|
$service_account_name = '421988011821-vlj6u2tfr1jihfjt2oibsrdqtqss26el@developer.gserviceaccount.com';
|
|
$key_file_location = '/var/www/earthquakenetwork.it/key/Google_Play_Android_Developer-ae5fe48b5cbe.p12';
|
|
|
|
$client = new Google_Client();
|
|
$client->setApplicationName('Earthquake Network');
|
|
$service=new Google_Service_AndroidPublisher($client);
|
|
|
|
if (isset($_SESSION['service_token']))
|
|
{
|
|
$client->setAccessToken($_SESSION['service_token']);
|
|
}
|
|
|
|
|
|
$key = file_get_contents($key_file_location);
|
|
$cred = new Google_Auth_AssertionCredentials($service_account_name,array('https://www.googleapis.com/auth/androidpublisher'),$key);
|
|
|
|
|
|
$client->setAssertionCredentials($cred);
|
|
|
|
$temp_dir=sys_get_temp_dir();
|
|
if ($client->getAuth()->isAccessTokenExpired())
|
|
{
|
|
try {
|
|
$client->getAuth()->refreshTokenWithAssertion($cred);
|
|
} catch (Exception $e) {
|
|
var_dump($e->getMessage());
|
|
}
|
|
}
|
|
|
|
$_SESSION['service_token'] = $client->getAccessToken();
|
|
|
|
$current_time = round(microtime(true) * 1000);
|
|
$sql=mysql_query("select * from subscriptions");
|
|
|
|
$num_rows = mysql_num_rows($sql);
|
|
for ($j = 0; $j < $num_rows; $j++)
|
|
{
|
|
print($j."\r\n");
|
|
$ID=mysql_result($sql,$j,"ID");
|
|
$token=mysql_result($sql,$j,"token");
|
|
$pro=mysql_result($sql,$j,"pro");
|
|
$top100=mysql_result($sql,$j,"top_100");
|
|
$top1000=mysql_result($sql,$j,"top_1000");
|
|
$top10000=mysql_result($sql,$j,"top_10000");
|
|
$top100_annual=mysql_result($sql,$j,"top_100_annual");
|
|
$top1000_annual=mysql_result($sql,$j,"top_1000_annual");
|
|
$top10000_annual=mysql_result($sql,$j,"top_10000_annual");
|
|
|
|
|
|
if ($pro==0){
|
|
$packageName='com.finazzi.distquake';
|
|
}
|
|
else{
|
|
$packageName='com.finazzi.distquakenoads';
|
|
}
|
|
if ($top100==1){
|
|
$subscriptionId="top_100a";
|
|
try {
|
|
$results = $service->purchases_subscriptions->get($packageName,$subscriptionId,$token);
|
|
if ($results->expiryTimeMillis<$current_time){
|
|
$sql2=mysql_query("update subscriptions set top_100=0 where ID=$ID");
|
|
}
|
|
} catch (Exception $e) {
|
|
$sql2=mysql_query("update subscriptions set top_100=2 where ID=$ID");
|
|
}
|
|
}
|
|
if ($top1000==1){
|
|
$subscriptionId="top_1000a";
|
|
try {
|
|
$results = $service->purchases_subscriptions->get($packageName,$subscriptionId,$token);
|
|
if ($results->expiryTimeMillis<$current_time){
|
|
$sql2=mysql_query("update subscriptions set top_1000=0 where ID=$ID");
|
|
}
|
|
} catch (Exception $e) {
|
|
$sql2=mysql_query("update subscriptions set top_1000=2 where ID=$ID");
|
|
}
|
|
}
|
|
if ($top10000==1){
|
|
$subscriptionId="top_10000a";
|
|
try {
|
|
$results = $service->purchases_subscriptions->get($packageName,$subscriptionId,$token);
|
|
if ($results->expiryTimeMillis<$current_time){
|
|
$sql2=mysql_query("update subscriptions set top_10000=0 where ID=$ID");
|
|
}
|
|
} catch (Exception $e) {
|
|
$sql2=mysql_query("update subscriptions set top_10000=2 where ID=$ID");
|
|
}
|
|
}
|
|
if ($top100_annual==1){
|
|
$subscriptionId="top_100a_annual";
|
|
try {
|
|
$results = $service->purchases_subscriptions->get($packageName,$subscriptionId,$token);
|
|
if ($results->expiryTimeMillis<$current_time){
|
|
$sql2=mysql_query("update subscriptions set top_100_annual=0 where ID=$ID");
|
|
}
|
|
} catch (Exception $e) {
|
|
$sql2=mysql_query("update subscriptions set top_100_annual=2 where ID=$ID");
|
|
}
|
|
}
|
|
if ($top1000_annual==1){
|
|
$subscriptionId="top_1000a_annual";
|
|
try {
|
|
$results = $service->purchases_subscriptions->get($packageName,$subscriptionId,$token);
|
|
if ($results->expiryTimeMillis<$current_time){
|
|
$sql2=mysql_query("update subscriptions set top_1000_annual=0 where ID=$ID");
|
|
}
|
|
} catch (Exception $e) {
|
|
$sql2=mysql_query("update subscriptions set top_1000_annual=2 where ID=$ID");
|
|
}
|
|
}
|
|
if ($top10000_annual==1){
|
|
$subscriptionId="top_10000a_annual";
|
|
try {
|
|
$results = $service->purchases_subscriptions->get($packageName,$subscriptionId,$token);
|
|
if ($results->expiryTimeMillis<$current_time){
|
|
$sql2=mysql_query("update subscriptions set top_10000_annual=0 where ID=$ID");
|
|
}
|
|
} catch (Exception $e) {
|
|
$sql2=mysql_query("update subscriptions set top_10000_annual=2 where ID=$ID");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
$sql=mysql_query("delete from subscriptions where top_100=0 AND top_1000=0 AND top_10000=0 AND top_100_annual=0 AND top_1000_annual=0 AND top_10000_annual=0");
|
|
|
|
mysql_close();
|
|
?>
|