3.0.8 -> 4.1.0 更新日志:
1. 完全重构(不再都转发到根目录的 index.php)
2. 重构数据库(需要重新创建数据库)
3. 移除 season 特殊参数(不再需要)
4. 修复缓存 season 时,只有 EP_ID 时出现的问题(并且同时修改 SS_ID 储存的栏位)
5. 服务器封锁用户时,会提示原因
6. 转发请求时,加上 CURLOPT_SSL_VERIFYPEER 以免部分服务器无法请求到内容
7. 修正缓存时长
8. 缓存用户key时,添加过期检测(CACHE_TIME_USER)

未公开的代码更新日志:
1. 新增替换大会员功能
3. 新增 add_key.php 方便导入key到数据库
2. 新增自动刷新大陆/东南亚key(需提供 refresh_token)
pull/19/head v4.1.0
david082321 3 years ago
parent 0d85fc51ec
commit 2f1da05af7

@ -1,11 +1,12 @@
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule pgc/player/api/playurl pgc/player/api/playurl/index.php
RewriteRule pgc/player/web/playurl pgc/player/web/playurl/index.php
RewriteRule intl/gateway/v2/app/search/type intl/gateway/v2/app/search/type/index.php
RewriteRule intl/gateway/v2/app/subtitle intl/gateway/v2/app/subtitle/index.php
RewriteRule intl/gateway/v2/ogv/playurl intl/gateway/v2/ogv/playurl/index.php
RewriteRule intl/gateway/v2/ogv/view/app/season intl/gateway/v2/ogv/view/app/season/index.php
RewriteRule intl/gateway/v2/app/search/type intl/gateway/v2/app/search/type/index.php
RewriteRule intl/gateway/v2/app/subtitle intl/gateway/v2/app/subtitle/index.php
RewriteRule pgc/player/api/playurl pgc/player/api/playurl/index.php
RewriteRule pgc/player/web/playurl pgc/player/web/playurl/index.php
RewriteRule x/intl/passport-login/oauth2/refresh_token x/intl/passport-login/oauth2/refresh_token/index.php
RewriteRule x/v2/search/type x/v2/search/type/index.php
RewriteRule x/web-interface/search/type x/web-interface/search/type/index.php
</IfModule>

@ -49,17 +49,19 @@
#...(中间略过,请加在配置文件最底下)...
rewrite "^/pgc/player/api/playurl?(.*)$" /pgc/player/api/playurl/index.php?$1 last;
rewrite "^/intl/gateway/v2/app/search/type?(.*)$" /intl/gateway/v2/app/search/type/index.php?$1 last;
rewrite "^/pgc/player/web/playurl?(.*)$" /pgc/player/web/playurl/index.php?$1 last;
rewrite "^/intl/gateway/v2/app/subtitle?(.*)$" /intl/gateway/v2/app/subtitle/index.php?$1 last;
rewrite "^/intl/gateway/v2/ogv/playurl?(.*)$" /intl/gateway/v2/ogv/playurl/index.php?$1 last;
rewrite "^/intl/gateway/v2/app/search/type?(.*)$" /intl/gateway/v2/app/search/type/index.php?$1 last;
rewrite "^/intl/gateway/v2/ogv/view/app/season?(.*)$" /intl/gateway/v2/ogv/view/app/season/index.php?$1 last;
rewrite "^/intl/gateway/v2/app/subtitle?(.*)$" /intl/gateway/v2/app/subtitle/index.php?$1 last;
rewrite "^/pgc/player/api/playurl?(.*)$" /pgc/player/api/playurl/index.php?$1 last;
rewrite "^/intl/gateway/v2/ogv/view/app/season?(.*)$" /intl/gateway/v2/ogv/view/app/season/index.php?$1 last;
rewrite "^/pgc/player/web/playurl?(.*)$" /pgc/player/web/playurl/index.php?$1 last;
rewrite "^/x/intl/passport-login/oauth2/refresh_token?(.*)$" /x/intl/passport-login/oauth2/refresh_token/index.php?$1 last;
rewrite "^/x/v2/search/type?(.*)$" /x/v2/search/type/index.php?$1 last;
@ -123,6 +125,8 @@
├─x/
 ├─intl/passport-login/oauth2/refresh_token/index.php (东南亚APP refresh_token)
 ├─v2/search/type/index.php (APP 搜索)
 └─web-interface/search/type/index.php (WEB 搜索)
