Upgrade 412 notification (#29)

pull/30/head
m1saka 3 years ago committed by GitHub
parent 6009a2d4a7
commit d461c4f428
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -37,6 +37,8 @@ if (IP_RESOLVE == 1) {
} else {
$output = get_webpage($url);
}
// 412提醒
check_412($output,$get_area);
// 替换内容
include (ROOT_PATH."utils/replace.php");
// 返回内容给用户

@ -38,12 +38,7 @@ if (IP_RESOLVE == 1) {
$output = get_webpage($url);
}
// 412提醒
if (TG_NOTIFY == 1) {
$status = json_decode($output, true);
if ($status['code'] == -412) {
file_get_contents(TG_BOT_API.'/'.TG_BOT_KEY.'/sendMessage?chat_id='.TG_CHAT_ID.'&text=破服务器412啦地区:' . $get_area);
}
}
check_412($output,$get_area);
// 替换内容
include (ROOT_PATH."utils/replace.php");
// 返回内容给用户

@ -38,12 +38,7 @@ if (IP_RESOLVE == 1) {
$output = get_webpage($url);
}
// 412提醒
if (TG_NOTIFY == 1) {
$status = json_decode($output, true);
if ($status['code'] == -412) {
file_get_contents(TG_BOT_API.'/'.TG_BOT_KEY.'/sendMessage?chat_id='.TG_CHAT_ID.'&text=破服务器412啦地区:' . $get_area);
}
}
check_412($output,$get_area);
// 替换内容
include (ROOT_PATH."utils/replace.php");
// 返回内容给用户

@ -135,4 +135,27 @@ function get_userinfo() {
}
return $out;
}
function check_412($output,$get_area){// 412提醒
if (TG_NOTIFY == 1) {
$status = json_decode($output, true);
if(SAVE_CACHE == 0){
if ($status['code'] == -412) {
file_get_contents(TG_BOT_API.'/'.TG_BOT_KEY.'/sendMessage?chat_id='.TG_CHAT_ID.'&text=破服务器412啦地区:' . $get_area);
}
} else {
$latest_code = read_status($get_area);
if($latest_code != $status['code']){
if($status['code'] == -412){
file_get_contents(TG_BOT_API.'/'.TG_BOT_KEY.'/sendMessage?chat_id='.TG_CHAT_ID.'&text=破服务器412啦地区:' . $get_area);
write_status($status['code'],$get_area);
} else {
if($latest_code == -412){
file_get_contents(TG_BOT_API.'/'.TG_BOT_KEY.'/sendMessage?chat_id='.TG_CHAT_ID.'&text=破服务器恢复啦,地区:' . $get_area);
}
write_status(0,$get_area);
}
}
}
}
}
?>

@ -460,4 +460,46 @@ function write_cache_blacklist() {
}
$dbh -> exec($sql);
}
//读取上次解析状态
function read_status($area){
global $dbh;
$result = $dbh -> query("SHOW TABLES LIKE 'status_code'");
$row = $result -> fetchAll();
//判断表是否存在
if ( count($row) == '1' ) {
$sqlco = "SELECT `code` FROM `status_code` WHERE `area` = '".$area."'";
$result = $dbh -> query($sqlco);
$code = $result -> fetch();
return $code['code'];
} else {
return 0;
}
}
//写入此次解析状态
function write_status($code,$area) {
global $dbh;
$result = $dbh -> query("SHOW TABLES LIKE 'status_code'");
$row = $result -> fetchAll();
//判断表是否存在
if ( count($row) == '1' ) {
$sql = "UPDATE `status_code` SET `time` = '".time()."', `code` = '".$code."' WHERE `area` = '".$area."';";
$dbh -> exec($sql);
} else {
$sql = "CREATE TABLE status_code (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
area VARCHAR(10),
code VARCHAR(10),
time INT
)";
$dbh -> exec($sql);
$sql = "INSERT INTO `status_code` (`area`,`code`,`time`) VALUES ('cn','".$code."','".time()."')";
$dbh -> exec($sql);
$sql = "INSERT INTO `status_code` (`area`,`code`,`time`) VALUES ('hk','".$code."','".time()."')";
$dbh -> exec($sql);
$sql = "INSERT INTO `status_code` (`area`,`code`,`time`) VALUES ('tw','".$code."','".time()."')";
$dbh -> exec($sql);
$sql = "INSERT INTO `status_code` (`area`,`code`,`time`) VALUES ('th','".$code."','".time()."')";
$dbh -> exec($sql);
}
}
?>

Loading…
Cancel
Save