pull/5/head
AisukaYuki 4 years ago
commit 60dca2b831

@ -0,0 +1,4 @@
<?php
// 必须要用户更改UPOS的默认设置改成不替换
exit('{"timelength":16740,"v_base_url":"https://s1.hdslb.com/bfs/static/player/media/error.mp4","v_bandwidth":172775,"v_backup_url":["https://s2.hdslb.com/bfs/static/player/media/error.mp4"],"a_base_url":"https://s1.hdslb.com/bfs/static/player/media/error.mp4","a_bandwidth":172775,"a_backup_url":["https://s2.hdslb.com/bfs/static/player/media/error.mp4"]}');
?>

@ -6,7 +6,7 @@
## 下载:
* [下载(GitHub) v2.8](https://github.com/david082321/BiliRoaming-PHP-Server/raw/main/Server_v2.8.zip)
* [下载(GitHub) v2.9.5](https://github.com/david082321/BiliRoaming-PHP-Server/raw/main/Server_v2.9.5.zip)
## 用法:
@ -64,3 +64,34 @@
* 导入 cache.sql
--------
# 文件功能介绍
├-intl/gateway/v2
│ ├-app
│ │ ├-search/type/index.php (转发到根目录的 index.php 处理)
│ │ └-subtitle/index.php (转发到根目录的 index.php 处理)
│ └-ogv/playurl/index.php (转发到根目录的 index.php 处理)
├-pgc/player/api/playurl/index.php (转发到根目录的 index.php 处理)
├-404.php (肥肠抱歉视频)
├-auth.php (鉴权)
├-cache.php (缓存)[仅缓存使用]
├-cache.sql (导入MySQL用的)[仅缓存使用]
├-config.php (用户设置)
├-index.php (接受上面index.php) <---
├-log.php (缓存用户)[仅缓存使用]
└-replace.php (替换视频)

Binary file not shown.

Binary file not shown.

@ -0,0 +1,68 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')){
exit(BLOCK_RETURN);
}
if (BLOCK_TYPE=="none"){ // 无鉴权模式
// pass
}else if (ACCESS_KEY != ""){ // access_key 存在
if (BLOCK_TYPE == "blacklist"){ // 黑名单鉴权
$url = "https://black.qimo.ink/?access_key=".ACCESS_KEY;
$out = get_webpage($url);
// 如果是黑名单
if ($out=="ban" || $baned == 1){
if (REPLACE_TYPE=="hlw" || REPLACE_TYPE=="tom" || REPLACE_TYPE=="xyy" || REPLACE_TYPE=="404"){ // 替换成葫芦娃、猫和老鼠、喜羊羊、肥肠抱歉
include ("replace.php");
replace();
}else {
exit(BLOCK_RETURN);
}
}
}else if (BLOCK_TYPE == "whitelist"){ // 白名单鉴权
if (SAVE_CACHE==1){ // 是否开启缓存
$uid = get_uid_fromsql(); // 从数据库获取
}else{
$uid = get_uid(); // 从API获取
}
// 是否在白名单内
if (!in_array($uid, $WHITELIST) || $baned == 1) {
if (REPLACE_TYPE=="hlw" || REPLACE_TYPE=="tom" || REPLACE_TYPE=="xyy" || REPLACE_TYPE=="404"){ // 替换成葫芦娃、猫和老鼠、喜羊羊、肥肠抱歉
include ("replace.php");
replace();
}else {
exit(BLOCK_RETURN);
}
}
}
}else{ // access_key 不存在
if (BLOCK_TYPE == "whitelist" || NEED_LOGIN == 1){ // 白名单模式 或 黑名单模式+需要登录
exit(BLOCK_RETURN);
}
}
function get_uid(){
$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";
}
return $uid;
}
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,28 +0,0 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')){
header('HTTP/1.1 404 Not Found');
exit(BLOCK_RETURN);
}
if (ACCESS_KEY != ""){ // access_key 是否存在
$url = "https://black.qimo.ink/?access_key=".ACCESS_KEY;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$out = curl_exec($ch);
curl_close($ch);
// 如果是黑名单
if ($out=="ban"){
if (REPLACE_TYPE=="hlw" || REPLACE_TYPE=="tom" || REPLACE_TYPE=="xyy"){ // 替换成葫芦娃、猫和老鼠、喜羊羊
include ("replace.php");
replace();
}else {
exit(BLOCK_RETURN);
}
}
}else if (NEED_LOGIN == 1){
exit(BLOCK_RETURN);
}
?>

