Skip to content

Commit

Permalink
Upgrade 412 notification (david082321#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
M1saka10010 authored Jan 2, 2022
1 parent 6009a2d commit d461c4f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 12 deletions.
2 changes: 2 additions & 0 deletions intl/gateway/v2/ogv/playurl/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
} else {
$output = get_webpage($url);
}
// 412提醒
check_412($output,$get_area);
// 替换内容
include (ROOT_PATH."utils/replace.php");
// 返回内容给用户
Expand Down
7 changes: 1 addition & 6 deletions pgc/player/api/playurl/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@
$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");
// 返回内容给用户
Expand Down
7 changes: 1 addition & 6 deletions pgc/player/web/playurl/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@
$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");
// 返回内容给用户
Expand Down
23 changes: 23 additions & 0 deletions utils/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
}
?>
42 changes: 42 additions & 0 deletions utils/functions_cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
?>

0 comments on commit d461c4f

Please sign in to comment.