@ -131,8 +135,6 @@
 ├─auth.php (鉴权)
 ├─cache.php (缓存playurl判断是否为大会员)[仅缓存使用]
 ├─fuck_search.php (在搜索中添加提示)[未公开]
 ├─fuck_sub.php (添加东南亚番剧字幕)[未公开]
@ -141,14 +143,16 @@
 ├─functions_cache.php (功能函数合集)[仅缓存使用]
│ ├─lock_area.php (锁区、web接口判断)
│ ├─functions_cache_key.php (功能函数合集)[仅缓存使用][未公开]
 ├─log.php (缓存用户)[仅缓存使用]
 ├─lock_area.php (锁区、web接口判断)
 ├─process.php (处理用户传入参数)
 ├─refresh_token.php (自动刷新访问密钥)[未公开]
 ├─refresh_token_th.php (自动刷新访问密钥)[未公开]
 ├─replace.php (修改返回内容)
 ├─replace_playurl.php (替换视频)
@ -157,6 +161,10 @@
 └─version.php (版本信息、Header)
├─.htaccess (防止重复的 301 转址)
├─add_key.php (添加访问密钥)[仅缓存使用][未公开]
├─cache.sql (导入MySQL用的)[仅缓存使用]
├─config.php (设置本程序各种参数) <──参数设置在这里