@ -1,13 +1,13 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')){
header('HTTP/1.1 404 Not Found');
exit(BLOCK_RETURN);
}
// 参数
$refresh_cache = 0;
// 判断登录状态
if (ACCESS_KEY ==""){
define('TYPE', 0); //未登录
}else{
@ -23,6 +23,19 @@ if (ACCESS_KEY ==""){
}
}
//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(){
global $dbh;
@ -81,5 +94,4 @@ function write_cache(){
}
}
}
?>

@ -1,6 +1,4 @@
<?php
if(!defined('SYSTEM')){header('HTTP/1.1 404 Not Found');}// 防止外部破解,不可以改
// 封锁
define('BLOCK_TYPE','blacklist'); // 封锁类型none 不封锁, blacklist 黑名单, whitelist 本地白名单
define('REPLACE_TYPE', "tom"); // 是否替换视频(仅黑/白名单时生效)。hlw 葫芦娃, tom 猫和老鼠, xyy 喜羊羊
@ -9,6 +7,14 @@ define('BILIROAMING', 1); //是否要用哔哩漫游才能使用。0 否, 1 是
define('LOCK_AREA', 0); //服务器锁区,须设置$SERVER_AREA。0 否, 1 是
$WHITELIST = array('1', '2', '3'); // 本地白名单,填写 uid可自行添加、删除注意使用英文,和'
// 封锁指定epid视频
define('BAN_EP', 0); //是否开启ban特定视频
//$epid_list = array("369747","371362","371461","371462","371463","371596"); //示范内容:巨人最终季
$epid_list = array();
// 封锁指定cid视频
define('BAN_CID', 0); //是否开启ban特定视频
$cid_list = array();
// 缓存
define('SAVE_CACHE', 0); //开启缓存须配置MySQL。0 否, 1 是
define('CACHE_TIME', 7200); //缓存时长(秒)
@ -29,12 +35,12 @@ define('DB_NAME', '数据库名称'); //数据库名称
$SERVER_AREA = array(); // 空白,不锁区
// API相关
define('CUSTOM_HOST_DEFAULT', 'api.bilibili.com'); // 兼容未发送 area 参数的其他脚本
define('CUSTOM_HOST_CN', 'api.bilibili.com'); // CN 解析api
define('CUSTOM_HOST_HK', 'api.bilibili.com'); // HK 解析api
define('CUSTOM_HOST_TW', 'api.bilibili.com'); // TW 解析api
define('CUSTOM_HOST_TH', 'api.global.bilibili.com'); //泰区 解析api
define('CUSTOM_HOST_SUB', 'app.global.bilibili.com'); //泰区 搜索字幕用api
define('CUSTOM_HOST_DEFAULT', 'https://api.bilibili.com'); // 兼容未发送 area 参数的其他脚本
define('CUSTOM_HOST_CN', 'https://api.bilibili.com'); // CN 解析api
define('CUSTOM_HOST_HK', 'https://api.bilibili.com'); // HK 解析api
define('CUSTOM_HOST_TW', 'https://api.bilibili.com'); // TW 解析api
define('CUSTOM_HOST_TH', 'https://api.global.bilibili.com'); //泰区 解析api
define('CUSTOM_HOST_SUB', 'https://app.global.bilibili.com'); //泰区 搜索字幕用api
// 自定义API,避免集中请求,降低风控几率
//$hk_api = array("host1","host2","host3");//可以自定义其他反代api,例如云函数,CFW
@ -61,4 +67,15 @@ define('AREA', @$_GET['area']);
define('CID', @$_GET['cid']);
define('EP_ID', @$_GET['ep_id']);
define('TS', @$_GET['ts']);
?>
$baned = 0;
if (in_array(EP_ID, $epid_list) && BAN_EP == 1) {
$baned = 1;
}
if (in_array(CID, $cid_list) && BAN_CID == 1) {
$baned = 1;
}
// 防止外部破解
if(!defined('SYSTEM')){
exit(BLOCK_RETURN);
}
?>

