quota
This commit is contained in:
parent
543f359acd
commit
a4cc8752ff
@ -21,7 +21,7 @@
|
|||||||
<div class="section">
|
<div class="section">
|
||||||
<h3 class="doc">Message sent</h3>
|
<h3 class="doc">Message sent</h3>
|
||||||
<p class="doc">Message succesfully sent<br>
|
<p class="doc">Message succesfully sent<br>
|
||||||
<?php echo isset($_GET['quota'])?$_GET['quota']:'ERR';?>/100 remaining</p>
|
<?php echo isset($_GET['quota'])?$_GET['quota']:'ERR';?>/<?php echo isset($_GET['quota_max'])?$_GET['quota_max']:'ERR';?> remaining</p>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ function send()
|
|||||||
'?ok=' + 1 +
|
'?ok=' + 1 +
|
||||||
'&message_count=' + resp.messagecount +
|
'&message_count=' + resp.messagecount +
|
||||||
'"a=' + resp.quota +
|
'"a=' + resp.quota +
|
||||||
|
'"a_max=' + resp.quota_max +
|
||||||
'&preset_user_id=' + uid.value +
|
'&preset_user_id=' + uid.value +
|
||||||
'&preset_user_key=' + key.value;
|
'&preset_user_key=' + key.value;
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,10 @@ CREATE TABLE `users`
|
|||||||
`messages_sent` INT(11) NOT NULL DEFAULT '0',
|
`messages_sent` INT(11) NOT NULL DEFAULT '0',
|
||||||
`timestamp_created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`timestamp_created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
`timestamp_accessed` DATETIME NULL DEFAULT NULL,
|
`timestamp_accessed` DATETIME NULL DEFAULT NULL,
|
||||||
|
|
||||||
|
`quota_today` INT(11) NOT NULL DEFAULT '0',
|
||||||
|
`quota_day` DATE NULL DEFAULT NULL,
|
||||||
|
`quota_max` INT(11) NOT NULL DEFAULT '100',
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
|
14
web/send.php
14
web/send.php
@ -30,7 +30,7 @@ if (strlen($content) > 10000) die(json_encode(['success' => false, 'errhighlight
|
|||||||
|
|
||||||
$pdo = getDatabase();
|
$pdo = getDatabase();
|
||||||
|
|
||||||
$stmt = $pdo->prepare('SELECT user_id, user_key, fcm_token, messages_sent FROM users WHERE user_id = :uid LIMIT 1');
|
$stmt = $pdo->prepare('SELECT user_id, user_key, fcm_token, messages_sent, quota_today, quota_max, quota_day FROM users WHERE user_id = :uid LIMIT 1');
|
||||||
$stmt->execute(['uid' => $user_id]);
|
$stmt->execute(['uid' => $user_id]);
|
||||||
|
|
||||||
$datas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$datas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
@ -43,6 +43,10 @@ if ($data['user_key'] !== $user_key) die(json_encode(['success' => false, 'errhi
|
|||||||
|
|
||||||
$fcm = $data['fcm_token'];
|
$fcm = $data['fcm_token'];
|
||||||
|
|
||||||
|
$new_quota = $data['quota_today'] + 1;
|
||||||
|
if ($data['quota_day'] === null || $data['quota_day'] !== date("Y-m-d")) $new_quota=0;
|
||||||
|
if ($new_quota > $data['quota_max']) die(json_encode(['success' => false, 'errhighlight' => -1, 'message' => 'Daily quota reached ('.$data['quota_max'].')']));
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
$url = "https://fcm.googleapis.com/fcm/send";
|
$url = "https://fcm.googleapis.com/fcm/send";
|
||||||
@ -77,14 +81,16 @@ catch (Exception $e)
|
|||||||
die(json_encode(['success' => false, 'message' => 'Exception: ' . $e->getMessage()]));
|
die(json_encode(['success' => false, 'message' => 'Exception: ' . $e->getMessage()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = $pdo->prepare('UPDATE users SET timestamp_accessed=NOW(), messages_sent=messages_sent+1 WHERE user_id = :uid');
|
$stmt = $pdo->prepare('UPDATE users SET timestamp_accessed=NOW(), messages_sent=messages_sent+1, quota_today=:q, quota_day=NOW() WHERE user_id = :uid');
|
||||||
$stmt->execute(['uid' => $user_id]);
|
$stmt->execute(['uid' => $user_id, 'q' => $new_quota]);
|
||||||
|
|
||||||
echo (json_encode(
|
echo (json_encode(
|
||||||
[
|
[
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'message' => 'Message sent',
|
'message' => 'Message sent',
|
||||||
'response' => $httpresult,
|
'response' => $httpresult,
|
||||||
'messagecount' => $data['messages_sent']+1
|
'messagecount' => $data['messages_sent']+1,
|
||||||
|
'quota'=>$new_quota,
|
||||||
|
'quota_max'=>$data['quota_max'],
|
||||||
]));
|
]));
|
||||||
return 0;
|
return 0;
|
Loading…
Reference in New Issue
Block a user