@ -6,7 +6,7 @@ START TRANSACTION;
CREATE TABLE `cache` (
`id` int(10) UNSIGNED NOT NULL COMMENT 'id',
`add_time` int(11) NOT NULL COMMENT '添加时间',
`expired_time` int(11) NOT NULL COMMENT '到期时间',
`area` varchar(10) DEFAULT NULL,
`type` tinyint(4) NOT NULL,
`cache_type` varchar(100) NOT NULL,
@ -37,4 +37,19 @@ ALTER TABLE `keys`
ALTER TABLE `keys`
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id';
CREATE TABLE `my_keys` (
`id` int(10) UNSIGNED NOT NULL COMMENT 'id',
`expired_time` int(11) NOT NULL COMMENT '到期时间',
`type` tinyint(4) NOT NULL COMMENT '类型',
`uid` int(20) DEFAULT NULL COMMENT '用户ID',
`access_token` varchar(100) NOT NULL,
`refresh_token` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='我的key';
ALTER TABLE `my_keys`
ADD PRIMARY KEY (`id`);
ALTER TABLE `my_keys`
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id';
COMMIT;

@ -33,9 +33,10 @@ define('CACHE_TIME', 60*60*1.95); // Playurl缓存时长目前最长
define('CACHE_TIME_SEASON', 60*60*1); // 泰国 season 的缓存时长(秒)
// 发生错误时的缓存时长
define('CACHE_TIME_10403', 60*60*24*14); // 返回10403地区错误时的缓存时长
define('CACHE_TIME_412', 60*60*24*7); // 返回412IP被风控时的缓存时长
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*24*1); // 返回其他错误时的缓存时长(秒)
define('CACHE_TIME_USER', 60*60*24*1); //缓存用户key的时长
// MySQL数据库
define('DB_HOST', 'localhost');
@ -77,7 +78,8 @@ define('CUSTOM_HOST_TW_WEB_SEARCH', 'https://api.bilibili.com'); // TW 搜索api
// API相关(东南亚服务器)
define('CUSTOM_HOST_TH', 'https://api.global.bilibili.com'); // 泰区 解析api
define('CUSTOM_HOST_TH_SEARCH', 'https://app.global.bilibili.com'); // 泰区 搜索api
define('CUSTOM_HOST_TH_SUB', 'https://app.global.bilibili.com'); // 泰区 字幕用api
define('CUSTOM_HOST_TH_SUB', 'https://app.global.bilibili.com'); // 泰区 字幕api
define('CUSTOM_HOST_TH_TOKEN', 'https://passport.biliintl.com'); // 泰区 刷新TOKEN api
// 自定义API,避免集中请求,降低风控几率
//$hk_api = array('host1','host2','host3');// 可以自定义其他反代api,例如云函数,CFW
@ -102,10 +104,11 @@ $hosts = array('workers.dev', 'workers.dev');
define('WELCOME', "file"); // 首页画面。text 文字, file 加载文件
define('WELCOME_TEXT', "Success!<br>Power by BiliRoaming-PHP-Server. Ver".VERSION); // 首页欢迎语
define('WELCOME_FILE', "hello.php"); // 首页文件
define('BLOCK_RETURN', '{"code":-10403,"message":"抱歉您已被封锁"}'); // 封锁返回内容
// 这个参数,不懂就别改
define('APPKEY', '1d8b6e7d45233436');
define('APPSEC', '560c52ccd288fed045859ed18bffd973');
// 【禁忌功能】替换访问密钥
define('MAGIC_KEY', '123'); // 请用密码生成器随机生成任意内容然后把123改成你生成的内容。(建议长一点)
define('RESIGN_CN', 0); // 替换成大会员。0 否, 1 是
define('RESIGN_TH', 0); // 替换成泰国登录会员。0 否, 1 是
define('RESIGN_TH_PAID', 0); // 替换成泰国付费会员。0 否, 1 是
?>

@ -38,4 +38,4 @@
<body>
Success!<br>Power by <a href="https://github.com/david082321/BiliRoaming-PHP-Server">BiliRoaming-PHP-Server</a>. Ver<?php print(VERSION); ?>
</body>
</html>
</html>

@ -8,13 +8,11 @@ include ($_SERVER['DOCUMENT_ROOT']."/config.php");
include(ROOT_PATH."utils/version.php");
// 加载functions
include (ROOT_PATH."utils/functions.php");
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 缓存用
if (SAVE_CACHE == 1) {
include (ROOT_PATH."utils/functions_cache.php");
include (ROOT_PATH."utils/log.php");
}
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 设置host
if ((CID != "" || EP_ID != "") && WEB_ON == 1) {
// Web接口

@ -10,8 +10,6 @@ include(ROOT_PATH."utils/version.php");
include (ROOT_PATH."utils/functions.php");
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 缓存用
//// (无)
// 设置host
$host = CUSTOM_HOST_TH_SEARCH;
// 锁区、web接口、X-From-Biliroaming

@ -10,8 +10,6 @@ include(ROOT_PATH."utils/version.php");
include (ROOT_PATH."utils/functions.php");
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 缓存用
//// (无)
// 设置host
$host = CUSTOM_HOST_TH_SUB;
// 锁区、web接口、X-From-Biliroaming
@ -38,4 +36,4 @@ include (ROOT_PATH."utils/replace.php");
print($output);
// 写入缓存
//// (无)
?>
?>

@ -8,13 +8,11 @@ include ($_SERVER['DOCUMENT_ROOT']."/config.php");
include(ROOT_PATH."utils/version.php");
// 加载functions
include (ROOT_PATH."utils/functions.php");
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 缓存用
if (SAVE_CACHE == 1) {
include (ROOT_PATH."utils/functions_cache.php");
include (ROOT_PATH."utils/log.php");
}
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 设置host
$host = CUSTOM_HOST_TH;
// 锁区、web接口、X-From-Biliroaming

@ -8,20 +8,17 @@ include ($_SERVER['DOCUMENT_ROOT']."/config.php");
include(ROOT_PATH."utils/version.php");
// 加载functions
include (ROOT_PATH."utils/functions.php");
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 缓存用
if (SAVE_CACHE == 1) {
include (ROOT_PATH."utils/functions_cache.php");
include (ROOT_PATH."utils/log.php");
}
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 设置host
$host = CUSTOM_HOST_TH;
// 特殊参数(移除因为还有ep_id而且目前没有检查参数)
//$query = "appkey=7d089525d3611b1c&autoplay=0&build=1052002&c_locale=&channel=master&lang=&locale=zh_SG&mobi_app=bstar_a&platform=android&s_locale=zh_SG&season_id=".SS_ID."&sim_code=&spmid=&ts=".TS;
// 锁区、web接口、X-From-Biliroaming
include (ROOT_PATH."utils/lock_area.php");
// 鉴权、替换access_key、获取缓存
// include (ROOT_PATH."utils/auth.php"); // 鉴权
if (SAVE_CACHE == 1) {
get_cache_season(); // 获取缓存
}

@ -8,13 +8,11 @@ include ($_SERVER['DOCUMENT_ROOT']."/config.php");
include(ROOT_PATH."utils/version.php");
// 加载functions
include (ROOT_PATH."utils/functions.php");
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 缓存用
if (SAVE_CACHE == 1) {
include (ROOT_PATH."utils/functions_cache.php");
include (ROOT_PATH."utils/log.php");
}
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 设置host
$host = get_host($type,$cache_type);
// 锁区、web接口、X-From-Biliroaming
@ -48,4 +46,4 @@ print($output);
if (SAVE_CACHE == 1) {
write_cache(); // 写入playurl
}
?>
?>

@ -8,13 +8,11 @@ include ($_SERVER['DOCUMENT_ROOT']."/config.php");
include(ROOT_PATH."utils/version.php");
// 加载functions
include (ROOT_PATH."utils/functions.php");
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 缓存用
if (SAVE_CACHE == 1) {
include (ROOT_PATH."utils/functions_cache.php");
include (ROOT_PATH."utils/log.php");
}
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 设置host
$host = get_host($type,$cache_type);
// 锁区、web接口、X-From-Biliroaming

@ -1,13 +1,38 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')) {exit(BLOCK_RETURN);}
if(!defined('SYSTEM')) {exit();}
if (ACCESS_KEY != "") { // access_key 存在
if (SAVE_CACHE == 1) { // 是否开启缓存
$uid = get_uid_fromsql(); // 从数据库获取
} else {
$uid = get_uid(); // 从API获取
// 判断登录状态
if (ACCESS_KEY != "" && SAVE_CACHE == 1) {
$out = get_userinfo_fromsql();
$uid = $out[0];
$add_time = $out[1];
if ($uid == "" || $uid == "0") {
$out = get_userinfo();
$uid = $out[0];
$due = $out[1];
if ($uid != "0") {
$sql = " INSERT INTO `keys` (`add_time`,`uid`,`access_key`,`due_date`) VALUES (now(),'$uid','".ACCESS_KEY."','$due')";
$dbh -> exec($sql);
} elseif (NEED_LOGIN == 1) {
$baned = 20;
block($baned);
}
} elseif (strtotime(time()) - strtotime($add_time) >= CACHE_TIME_USER) {
refresh_userinfo();
}
} elseif (ACCESS_KEY != "") {
$out = get_userinfo();
$uid = $out[0];
$due = $out[1];
if ($uid == "0" && NEED_LOGIN == 1) {
$baned = 20;
block($baned);
}
}
// 开始鉴权
if (ACCESS_KEY != "") { // access_key 存在
if (BLOCK_TYPE == "blacklist") { // 黑名单鉴权
$url = "https://black.qimo.ink/?access_key=".ACCESS_KEY;
$out = get_webpage($url);
@ -17,7 +42,8 @@ if (ACCESS_KEY != "") { // access_key 存在
include (ROOT_PATH."utils/replace_playurl.php");
replace_playurl();
} else {
block();
$baned = 21;
block($baned);
}
}
} else if (BLOCK_TYPE == "whitelist") { // 白名单鉴权
@ -27,7 +53,8 @@ if (ACCESS_KEY != "") { // access_key 存在
include (ROOT_PATH."utils/replace_playurl.php");
replace_playurl();
} else {
block();
$baned = 22;
block($baned);
}
}
}
@ -35,7 +62,8 @@ if (ACCESS_KEY != "") { // access_key 存在
if (CID == "13073143" || CID == "120453316") { // 漫游测速
//pass
} else if (BLOCK_TYPE == "whitelist" || NEED_LOGIN == 1) { // 白名单模式 或 黑名单模式+需要登录
block();
$baned = 23;
block($baned);
}
}
?>

@ -1,22 +0,0 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')) {exit(BLOCK_RETURN);}
// 判断登录状态
if ($member_type > 0) {
// pass
} else if (ACCESS_KEY == "") {
$member_type = 0; //未登录
} else {
// 判断大会员
$sqlco = "SELECT `due_date` FROM `keys` WHERE `access_key` = '".ACCESS_KEY."'";
$cres = $dbh -> query($sqlco);
$vnum = $cres -> fetch();
$due = $vnum['due_date'];
if ((int)$due > time()*1000) {
$member_type = 2; // 大会员
} else {
$member_type = 1; // 不是大会员
}
}
?>

@ -1,3 +1,3 @@
<?php
//未公开
?>
// 【禁忌功能】代码已隐藏
?>

@ -1,3 +1,3 @@
<?php
//未公开
?>
// 【禁忌功能】代码已隐藏
?>

@ -1,6 +1,7 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')) {exit(BLOCK_RETURN);}
if(!defined('SYSTEM')) {exit();}
$member_type = 0; // 判断用户状态
function get_webpage($url,$host="",$ip="") {
$ch = curl_init();
@ -15,6 +16,7 @@ function get_webpage($url,$host="",$ip="") {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"User-Agent: ".@$_SERVER["HTTP_USER_AGENT"]
));
@ -76,26 +78,27 @@ function get_host($type,$cache_type) {
return $host;
}
function get_uid() {
// 获取用户信息
function get_userinfo() {
global $member_type;
$sign = md5("access_key=".ACCESS_KEY."&appkey=".APPKEY."&ts=".TS.APPSEC);
$url = "https://app.bilibili.com/x/v2/account/myinfo?access_key=".ACCESS_KEY."&appkey=".APPKEY."&ts=".TS."&sign=".$sign;
$output = get_webpage($url);
$array = json_decode($output, true);
$code = $array['code'];
if ($code=="0") {
$uid = $array['data']['mid'];
}else{
$uid = "0";
if ($code == "0") {
$out[0] = $array['data']['mid'];
$out[1] = $array['data']['vip']['due_date'];
if ((int)$out[1] > time()*1000) {
$member_type = 2; // 大会员
} else {
$member_type = 1; // 不是大会员
}
} else {
$out[0] = "0";
$out[1] = "0";
$member_type = 0; //未登录
}
return $uid;
return $out;
}
function get_uid_fromsql() {
global $dbh;
$sqlco = "SELECT `uid` FROM `keys` WHERE `access_key` = '".ACCESS_KEY."'";
$cres = $dbh -> query($sqlco);
$vnum = $cres -> fetch();
$uid = $vnum['uid'];
return $uid;
}
?>
?>

@ -1,7 +1,6 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')) {exit(BLOCK_RETURN);}
if(!defined('SYSTEM')) {exit();}
//pdo连接数据库
$db_host = DB_HOST;
$db_user = DB_USER;
@ -13,61 +12,80 @@ try {
//echo '连接成功';
}catch(PDOException $e) {
//pass
//echo $e;
echo '数据库连接失敗';
}
// 参数(判断是否刷新缓存)
$refresh_cache = 0;
$refresh_cache_season = 0;
function get_userinfo() {
$sign = md5("access_key=".ACCESS_KEY."&appkey=".APPKEY."&ts=".TS.APPSEC);
$url = "https://app.bilibili.com/x/v2/account/myinfo?access_key=".ACCESS_KEY."&appkey=".APPKEY."&ts=".TS."&sign=".$sign;
$output = get_webpage($url);
$array = json_decode($output, true);
$code = $array['code'];
if ($code == "0") {
$out[0] = $array['data']['mid'];
$out[1] = $array['data']['vip']['due_date'];
} else {
$out[0] = "0";
$out[1] = "0";
}
return $out;
}
// 刷新用户信息的缓存
function refresh_userinfo() {
global $dbh;
global $member_type;
$out = get_userinfo();
$uid = $out[0];
$due = $out[1];
if ($uid != "0") {
$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."';";
}
$dbh -> exec($sql);
}
?>
?>

@ -1,20 +1,23 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')) {exit(BLOCK_RETURN);}
if(!defined('SYSTEM')) {exit();}
// 锁区、web接口、X-From-Biliroaming
if ($cache_type == "app"){
if ($type == 1 && LOCK_AREA == 1 && !empty($SERVER_AREA) && !in_array(AREA, $SERVER_AREA)) {
block(); // 判断服务器锁区
$baned = 30;
block($baned); // 判断服务器锁区
}
if (BILIROAMING_VERSION == "" && BILIROAMING == 1) {
if (WEB_ON == 1 && $path == "/intl/gateway/v2/ogv/view/app/season"){
// web接口会用到东南亚season特殊放行
} else {
block(); // 没带上 X-From-Biliroaming 的请求头
$baned = 31;
block($baned); // 没带上 X-From-Biliroaming 的请求头
}
}
} elseif ($cache_type == "web" && WEB_ON == 0) {
block(); // 服务器不开web接口
$baned = 32;
block($baned); // 服务器不开web接口
}
?>
?>

@ -1,24 +0,0 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')) {exit(BLOCK_RETURN);}
// 判断登录状态
if (ACCESS_KEY != "") {
$sqlco = "SELECT `uid` as num, `add_time` FROM `keys` WHERE `access_key` = '".ACCESS_KEY."'";
$cres = $dbh -> query($sqlco);
$vnum = $cres -> fetch();
$uid = $vnum['num'];
$add_time = $vnum['add_time'];
if ($uid == "" || $uid == "0") {
$out = get_userinfo();
$uid = $out[0];
$due = $out[1];
if ($uid != "0") {
$sql = " INSERT INTO `keys` (`add_time`,`uid`,`access_key`,`due_date`) VALUES (now(),'$uid','".ACCESS_KEY."','$due')";
$dbh -> exec($sql);
}
} elseif (strtotime(now()) - strtotime($add_time) >= 60*60*24*1) {
$uid = refresh_userinfo();
}
}
?>

@ -1,6 +1,6 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')) {exit(BLOCK_RETURN);}
if(!defined('SYSTEM')) {exit();}
// 判断要转发的内容
$path = explode('/index.php', $_SERVER['PHP_SELF'])[0];
@ -14,7 +14,8 @@ define('BILIROAMING_VERSION', @$_SERVER['HTTP_X_FROM_BILIROAMING']);
$baned = 0;
if (BILIROAMING_VERSION == '') {
if (BILIROAMING == 1 && WEB_ON == 0) { //仅限漫游用户且未开放web脚本
$baned = 1;
$baned = 10;
block($baned);
}
if (@$_GET['area'] == '' || @$_GET['area'] == 'false') { //web脚本
define('AREA', 'noarea');
@ -32,18 +33,55 @@ if (@$_GET['ts'] == '') {
define('TS', @$_GET['ts']);
}
if (in_array(EP_ID, $epid_list) && BAN_EP == 1) {
$baned = 1;
$baned = 11;
block($baned);
}
if (in_array(CID, $cid_list) && BAN_CID == 1) {
$baned = 1;
$baned = 12;
block($baned);
}
if (in_array(AREA, $BAN_SERVER_AREA)) {
$baned = 1;
block();
$baned = 13;
block($baned);
}
function block(){
function block($baned){
switch ($baned) {
case 10:
$reason = "服务器限漫游使用";
break;
case 11:
$reason = "ep_id黑名单";
break;
case 12:
$reason = "cid黑名单";
break;
case 13:
case 30:
$reason = "area黑名单";
break;
case 20:
$reason = "访问密钥已过期或不存在(脚本设置左下角重新授权)";
break;
case 21:
$reason = "uid黑名单";
break;
case 22:
$reason = "uid不在白名单";
break;
case 23:
$reason = "未提供访问密钥(漫游需要登录、脚本需要授权)";
break;
case 31:
$reason = "此API仅限漫游用户若误封请到这里提出 github.com/david082321/BiliRoaming-PHP-Server/issues";
break;
case 32:
$reason = "服务器未开放web接口";
break;
default:
$reason = "未知错误";
}
http_response_code(404);
exit(BLOCK_RETURN);
exit('{"code":-418,"message":"'.$reason.'"}');
}
?>

@ -1,6 +1,6 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')) {exit(BLOCK_RETURN);}
if(!defined('SYSTEM')) {exit();}
// 替换内容
$output = str_replace("\u0026","&",$output);
@ -18,4 +18,4 @@ switch ($type) {
case 3: // 东南亚APP 字幕
break;
}
?>
?>

@ -1,6 +1,6 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')) {exit(BLOCK_RETURN);}
if(!defined('SYSTEM')) {exit();}
function replace_playurl() {
global $host;

@ -1,3 +1,3 @@
<?php
//未公开
?>
// 【禁忌功能】代码已隐藏
?>

@ -1,11 +1,17 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')) {exit(BLOCK_RETURN);} // 防止外部破解,此行勿改
if(!defined('SYSTEM')) {exit();} // 防止外部破解,此行勿改
define('VERSION', '4.0.1');
define('VERSION', '4.1.0');
// 加上json的Header
header('Content-Type: application/json; charset=utf-8');
// 加上web的Header
header("Access-Control-Allow-Origin: https://www.bilibili.com");
header("Access-Control-Allow-Credentials: true");
?>
// 这个参数,不懂就别改
define('APPKEY', '1d8b6e7d45233436');
define('APPSEC', '560c52ccd288fed045859ed18bffd973');
define('APPKEY_TH', '7d089525d3611b1c');
define('APPSEC_TH', 'acd495b248ec528c2eed1e862d393126');
?>

@ -0,0 +1,39 @@
<?php
// 加载配置
include ($_SERVER['DOCUMENT_ROOT']."/config.php");
// 加载版本
include(ROOT_PATH."utils/version.php");
// 处理用户传入参数
if (@$_GET['access_token']!=''){
define('ACCESS_TOKEN', @$_GET['access_token']);
define('REFRESH_TOKEN', @$_GET['refresh_token']);
} else {
define('ACCESS_TOKEN', @$_POST['access_token']);
define('REFRESH_TOKEN', @$_POST['refresh_token']);
}
if (ACCESS_TOKEN == '' || REFRESH_TOKEN == '') {
exit("Error");
}
// 开始获取
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://passport.biliintl.com/x/intl/passport-login/oauth2/refresh_token");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded; charset=utf-8"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
if (PROXY_ON == 1) {
curl_setopt($ch, CURLOPT_PROXYTYPE, PROXY_TYPE);
curl_setopt($ch, CURLOPT_PROXY, PROXY_IP);
}
if (IP_RESOLVE == 1) {
curl_setopt($ch, CURLOPT_RESOLVE, [$host.":443:".$ip]);
}
$PostData = "access_token=".ACCESS_TOKEN."&refresh_token=".REFRESH_TOKEN;
curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData);
header('Content-Type: application/json; charset=utf-8');
$output = curl_exec($ch);
curl_close($ch);
// 返回内容给用户
print($output);
?>

@ -10,8 +10,6 @@ include(ROOT_PATH."utils/version.php");
include (ROOT_PATH."utils/functions.php");
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 缓存用
//// (无)
// 设置host
$host = get_host($type,$cache_type);
// 锁区、web接口、X-From-Biliroaming

@ -10,8 +10,6 @@ include(ROOT_PATH."utils/version.php");
include (ROOT_PATH."utils/functions.php");
// 处理用户传入参数
include (ROOT_PATH."utils/process.php");
// 缓存用
//// (无)
// 设置host
$host = get_host($type,$cache_type);
// 锁区、web接口、X-From-Biliroaming

Loading…
Cancel
Save