@ -1,92 +1,95 @@
<?php
define('SYSTEM', TRUE); // 防止外部破解
define('VERSION', '2.8');
include ("config.php"); // 加载配置
// 防止外部破解
define('SYSTEM', TRUE);
define('VERSION', '2.9.4');
// 加上json的Header
header('Content-Type: application/json; charset=utf-8');
// 加载配置
include ("config.php");
// 缓存用
if (SAVE_CACHE==1){
if (SAVE_CACHE==1) {
include ("log.php");
}
// 服务器锁区
function lock_area(){
if (LOCK_AREA==1){
if ( !empty($SERVER_AREA) && !in_array(AREA, $SERVER_AREA) ){
exit(BLOCK_RETURN);
}
}
}
// 判断要转发的host
$path = explode('/index.php', $_SERVER['PHP_SELF'])[0];
if ($path=="/intl/gateway/v2/ogv/playurl"){
if ($path=="/intl/gateway/v2/ogv/playurl") {
$host = CUSTOM_HOST_TH;
lock_area();
}elseif ($path=="/intl/gateway/v2/app/search/type"){
} elseif ($path=="/intl/gateway/v2/app/search/type") {
$host = CUSTOM_HOST_SUB;
}elseif ($path=="/intl/gateway/v2/app/subtitle"){
} elseif ($path=="/intl/gateway/v2/app/subtitle") {
$host = CUSTOM_HOST_SUB;
}elseif ($path=="/pgc/player/api/playurl"){
if (AREA=="cn"){$host = CUSTOM_HOST_CN;}
else if (AREA=="hk"){$host = CUSTOM_HOST_HK;}
else if (AREA=="tw"){$host = CUSTOM_HOST_TW;}
else {$host = CUSTOM_HOST_DEFAULT;}
} elseif ($path=="/pgc/player/api/playurl") {
if (AREA=="cn") {
$host = CUSTOM_HOST_CN;
} else if (AREA=="hk") {
$host = CUSTOM_HOST_HK;
} else if (AREA=="tw") {
$host = CUSTOM_HOST_TW;
} else {
$host = CUSTOM_HOST_DEFAULT;
}
lock_area();
}else {
} else {
// 欢迎语
exit(WELCOME);
}
// 模块请求都会带上X-From-Biliroaming的请求头为了防止被盗用可以加上请求头判断
$headerStringValue = $_SERVER['HTTP_X_FROM_BILIROAMING'];
if (BILIROAMING==1){
if ($headerStringValue==""){
exit(BLOCK_RETURN);
if ($headerStringValue=="" && BILIROAMING==1) {
exit(BLOCK_RETURN);
}
// 服务器锁区
function lock_area() {
if ( LOCK_AREA=="1" ) {
if ( !empty($SERVER_AREA) && !in_array(AREA, $SERVER_AREA)) {
exit(BLOCK_RETURN);
}
}
}
// 鉴权
if ($path!="/intl/gateway/v2/app/subtitle"){
include (BLOCK_TYPE.".php");
if ($path=="/intl/gateway/v2/ogv/playurl" || $path=="/pgc/player/api/playurl"){
include ("auth.php");
}
// 获取缓存
if (SAVE_CACHE==1){
if (SAVE_CACHE==1) {
include ("cache.php");
$cache = get_cache();
if ($cache != ""){
if ($cache != "") {
exit($cache);
}
}
$url = "https://".$link.$path."?".$_SERVER['QUERY_STRING'];
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RESOLVE,[$link.":443:".$ip]);
// 指定ip回源
if (IP_RESOLVE==1){
$host = $links[array_rand($hosts)];
if (IP_RESOLVE==1) {
$host = $hosts[array_rand($hosts)];
$ip = $ips[array_rand($ips)];
}
// 转发到指定服务器
$url = "https://".$host.$path."?".$_SERVER['QUERY_STRING'];
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
if (IP_RESOLVE==1){curl_setopt($ch,CURLOPT_RESOLVE,[$host.":443:".$ip]);} // 指定ip回源
curl_setopt($ch,CURLOPT_HTTPHEADER, array(
'User-Agent: '.@$_SERVER["HTTP_USER_AGENT"]
));
$output = curl_exec($ch);
curl_close($ch);
$url = $host.$path."?".$_SERVER['QUERY_STRING'];
if (IP_RESOLVE==1) {
$output = get_webpage($url,$host,$ip);
}else {
$output = get_webpage($url);
}
print($output);
// 写入缓存
if (SAVE_CACHE==1){
if (SAVE_CACHE==1) {
write_cache();
}
function get_webpage($url,$host="",$ip=""){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
if (IP_RESOLVE==1) { // 指定ip回源
curl_setopt($ch,CURLOPT_RESOLVE,[$host.":443:".$ip]);
}
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER, array(
'User-Agent: '.@$_SERVER["HTTP_USER_AGENT"]
));
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
?>

@ -1,12 +1,9 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')){
header('HTTP/1.1 404 Not Found');
exit(BLOCK_RETURN);
}
// https://zhuanlan.zhihu.com/p/122967323
//获取访客信息
//pdo连接数据库
$db_host=DB_HOST;
$db_user=DB_USER;
@ -20,6 +17,7 @@ try{
//pass
}
// 判断登录状态
if (ACCESS_KEY !=""){
$sqlco = "SELECT `uid` as num FROM `keys` WHERE `access_key` = '".ACCESS_KEY."'";
$cres = $dbh -> query($sqlco);
@ -38,12 +36,8 @@ if (ACCESS_KEY !=""){
function get_userinfo(){
$sign = md5("access_key=".ACCESS_KEY."&appkey=".APPKEY."&ts=".TS.APPSEC);
$testurl = "https://app.bilibili.com/x/v2/account/myinfo?access_key=".ACCESS_KEY."&appkey=".APPKEY."&ts=".TS."&sign=".$sign;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $testurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
$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"){

@ -1,3 +0,0 @@
<?php
// 无鉴权模式
?>

@ -1,7 +1,6 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')){
header('HTTP/1.1 404 Not Found');
exit(BLOCK_RETURN);
}
@ -12,19 +11,12 @@ function replace(){
$url = 'https://black.qimo.ink/TandJ.php';
}else if (REPLACE_TYPE=="xyy"){
$url = 'https://bili.tuturu.top/xyyjson.php';
}else if (REPLACE_TYPE=="404"){
$url = 'https://'.$_SERVER['HTTP_HOST'].'/404.php';
}else{
$url = 'https://black.qimo.ink/TandJ.php';
}
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER, array(
'User-Agent: '.@$_SERVER["HTTP_USER_AGENT"]
));
$output = curl_exec($ch);
curl_close($ch);
$output = get_webpage($url);
// 分析 output
$array = json_decode($output, true);
$timelength = $array['timelength'];
@ -35,40 +27,18 @@ function replace(){
$a_bandwidth = $array['a_bandwidth'];
$a_backup_url = $array['a_backup_url'];
// 获取缓存
if (SAVE_CACHE==1){
include ("cache.php");
$output2 = get_cache();
}else{
$output2 = "";
global $host;
global $path;
// 判断来源
if ($path=="/intl/gateway/v2/ogv/playurl"){
$type = "intl";
}elseif ($path=="/pgc/player/api/playurl"){
$type = "main";
}
if ($output2 == ""){
global $host;
global $path;
// 判断来源
if ($path=="/intl/gateway/v2/ogv/playurl"){
$type = "intl";
}elseif ($path=="/pgc/player/api/playurl"){
$type = "main";
}
// 转发到指定服务器
$url = "https://".$host.$path."?".$_SERVER['QUERY_STRING'];
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER, array(
'User-Agent: '.@$_SERVER["HTTP_USER_AGENT"]
));
$output2 = curl_exec($ch);
curl_close($ch);
// 写入缓存
if (SAVE_CACHE==1){
$output = $output2;
write_cache();
}
}
// 转发到指定服务器
$url = "https://".$host.$path."?".$_SERVER['QUERY_STRING'];
$output2 = get_webpage($url);
if ($type=="intl"){
// 替换成hop
$array2 = json_decode($output2, true);
@ -115,10 +85,9 @@ function replace(){
}
// 发送内容
header('Content-Type: application/json; charset=utf-8');
$output3 = json_encode($array2);
$output3 = str_replace("\/","/",$output3);
print($output3);
exit();
}
}
?>

@ -1,56 +0,0 @@
<?php
// 防止外部破解
if(!defined('SYSTEM')){
header('HTTP/1.1 404 Not Found');
exit(BLOCK_RETURN);
}
if (ACCESS_KEY != ""){ // access_key 是否存在
if (SAVE_CACHE==1){ // 是否开启缓存
$uid = get_uid_fromsql(); // 从数据库获取
}else{
$uid = get_uid(); // 从API获取
}
// 是否在白名单内
if (in_array($uid, $WHITELIST)) {
// pass
}else{
if (REPLACE_TYPE=="hlw" || REPLACE_TYPE=="tom" || REPLACE_TYPE=="xyy"){ // 替换成葫芦娃、猫和老鼠、喜羊羊
include ("replace.php");
replace();
}else {
exit(BLOCK_RETURN);
}
}
}else{
exit(BLOCK_RETURN);
}
function get_uid(){
$sign = md5("access_key=".ACCESS_KEY."&appkey=".APPKEY."&ts=".TS.APPSEC);
$testurl = "https://app.bilibili.com/x/v2/account/myinfo?access_key=".ACCESS_KEY."&appkey=".APPKEY."&ts=".TS."&sign=".$sign;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $testurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
$array = json_decode($output, true);
$code = $array['code'];
if ($code=="0"){
$uid = $array['data']['mid'];
}else{
$uid = "0";
}
return $uid;
}
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;
}
?>
Loading…
Cancel
Save