Merge pull request #2 from david082321/main

update to v2.9.18
pull/10/head
AisukaYuki 4 years ago committed by GitHub
commit 43863a94e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,6 +3,7 @@
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/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
</IfModule>

@ -6,7 +6,7 @@
## 下载:
* [下载(GitHub) v2.9.16](https://github.com/david082321/BiliRoaming-PHP-Server/raw/main/Server_v2.9.16.zip)
* [下载(GitHub) v2.9.18](https://github.com/david082321/BiliRoaming-PHP-Server/raw/main/Server_v2.9.18.zip)
## 用法:
@ -56,6 +56,8 @@
rewrite "^/intl/gateway/v2/app/subtitle?(.*)$" /intl/gateway/v2/app/subtitle/index.php?$1 last;
rewrite "^/intl/gateway/v2/ogv/view/app/season?(.*)$" /intl/gateway/v2/ogv/view/app/season/index.php?$1 last;
}
## (非必要步骤) 缓存
@ -66,7 +68,7 @@
* 导入 cache.sql
## (非必要步骤) 支持网页版油猴脚本
## (非必要步骤,实验性) 支持网页版油猴脚本
* [油猴脚本地址](https://github.com/ipcjs/bilibili-helper/blob/user.js/packages/unblock-area-limit/README.md)
@ -84,6 +86,8 @@
#####    https://example.com
* 注意:不配置上面的 「禁用 301 转址」,少部分 泰国/东南亚番剧 将无法在网页版加载。(哔哩漫游无影响)
--------
# 文件功能介绍
@ -96,7 +100,11 @@
  └─subtitle/index.php (转发到根目录的 index.php 处理)
 └─ogv/playurl/index.php (转发到根目录的 index.php 处理)
 └─ogv
   ├─playurl/index.php (转发到根目录的 index.php 处理)
   └─view/app/season/index.php (转发到根目录的 index.php 处理)
├─pgc/player/
@ -108,6 +116,8 @@
├─cache.php (缓存)[仅缓存使用]
├─cache_season.php (缓存泰国/东南亚season)[仅缓存使用]
├─cache.sql (导入MySQL用的)[仅缓存使用]
├─config.php (用户设置)
@ -116,4 +126,8 @@
├─log.php (缓存用户)[仅缓存使用]
└─replace.php (替换视频)
├─replace.php (替换视频)
├─sign.php (重签名)[未公开源码]
└─resign.php (替换access_key)[未公开源码]

Binary file not shown.

Binary file not shown.

@ -8,9 +8,9 @@ $refresh_cache = 0;
// 判断登录状态
if ($member_type > 0) {
// pass
}else if (ACCESS_KEY == "") {
} else if (ACCESS_KEY == "") {
$member_type = 0; //未登录
}else{
} else {
// 判断大会员
$sqlco = "SELECT `due_date` FROM `keys` WHERE `access_key` = '".ACCESS_KEY."'";
$cres = $dbh -> query($sqlco);
@ -29,10 +29,10 @@ $db_user=DB_USER;
$db_pass=DB_PASS;
$db_name=DB_NAME;
$dbh='mysql:host='.$db_host.';'.'dbname='.$db_name;
try{
try {
$dbh = new PDO($dbh,$db_user,$db_pass);
//echo '连接成功';
}catch(PDOException $e) {
} catch(PDOException $e) {
//pass
}
@ -73,7 +73,7 @@ function write_cache() {
if ($code == "0") {
$a = explode('mid=', $output);
$out = $a[0];
for($j=1; $j<count($a)-1; $j++) {
for ($j=1; $j<count($a)-1; $j++) {
//echo $a[$j];
$b = explode('orderid=', $a[$j]);
$out = $out.'orderid='.$b[1];
@ -86,11 +86,11 @@ function write_cache() {
}
$dbh -> exec($sql);
// 缓存地区错误
}else if (in_array(AREA, $SERVER_AREA)) {
} else if (in_array(AREA, $SERVER_AREA)) {
$sql ="INSERT INTO `cache` (`add_time`,`area`,`type`,`cid`,`ep_id`,`cache`) VALUES ('9999999999','".AREA."','".$member_type."','".CID."','".EP_ID."','$output')";
if ($code == "-10403") {// 10403 地区错误
$dbh -> exec($sql);
}else if ($code == "-404" && AREA == "th") {// 404 泰版地区错误
} else if ($code == "-404" && AREA == "th") {// 404 泰版地区错误
$dbh -> exec($sql);
}
}

@ -0,0 +1,70 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')) {exit(BLOCK_RETURN);}
// 参数
$refresh_cache_season = 0;
//pdo连接数据库
$db_host=DB_HOST;
$db_user=DB_USER;
$db_pass=DB_PASS;
$db_name=DB_NAME;
$dbh='mysql:host='.$db_host.';'.'dbname='.$db_name;
try {
$dbh = new PDO($dbh,$db_user,$db_pass);
//echo '连接成功';
} catch(PDOException $e) {
//pass
}
// 获取缓存
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 `cid` = '0' AND `ep_id` = '".SS_ID."'";
$cres = $dbh -> query($sqlco);
$vnum = $cres -> fetch();
$cache = $vnum['cache'];
$add_time = $vnum['add_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;
}else{
// 准备刷新缓存
$refresh_cache_season = 1;
return "";
}
}
return "";
}
// 写入缓存
function write_cache_season() {
global $dbh;
global $output;
global $refresh_cache_season;
$ts = time();
$array = json_decode($output, true);
$code = $array['code'];
if ($code == "0") {
$sql ="INSERT INTO `cache` (`add_time`,`area`,`type`,`cid`,`ep_id`,`cache`) VALUES ('$ts','season','0','0','".SS_ID."','$output')";
// 刷新缓存
if ($refresh_cache_season == 1) {
$sql = "UPDATE `cache` SET `add_time` = '$ts', `cache` = '$output' WHERE `area` = '".AREA."' AND `type` = '".$member_type."' AND `cid` = '".CID."' AND `ep_id` = '".EP_ID."';";
}
$dbh -> exec($sql);
// 缓存 404 错误
} else if ($code == "-404") {
$ts = $ts + CACHE_TIME_SEASON_404;
$sql ="INSERT INTO `cache` (`add_time`,`area`,`type`,`cid`,`ep_id`,`cache`) VALUES ('$ts','season','0','0','".SS_ID."','$output')";
$dbh -> exec($sql);
}
}
?>

@ -23,11 +23,14 @@ $cid_list = array();
// 缓存
define('SAVE_CACHE', 0); //开启缓存须配置MySQL。0 否, 1 是
define('CACHE_TIME', 10000); //缓存时长目前最长可到14400秒
define('CACHE_TIME', 60*60*3); //缓存时长目前最长可到14400秒
define('DB_HOST', 'localhost');
define('DB_USER', '这里改成登录的用户名'); //登录的用户名
define('DB_PASS', '登录的密码'); //登录的密码
define('DB_NAME', '数据库名称'); //数据库名称
// 缓存泰国 season
define('CACHE_TIME_SEASON', 60*60*24); //泰国 season 的缓存时长(秒)
define('CACHE_TIME_SEASON_404', 60*60*24*3); //泰国 season (返回404时的)缓存时长(秒)
// 服务器所在的地区
/*
@ -39,6 +42,8 @@ define('DB_NAME', '数据库名称'); //数据库名称
$SERVER_AREA = array('th');
*/
$SERVER_AREA = array(); // 空白,不锁区
// 指定锁区(不论上面怎么设置,只要填这个,可以锁定指定的地区)
$BAN_SERVER_AREA = array(); // 空白,不锁区
// API相关
define('CUSTOM_HOST_DEFAULT', 'https://api.bilibili.com'); // 兼容未发送 area 参数的其他脚本
@ -71,6 +76,7 @@ define('APPSEC', '560c52ccd288fed045859ed18bffd973');
define('ACCESS_KEY', @$_GET['access_key']);
define('CID', @$_GET['cid']);
define('EP_ID', @$_GET['ep_id']);
define('SS_ID', @$_GET['season_id']);
define('BILIROAMING_VERSION', @$_SERVER['HTTP_X_FROM_BILIROAMING']);
if (@$_GET['area'] == '' && BILIROAMING_VERSION == '') {
define('AREA', 'noarea');
@ -91,8 +97,12 @@ if (in_array(EP_ID, $epid_list) && BAN_EP == 1) {
if (in_array(CID, $cid_list) && BAN_CID == 1) {
$baned = 1;
}
if (in_array(AREA, $BAN_SERVER_AREA)) {
$baned = 1;
exit(BLOCK_RETURN);
}
// 防止外部破解
if(!defined('SYSTEM')) {
exit(BLOCK_RETURN);
}
?>
?>

@ -1,7 +1,7 @@
<?php
// 防止外部破解
define('SYSTEM', TRUE);
define('VERSION', '2.9.16');
define('VERSION', '2.9.18');
// 加载配置
include ("config.php");
// 加上json的Header
@ -18,7 +18,7 @@ if (SAVE_CACHE == 1) {
// 判断要转发的内容
$path = explode('/index.php', $_SERVER['PHP_SELF'])[0];
$query = $_SERVER['QUERY_STRING'];
if ($path == "/intl/gateway/v2/ogv/playurl") {
if ($path == "/intl/gateway/v2/ogv/playurl" || $path == "/intl/gateway/v2/ogv/view/app/season") {
$host = CUSTOM_HOST_TH;
} elseif ($path == "/intl/gateway/v2/app/search/type" || $path == "/intl/gateway/v2/app/subtitle") {
$host = CUSTOM_HOST_SUB;
@ -55,13 +55,15 @@ if ($path == "/intl/gateway/v2/ogv/playurl" || $path == "/pgc/player/api/playurl
}
}
// 模块请求都会带上X-From-Biliroaming的请求头为了防止被盗用可以加上请求头判断WEB接口暂不限制
if (BILIROAMING_VERSION == "" && BILIROAMING == 1 && $path != "/pgc/player/web/playurl") {
if (BILIROAMING_VERSION == "" && BILIROAMING == 1 && $path != "/pgc/player/web/playurl" && $path != "/intl/gateway/v2/ogv/view/app/season") {
exit(BLOCK_RETURN);
}
// 判断 playurl
$playurl = 0;
if ($path != "/intl/gateway/v2/app/search/type" && $path != "/intl/gateway/v2/app/subtitle") {
if ($path != "/intl/gateway/v2/app/search/type" && $path != "/intl/gateway/v2/app/subtitle" && $path != "/intl/gateway/v2/ogv/view/app/season") {
$playurl = 1;
} else if ($path == "/intl/gateway/v2/ogv/view/app/season") {
$playurl = 2;
}
// 鉴权
if ($playurl == 1) { //playurl
@ -69,17 +71,24 @@ if ($playurl == 1) { //playurl
} elseif ($path == "/intl/gateway/v2/app/subtitle" && $baned == 1) { //泰国字幕
exit(BLOCK_RETURN);
}
// 替换key
// 替换access_key
if (ACCESS_KEY != "" && $playurl == 1) {
//include("resign.php");
}
// 获取缓存
// 获取缓存 (playurl)
if (SAVE_CACHE == 1 && $playurl == 1) {
include ("cache.php");
$cache = get_cache();
if ($cache != "") {
exit($cache);
}
// 获取缓存 (东南亚season)
} else if (SAVE_CACHE == 1 && $playurl == 2) {
include ("cache_season.php");
$cache = get_cache_season();
if ($cache != "") {
exit($cache);
}
}
// 指定ip回源
if (IP_RESOLVE == 1) {
@ -90,14 +99,16 @@ if (IP_RESOLVE == 1) {
$url = $host.$path."?".$query;
if (IP_RESOLVE == 1) {
$output = get_webpage($url,$host,$ip);
}else {
} else {
$output = get_webpage($url);
}
$output = str_replace("\u0026","&",$output);
print($output);
// 写入缓存
if (SAVE_CACHE == 1 && $playurl == 1) {
write_cache();
write_cache(); // 写入playurl
} else if (SAVE_CACHE == 1 && $playurl == 2) {
write_cache_season(); //写入东南亚season
}
function get_webpage($url,$host="",$ip="") {

@ -0,0 +1,3 @@
<?php
include($_SERVER['DOCUMENT_ROOT']."/index.php");
?>
Loading…
Cancel
Save