$sql = " UPDATE `keys` SET `uid` = '$uid', `due_date` = '$due' WHERE `keys`.`access_key` = '".ACCESS_KEY."';";
$sql = " UPDATE `keys` SET `add_time` = now(), `uid` = '".$uid."', `due_date` = '".$due."' WHERE `keys`.`access_key` = '".ACCESS_KEY."';";
$dbh -> exec($sql);
if ((int)$due > time()*1000) {
$member_type = 2; // 大会员
} else {
$member_type = 1; // 不是大会员
}
} else {
$sql = " UPDATE `keys` SET `expired` = '1' WHERE `keys`.`access_key` = '".ACCESS_KEY."';";
$dbh -> exec($sql);
$member_type = 0; //未登录
}
return $uid;
}
// 获取缓存
// 从缓存获取用户信息
function get_userinfo_fromsql() {
global $dbh;
global $member_type;
$sqlco = "SELECT `uid`,`add_time`,`expired` FROM `keys` WHERE `access_key` = '".ACCESS_KEY."'";
$cres = $dbh -> query($sqlco);
$vnum = $cres -> fetch();
if (!$vnum){
$member_type = 0; //未登录
return ["0","0","0"];
}
$out[0] = $vnum['uid'];
$out[1] = $vnum['add_time'];
$out[2] = $vnum['expired'];
if ((int)$out[2] > time()*1000) {
$member_type = 2; // 大会员
} else {
$member_type = 1; // 不是大会员
}
return $out;
}
// 获取playurl缓存
function get_cache() {
global $dbh;
global $member_type;
global $cache_type;
global $refresh_cache;
$ts = time();
$sqlco = "SELECT `cache`,`add_time` FROM `cache` WHERE `area` = '".AREA."' AND `type` = '".$member_type."' AND `cache_type` = '".$cache_type."' AND `cid` = '".CID."' AND `ep_id` = '".EP_ID."'";
$sqlco = "SELECT `cache`,`expired_time` FROM `cache` WHERE `area` = '".AREA."' AND `type` = '".$member_type."' AND `cache_type` = '".$cache_type."' AND `cid` = '".CID."' AND `ep_id` = '".EP_ID."'";
$cres = $dbh -> query($sqlco);
$vnum = $cres -> fetch();
$cache = $vnum['cache'];
$add_time = $vnum['add_time'];
if (!$vnum){
return "";
}
@$cache = $vnum['cache'];
@$expired_time = $vnum['expired_time'];
//修复读取问题
$cache = str_replace("u0026", "&", $cache);
$cache = str_replace("\r", "\\r", $cache);
$cache = str_replace("\n", "\\n", $cache);
if ($cache != "") {
if ((int)$add_time + CACHE_TIME >= $ts) {
return $cache;
if (time() <= (int)$expired_time) {
exit($cache);
} else {
// 准备刷新缓存
$refresh_cache = 1;
@ -76,7 +94,7 @@ function get_cache() {
return "";
}
// 写入缓存
// 写入playurl缓存
function write_cache() {
global $dbh;
global $SERVER_AREA;
@ -85,9 +103,22 @@ function write_cache() {
global $output;
global $refresh_cache;
$ts = time();
$array = json_decode($output, true);
$code = $array['code'];
switch ($code) {
case "0":
//pass
// 删掉用户mid
$array = json_decode($output, true);
$code = $array['code'];
$a = explode('mid=', $output);
$out = $a[0];
for ($j = 1; $j <count($a)-1;$j++){
//echo $a[$j];
$b = explode('orderid=', $a[$j]);
$out = $out.'orderid='.$b[1];
}
$output = $out.$a[count($a)-1];
$ts = $ts + CACHE_TIME;
break;
case "-10403":
$ts = $ts + CACHE_TIME_10403;
@ -101,42 +132,41 @@ function write_cache() {
default:
$ts = $ts + CACHE_TIME_OTHER;
}
$array = json_decode($output, true);
$code = $array['code'];
$a = explode('mid=', $output);
$out = $a[0];
for ($j = 1; $j <count($a)-1;$j++){
//echo $a[$j];
$b = explode('orderid=', $a[$j]);
$out = $out.'orderid='.$b[1];
}
$output = $out.$a[count($a)-1];
$sql = "INSERT INTO `cache` (`add_time`,`area`,`type`,`cache_type`,`cid`,`ep_id`,`cache`) VALUES ('$ts','".AREA."','".$member_type."','".$cache_type."','".CID."','".EP_ID."','$output')";
$sql = "INSERT INTO `cache` (`expired_time`,`area`,`type`,`cache_type`,`cid`,`ep_id`,`cache`) VALUES ('".$ts."','".AREA."','".$member_type."','".$cache_type."','".CID."','".EP_ID."','".$output."')";
// 刷新缓存
if ($refresh_cache == 1) {
$sql = "UPDATE `cache` SET `add_time` = '$ts', `cache` = '$output' WHERE `area` = '".AREA."' AND `type` = '".$member_type."' AND `cache_type` = '".$cache_type."' AND `cid` = '".CID."' AND `ep_id` = '".EP_ID."';";
$sql = "UPDATE `cache` SET `expired_time` = '".$ts."', `cache` = '".$output."' WHERE `area` = '".AREA."' AND `type` = '".$member_type."' AND `cache_type` = '".$cache_type."' AND `cid` = '".CID."' AND `ep_id` = '".EP_ID."';";
}
$dbh -> exec($sql);
}
// 获取缓存
// 获取season缓存
function get_cache_season() {
global $dbh;
global $member_type;
global $refresh_cache_season;
$ts = time();
$sqlco = "SELECT * FROM `cache` WHERE `area` = 'season' AND `type` = '0' AND `cache_type` = 'season' AND `cid` = '0' AND `ep_id` = '".SS_ID."'";
if (EP_ID != ""){
$sqlco = "SELECT `cache`,`expired_time` FROM `cache` WHERE `area` = 'season' AND `type` = '0' AND `cache_type` = 'season' AND `cid` = '0' AND `ep_id` = '".EP_ID."'";
} elseif (SS_ID != "") {
$sqlco = "SELECT `cache`,`expired_time` FROM `cache` WHERE `area` = 'season' AND `type` = '0' AND `cache_type` = 'season' AND `cid` = '".SS_ID."' AND `ep_id` = '0'";
} else {
return "";
}
//$sqlco = "SELECT * FROM `cache` WHERE `area` = 'season' AND `type` = '0' AND `cache_type` = 'season' AND `cid` = '".SS_ID."' AND `ep_id` = '".EP_ID."'";
$cres = $dbh -> query($sqlco);
$vnum = $cres -> fetch();
$cache = $vnum['cache'];
$add_time = $vnum['add_time'];
if (!$vnum){
return "";
}
@$cache = $vnum['cache'];
@$expired_time = $vnum['expired_time'];
//修复读取问题
$cache = str_replace("u0026", "&", $cache);
$cache = str_replace("\r", "\\r", $cache);
$cache = str_replace("\n", "\\n", $cache);
if ($cache != "") {
if ((int)$add_time + CACHE_TIME_SEASON >= $ts) {
return $cache;
if (time() <= (int)$expired_time) {
exit($cache);
} else {
// 准备刷新缓存
$refresh_cache_season = 1;
@ -146,31 +176,45 @@ function get_cache_season() {
return "";
}
// 写入缓存
// 写入season缓存
function write_cache_season() {
global $dbh;
global $output;
global $refresh_cache_season;
$ts = time();
if ($code == "0") {
// pass
} elseif ($code == "-10403") {
$ts = $ts + CACHE_TIME_10403;
} elseif ($code == "-404") {
$ts = $ts + CACHE_TIME_404;
} elseif ($code == "-412") {
$ts = $ts + CACHE_TIME_412;
} else {
$ts = $ts + CACHE_TIME_OTHER;
}
$array = json_decode($output, true);
$code = $array['code'];
$sql = "INSERT INTO `cache` (`add_time`,`area`,`type`,`cache_type`,`cid`,`ep_id`,`cache`) VALUES ('$ts','season','0','season','0','".SS_ID."','$output')";
switch ($code) {
case "0":
$ts = $ts + CACHE_TIME_SEASON;
break;
case "-10403":
$ts = $ts + CACHE_TIME_10403;
break;
case "-404":
$ts = $ts + CACHE_TIME_404;
break;
case "-412":
$ts = $ts + CACHE_TIME_412;
break;
default:
$ts = $ts + CACHE_TIME_OTHER;
}
if (EP_ID != ""){
$ep_id = EP_ID;
$ss_id = "0";
} elseif (SS_ID != "") {
$ss_id = SS_ID;
$ep_id = "0";
} else {
return "no cache";
}
$sql = "INSERT INTO `cache` (`expired_time`,`area`,`type`,`cache_type`,`cid`,`ep_id`,`cache`) VALUES ('".$ts."','season','0','season','".$ss_id."','".$ep_id."','".$output."')";
// 刷新缓存
if ($refresh_cache_season == 1) {
$sql = "UPDATE `cache` SET `add_time` = '$ts', `cache` = '$output' WHERE `area` = '".AREA."' AND `cache_type` = 'season' AND `type` = '".$member_type."' AND `cid` = '".CID."' AND `ep_id` = '".EP_ID."';";
$sql = "UPDATE `cache` SET `expired_time` = '".$ts."', `cache` = '".$output."' WHERE `area` = '".AREA."' AND `cache_type` = 'season' AND `cid` = '".$ss_id."' AND `ep_id` = '".$ep_id."';";