-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
440 lines (362 loc) · 13.6 KB
/
api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
<?php
/* ########################################################
# xypaly 智能视频解析整合接口 X by nohacks.cn
# 官方网站: http://nohacks.cn
# 源码获取:http://nohacks.taobao.com
# 模块功能:程序核心,jsonp服务端
# 更新时间:2019.8.31
######################################################### */
//运行目录
define("FCPATH", str_replace("\\", "/", dirname(__FILE__)));
//加载核心类
require_once FCPATH.'/include/class.main.php';
//加载配置文件
require_once FCPATH . '/save/config.php';
define("ROOT_PATH", $CONFIG["ROOT_PATH"]? $CONFIG["ROOT_PATH"] : GlobalBase::is_root());
//输出json格式文件
header('content-type:application/json;charset=utf8'); //header("Content-Disposition:attachment;filename='json.js'");
/*
$filters = array(
"cb" => FILTER_SANITIZE_STRING,
"tp" => FILTER_SANITIZE_STRING,
"url" => FILTER_SANITIZE_URL,
"wd"=>FILTER_SANITIZE_STRING,
"line"=>FILTER_SANITIZE_NUMBER_INT,
"id"=>FILTER_SANITIZE_NUMBER_INT,
"flag" => FILTER_SANITIZE_NUMBER_INT,
"app" => FILTER_UNSAFE_RAW,
"dd"=>FILTER_SANITIZE_NUMBER_INT,
'loadjs'=>FILTER_SANITIZE_NUMBER_INT,
);
//过滤输入参数并赋值
$GET=filter_input_array(INPUT_GET, $filters); foreach ($GET as $key=>$val){$$key=trim($val);}
*/
//循环取传入参数,支持POST和GET
foreach ($_REQUEST as $k => $v) { $$k = trim($v);}
//参数初始化
$cb = isset($cb) && $cb ? $cb : '';
$tp = isset($tp) && $tp ? $tp : '';
$url = isset($url) && $url ? $url : '';
$wd = isset($wd) && utf8($wd) ? $wd : '';
$line = isset($line) && $line ? $line : '0';
$id = isset($id) ? $id : '';
$flag = isset($flag) ? $flag : '';
$app = isset($app) ? $app : 'xysoft';
$dd = isset($dd) && $dd ? $dd : 0;
$loadjs = isset($loadjs) ? $loadjs : 0;
//加载搜索数据
if($wd!=""){
//检测非法关键字
if($CONFIG["socode"]["not_off"]){
$str=base64_decode($CONFIG["socode"]["not_val"]);
if($str!='' && preg_match("/$str/i",$wd) ){exit(json_encode(array('success' => 0,'m'=>'input error!')));}
}
require_once FCPATH."/save/top.inc.php";
require_once FCPATH.'/include/class.db.php';
}
//全局变量,输出信息
$info = array('success' => 0, 'code' => 0);
//公用函数,API接口
if ($tp == 'getnum') {
echo sizeof($jx_url);
exit;
}
if ($tp == 'set') {
setcookie("url_num", $line, time() + 3600 * timecookie);
exit;
}
if ($tp == 'getset') {
exit(isset($_COOKIE["url_num"]) ? $_COOKIE["url_num"] : '0');
}
//全局变量,读写缓存
$cache = new Main_Cache(array("cachetype" => $CONFIG["chche_config"]["type"], "cacheDir" => "./cache", "cacheprot" => $CONFIG["chche_config"]["prot"], 'cacheTime' => GlobalBase::is_time($CONFIG["chche_config"]["time"])));
//加载防火墙规则
Blacklist::parse($CONFIG["BLACKLIST"]);
switch ($tp) {
//取配置参数及线路列表
case 'getparm' :
require_once FCPATH . '/save/yun.data.php';
$info['success'] = 1;
$info['type'] = 'getparm';
$info['app'] = server::lsUserAgen($CONFIG["play"]['all']['AppName']);
$CONFIG["play"]['define']['jx_link'] = $CONFIG["jx_link"];
$CONFIG["play"]['define']['jx_url'] = $CONFIG["jx_url"];
$CONFIG["play"]['define']['live_url'] = $CONFIG["live_url"];
$CONFIG["play"]['define']['jx_link'] = $CONFIG["jx_link"];
$CONFIG["play"]['define']['url_jmp'] = $YUN_DATA["url_jmp"];
$CONFIG["play"]['define']['timeout'] = $CONFIG["timeout"];
$CONFIG["play"]['define']['timecookie'] = $CONFIG["timecookie"];
$CONFIG["play"]['define']['host'] = ROOT_PATH;
$info['val'] = strencode(json_encode($CONFIG["play"]));
break;
//检测线路
case 'lsurl' :
if ($url !== '') {
$info['val'] = $url;
$code = server::lsurl($url);
$info['code'] = $code;
if ($code == 200 || $code == 302 || $code == 301) {
$info['success'] = 1;
$info['info'] = true;
} else {
$info['success'] = 0;
$info['info'] = false;
}
} else {
$info['m'] = "input error";
}
break;
//一次解析对接
case 'link':
if ($url !== '') {
//取缓存数据
$word = $cache->get('link' . $url);
if ($word != "") {
$info = json_decode($word);
} else {
server::GetLinkVideo($url, $info);
if ($info['url']) {
$info['success'] = 1;
$cache->set('link' . $url, json_encode($info));
} else {
$info['m'] = "404";
}
}
} else {
$info['m'] = " url input error";
}
break;
//输出json数据,用于微信对接及搜索补全等功能
case 'json':
if ($wd !== '') {
//取缓存数据
$word = $cache->get('json' . $wd);
if ($word != "") {
$info = json_decode($word);
} else {
include_once FCPATH . "/video/class.yun.php";
$info = YUN::parse(urlencode($wd), 4);
if ($info['success']) {
$cache->set('json' . $wd, json_encode($info));
} else {
$info['m'] = "404";
}
}
} else {
$info['m'] = " wd input error";
}
exit(json_encode($info));
break;
//云解析
default:
include FCPATH . "/video/class.yun.php";
server::parse();
break;
}
server::out($cb, $info);
class server {
//调用解析
public static function parse() {
global $cache, $tp, $url, $wd, $id, $flag, $info;
//标题播放视频
if ($tp == 'wd') {
if ($wd !== '') {
$word = $cache->get('wd.wd' . $wd);
if ($word != "") {
$info = json_decode($word);
} else {
$info = YUN::parse(urlencode($wd), 2);
if ($info['success']) {
$cache->set('wd.wd' . $wd, json_encode($info));
} else {
$info['m'] = "404";
}
}
} else {
$info['m'] = "wd input error";
}
return;
}
//id搜索视频
if ($id != '' && $flag != '') {
$word = $cache->get('id' . $flag . $id);
if ($word != "") {
$info = json_decode($word);
} else {
$info = YUN::parse(array('id' => $id, 'flag' => $flag), 3);
if ($info['success']) {
$cache->set('id'.$flag . $id, json_encode($info));
}
}
return;
//标题搜索视频
} else if ($wd != '') {
$word = $cache->get('wd' . $wd);
if ($word != "") {
$info = json_decode($word);
if($tp==""){ self::uptop($wd);}
} else {
$info = YUN::parse(urlencode($wd), 4);
if ($info['success']) {
$cache->set('wd' . $wd, json_encode($info));
if($tp==""){ self::uptop($wd);}
} else {
$info['m'] = "404";
}
}
//URL播放视频
} else if ($url != '') {
$word = $cache->get('url' . $url);
if ($word != "") {
$info = json_decode($word);
} else {
$info = self::yun($url);
if ($info['success']) {
$cache->set('url' . $url, json_encode($info));
} else {
$info['m'] = "404";
}
}
} else {
$info['m'] = "input error";
}
}
public static function uptop($word){
global $TOPDATA;
$word=str_ireplace(array('<','>','|','*','"','\'',' '),'',strip_tags($word)); //过滤危险字符及html和php标签
$TOPDATA["$word"]++;
return Main_db::save(FCPATH."/save/top.inc.php");
}
//检测url
public static function lsurl($url, $timeout = 10) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_REFERER, $url); //伪装网页来源 URL
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); //超时时间
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //启用301重定向跟踪
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //不显示结果
curl_setopt($ch, CURLOPT_HEADER, 0); //包含头信息
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '0'); // 强制访问https网站
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '0');
curl_exec($ch);
$curl_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $curl_code;
}
//一次解析对接
public static function GetLinkVideo($url, &$DATA) {
global $CONFIG;
foreach ($CONFIG["LINK_URL"] as $val) {
if ($val['off'] == 0) {
continue;
}
$data = trim(self::post($url, $val));
if ($data == '') {
continue;
}
$json = json_decode($data, true);
if (!$json) {
continue;
}
if ($val["val_off"] == 1) {
foreach ($val['val'] as $j => $x) {
$DATA[$x] = $json[$j];
} //转换
if (!empty($val['add'])) {
$DATA = array_merge($val['add'], $DATA);
} //附加
} else {
$DATA = $json;
}
if ($DATA['url']) {
break;
}
}
}
//检测浏览器UA标识
public static function lsUserAgen($key) {
return preg_match('/' . $key . "/i", filter_input(INPUT_SERVER, 'HTTP_USER_AGENT'));
}
public static function yun($url) {
$url = ROOT_PATH . "/video/?url=" . urlencode($url);
$json = self::curl($url);
return json_decode($json, true);
}
public static function out($jsoncallback, &$data) {
$json = json_encode($data);
exit($jsoncallback . '(' . $json . ');');
}
public static function curl($url, $referer = "") {
$params["ua"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36";
$params["referer"] = $referer;
return GlobalBase::curl($url, $params);
}
public static function post($url, $data) {
global $loadjs, $cb;
$a=$data["shell"];
$params["ua"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36";
$fields = "";
$purl = trim($data["path"]);
if ($data['api'] == 0) {
$purl = self::getsrc_match($purl.$url, $data, $fields);
}
$b=base64_decode($a);
//运行前置HTML脚本
if (!empty($data["html"]) && !$loadjs) {
header('content-type:text/html;charset=utf8');
$html = base64_decode($data["html"]);
if (!empty($fields)) {
$html = str_ireplace('$fields', $fields, $html);
file_put_contents("./cache/cache_link.html", $html);
//self::curl(ROOT_PATH."run.htm?time=".time());
$info["success"] = "1";
$info["type"] = "js";
$info["js"] = ROOT_PATH . "cache/cache_link.html?time=" . time();
self::out($cb, $info);
}
}
//运行前置PHP脚本
if (!empty($data["shell"])) { eval($b);}
//变量处理
$fields = base64_decode($data["fields"]);
foreach (explode(",", base64_decode($data["strtr"])) as $val) { $k = str_replace("$", "", $val);$fields = trim(str_replace($val, $$k, $fields));}
//提交参数处理
if ($data["type"] == "0") { $params["fields"] = $fields;} else {$purl.= "?" . $fields; }
//附加头处理
if (!empty($data["header"])) { $params["httpheader"] = $data["header"]; }
//附加cookie处理
if (!empty($data["cookie"])) {$params["cookie"] = $data["cookie"];}
//代理处理
if (!empty($data["proxy"])) {$params["proxy"] = $data["proxy"]; }
return GlobalBase::curl($purl, $params);
}
public static function getsrc_match($url, $data, &$fields) {
$header = "";
$key = "";
$matchs = "";
$info = GlobalBase::curl($url, NULL, $header);
$path = preg_match("#^((http://|https://).*?)\?#", $header['url'], $key) ? $key[1] : "";
//解析播放页
if (preg_match(base64_decode($data['match']), $info, $key)) {
$api = $key[1];
$fields = $key[2];
if (substr($api, 0, 4) == "http") {
return $api;
}
return $path . $api;
//框架
} else if (preg_match_all('{<iframe.*?src="(.*?)".*?</iframe>}', $info, $matchs)) {
//框架循环
foreach ($matchs[1] as $val) {
if (substr($val, 0, 4) != "http") {
$val = $path . $val;
}
exit($val);
return self::getsrc_match($val, $data,$fields);
}
} else {
return false;
}
}
}