1. 数据库添加新表“status”

2. 缓存在线黑白名单
pull/27/head
david082321 3 years ago
parent d953a63dae
commit 6a3eb3048c

@ -50,4 +50,20 @@ ALTER TABLE `my_keys`
ALTER TABLE `my_keys`
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id';
COMMIT;
CREATE TABLE `status` (
`id` int(11) NOT NULL COMMENT 'id',
`expired_time` int(11) NOT NULL COMMENT '到期时间',
`uid` int(20) NOT NULL COMMENT '用户id',
`is_blacklist` tinyint(1) NOT NULL,
`is_whitelist` tinyint(1) NOT NULL,
`reason` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='黑白名单';
ALTER TABLE `status`
ADD PRIMARY KEY (`id`);
ALTER TABLE `status`
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id';
COMMIT;

@ -39,6 +39,7 @@ define('CACHE_TIME_412', 60*60*24*7); // 返回412服务器IP被风控
define('CACHE_TIME_404', 60*60*24*1); // 返回404时的缓存时长
define('CACHE_TIME_OTHER', 60*60*1); // 返回其他错误时的缓存时长(秒)
define('CACHE_TIME_USER', 60*60*24*1); //缓存用户key的时长
define('CACHE_TIME_BLACKLIST', 60*15); //缓存黑白名单的时长(秒)
// MySQL数据库
define('DB_HOST', 'localhost');

@ -50,14 +50,26 @@ if (ACCESS_KEY != "") { // access_key 存在
// resign.php 可能会用到
$is_blacklist = false;
$is_whitelist = false;
if (BLOCK_TYPE == "blacklist" || BLOCK_TYPE == "whitelist") {
$url = "https://black.qimo.ink/status.php?access_key=".ACCESS_KEY;
$status = json_decode(get_webpage($url), true);
$code = $status['code'];
if ((string)$code == "0") {
$is_blacklist = $status['data']['is_blacklist'];
$is_whitelist = $status['data']['is_whitelist'];
//$reason = $status['data']['reason'];
if (SAVE_CACHE == 1) {
// 获取黑白名单缓存
$out = get_cache_blacklist();
$is_blacklist = $out[0];
$is_whitelist = $out[1];
}
if ((SAVE_CACHE == 1 && $is_blacklist == "⑨") || SAVE_CACHE == 0) {
$url = "https://black.qimo.ink/status.php?access_key=".ACCESS_KEY;
$status = json_decode(get_webpage($url), true);
$code = $status['code'];
if ((string)$code == "0") {
$is_blacklist = $status['data']['is_blacklist'];
$is_whitelist = $status['data']['is_whitelist'];
//$reason = $status['data']['reason'];
if (SAVE_CACHE == 1) {
write_cache_blacklist(); // 写入缓存
}
}
}
}
$is_baned = false;

@ -20,6 +20,7 @@ try {
$refresh_cache = 0;
$refresh_cache_season = 0;
$refresh_cache_subtitle = 0;
$refresh_cache_status = 0;
// 刷新用户信息的缓存
function refresh_userinfo() {
@ -364,7 +365,7 @@ function write_cache_subtitle() {
global $output;
global $cache_type;
global $refresh_cache_subtitle;
if (EP_ID == "") {
return "no cache";
}
@ -410,4 +411,53 @@ function write_cache_subtitle() {
}
$dbh -> exec($sql);
}
// 获取黑白名单缓存
function get_cache_blacklist() {
global $dbh;
global $uid;
global $refresh_cache_status;
$sqlco = "SELECT * FROM `status` WHERE `uid` = '".$uid."'";
$cres = $dbh -> query($sqlco);
$vnum = $cres -> fetch();
if (!$vnum) {
return ["⑨","⑨"];
}
//$uid = $vnum['uid'];
$expired_time = $vnum['expired_time'];
$is_blacklist = $vnum['is_blacklist'];
$is_whitelist = $vnum['is_whitelist'];
//$reason = $vnum['reason'];
if (time() > (int)$expired_time) {
$refresh_cache_status = 1; // 刷新缓存
return ["⑨","⑨"];
}
return [$is_blacklist, $is_whitelist];
}
// 写入黑白名单缓存
function write_cache_blacklist() {
global $dbh;
global $uid;
global $is_blacklist;
global $is_whitelist;
global $refresh_cache_status;
if ($is_blacklist) {
$is_blacklist = 1;
} else {
$is_blacklist = 0;
}
if ($is_whitelist) {
$is_whitelist = 1;
} else {
$is_whitelist = 0;
}
$ts = time() + CACHE_TIME_BLACKLIST;
$sql = "INSERT INTO `status` (`expired_time`,`uid`,`is_blacklist`,`is_whitelist`) VALUES ('".$ts."','".$uid."','".$is_blacklist."','".$is_whitelist."')";
// 刷新缓存
if ($refresh_cache_status == 1) {
$sql = "UPDATE `cache` SET `expired_time` = '".$ts."' WHERE `uid` = '".$uid."' AND `is_blacklist` = '".$is_blacklist."' AND `is_whitelist` = '".$is_whitelist."';";
}
$dbh -> exec($sql);
}
?>

Loading…
Cancel
Save