添加随机视频
This commit is contained in:
103
api/sjsp/index.php
Normal file
103
api/sjsp/index.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
Header('content-type: application/json');
|
||||
require ('../../curl.php');//引进封装好的curl文件
|
||||
require ('../../need.php');//引用封装好的函数文件
|
||||
|
||||
/* End */
|
||||
|
||||
$name = @$_REQUEST["msg"];
|
||||
$type = @$_REQUEST["type"];
|
||||
|
||||
new rand_video(['msg'=>$name, 'type'=>$type]);
|
||||
|
||||
class rand_video
|
||||
{
|
||||
public $id = array(
|
||||
"网红" => "5930e061e7bce72ce01371ae",
|
||||
"明星" => "5930e046e7bce72ce013719c",
|
||||
"热舞" => "5930e081e7bce72ce01371c8",
|
||||
"风景" => "5930e16ee7bce72ce013725f",
|
||||
"游戏" => "5930e009e7bce72ce0137170",
|
||||
"动物" => "5930e22ee7bce72ce01372f3",
|
||||
'动漫'=>'5930e065e7bce72ce01371b1'
|
||||
);
|
||||
public $skip = array(
|
||||
"网红" => 1000,
|
||||
"明星" => 850,
|
||||
"热舞" => 470,
|
||||
"风景" => 800,
|
||||
"游戏" => 1100,
|
||||
"动物" => 300,
|
||||
'动漫'=> 2800
|
||||
);
|
||||
public $info = [];
|
||||
public $array = [];
|
||||
public $message;
|
||||
public function __construct($array)
|
||||
{
|
||||
foreach($array as $k=>$v) $this->info[$k] = $v;
|
||||
$this->parameterException();
|
||||
}
|
||||
public function parameterException()
|
||||
{
|
||||
if(!isset($this->info['msg']) || !$this->info['msg'] || !isset($this->id[$this->info['msg']]))
|
||||
{
|
||||
$this->info['msg'] = '动漫';
|
||||
}
|
||||
return $this->start();
|
||||
}
|
||||
public function start()
|
||||
{
|
||||
$skip = mt_rand(0, $this->skip[$this->info['msg']]);
|
||||
$url = 'https://service.videowp.adesk.com/v1/videowp/category/'.$this->id[$this->info['msg']].'?limit=30&skip='.$skip.'&adult=false&first=0&order=hot';
|
||||
// echo $url;
|
||||
$data = json_decode(need::teacher_curl($url, [
|
||||
'Header'=>[
|
||||
'Accept-Language'=>'zh-CN,zh;q=0.8',
|
||||
'User-Agent'=>'132,tencent',
|
||||
'Session-Id'=>' ',
|
||||
'Host'=>'service.videowp.adesk.com',
|
||||
'Connection'=>'Keep-Alive',
|
||||
'Accept-Encoding'=>'gzip'
|
||||
],
|
||||
'ua'=>'132,tencent'
|
||||
]), true);
|
||||
if(!$data || !$data['res']['videowp'])
|
||||
{
|
||||
return $this->exec(['code'=>-1, 'text'=>'获取失败,未知错误']);
|
||||
} else {
|
||||
$data = $data['res']['videowp'];
|
||||
$rand = array_rand($data, 1);
|
||||
$data = $data[$rand];
|
||||
// print_r($data);
|
||||
$tag = (isset($data['tag']) && $data['tag'] ?'#'.join(' #', explode(' ', $data['tag'])) : '#'.$data['name']);
|
||||
$url = $data['video'];
|
||||
$cover = $data['img'];
|
||||
return $this->exec(['code'=>1, 'text'=>'获取成功', 'data'=>['img'=>$cover, 'mold'=>$tag, 'url'=>$url]], "±img={$cover}±\n{$tag}\n{$url}");
|
||||
}
|
||||
}
|
||||
public function exec($array, $message = null)
|
||||
{
|
||||
$message = !$message ? $array['text'] : $message;
|
||||
$this->array = $array;
|
||||
$this->message = $message;
|
||||
return $this->result();
|
||||
}
|
||||
public function result()
|
||||
{
|
||||
$info = $this->info;
|
||||
$type = isset($info['type']) ? $info['type'] : 'json';
|
||||
Switch($type)
|
||||
{
|
||||
case 'text':
|
||||
need::send($this->message, 'text');
|
||||
break;
|
||||
default:
|
||||
need::send($this->array, 'json');
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -277,6 +277,26 @@
|
||||
"description": "返回格式[json|text],默认为json。json返回详细的物流轨迹数据,text返回格式化的文本信息"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "随机视频",
|
||||
"description": "获取随机视频,支持多个分类,返回视频地址、封面和标签信息",
|
||||
"path": "/api/sjsp/index.php",
|
||||
"method": "GET",
|
||||
"params": [
|
||||
{
|
||||
"name": "msg",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "视频分类[网红|明星|热舞|风景|游戏|动物|动漫],默认为动漫"
|
||||
},
|
||||
{
|
||||
"name": "type",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "返回格式[json|text],默认为json。json返回视频信息,text返回格式化文本"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
147
curl.php
Normal file
147
curl.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
* @author 教书先生
|
||||
* @link https://blog.oioweb.cn
|
||||
* @date 2020年11月12日18:00:30
|
||||
* @msg PHPCurl封装的方法
|
||||
*/
|
||||
|
||||
$ip = Rand_IP();
|
||||
|
||||
function teacher_curl($url, $paras = array())
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
if (@$paras['Header']) {
|
||||
$Header = $paras['Header'];
|
||||
} else {
|
||||
$Header[] = "Accept:*/*";
|
||||
$Header[] = "Accept-Encoding:gzip,deflate,sdch";
|
||||
$Header[] = "Accept-Language:zh-CN,zh;q=0.8";
|
||||
$Header[] = "Connection:close";
|
||||
$Header[] = 'X-FORWARDED-FOR:'.Rand_IP();
|
||||
$Header[] = 'CLIENT-IP:'.Rand_IP();
|
||||
$Header[] = 'REMOTE_ADDR:'.Rand_IP();
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $Header);
|
||||
if (@$paras['ctime']) { // 连接超时
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $paras['ctime']);
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
|
||||
}
|
||||
if (@$paras['rtime']) { // 读取超时
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $paras['rtime']);
|
||||
}
|
||||
if (@$paras['post']) {
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $paras['post']);
|
||||
}
|
||||
if (@$paras['header']) {
|
||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
}
|
||||
if (@$paras['cookie']) {
|
||||
curl_setopt($ch, CURLOPT_COOKIE, $paras['cookie']);
|
||||
}
|
||||
if (@$paras['refer']) {
|
||||
if ($paras['refer'] == 1) {
|
||||
curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_REFERER, $paras['refer']);
|
||||
}
|
||||
}
|
||||
if (@$paras['ua']) {
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $paras['ua']);
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
|
||||
}
|
||||
if (@$paras['nobody']) {
|
||||
curl_setopt($ch, CURLOPT_NOBODY, 1);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
if (@$paras['GetCookie']) {
|
||||
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
$result = curl_exec($ch);
|
||||
preg_match_all("/Set-Cookie: (.*?);/m", $result, $matches);
|
||||
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
||||
$header = substr($result, 0, $headerSize); //状态码
|
||||
$body = substr($result, $headerSize);
|
||||
$ret = [
|
||||
"Cookie" => $matches, "body" => $body, "header" => $header, 'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE)
|
||||
];
|
||||
curl_close($ch);
|
||||
return $ret;
|
||||
}
|
||||
$ret = curl_exec($ch);
|
||||
if (@$paras['loadurl']) {
|
||||
$Headers = curl_getinfo($ch);
|
||||
$ret = $Headers['redirect_url'];
|
||||
}
|
||||
curl_close($ch);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function Rand_IP(){
|
||||
#第一种方法,直接生成
|
||||
$ip2id= round(rand(600000, 2550000) / 10000);
|
||||
$ip3id= round(rand(600000, 2550000) / 10000);
|
||||
$ip4id= round(rand(600000, 2550000) / 10000);
|
||||
#第二种方法,随机抽取
|
||||
$arr_1 = array("218","218","66","66","218","218","60","60","202","204","66","66","66","59","61","60","222","221","66","59","60","60","66","218","218","62","63","64","66","66","122","211");
|
||||
$randarr= mt_rand(0,count($arr_1)-1);
|
||||
$ip1id = $arr_1[$randarr];
|
||||
return $ip1id.".".$ip2id.".".$ip3id.".".$ip4id;
|
||||
}
|
||||
#获取重定向请求头
|
||||
function getResponseHeader($url) {
|
||||
$ch = curl_init($url);
|
||||
$httpheader = [];
|
||||
$httpheader[] = 'X-FORWARDED-FOR:'.Rand_IP();
|
||||
$httpheader[] = 'CLIENT-IP:'.Rand_IP();
|
||||
#请求头中添加cookie
|
||||
$httpheader[] = 'cookie:did=web_'.md5(time() . mt_rand(1,1000000)).'; didv='.time().'000;clientid=3; client_key=6589'.rand(1000, 9999);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER,$httpheader);
|
||||
#以下两句设置返回响应头不返回响应体
|
||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
curl_setopt($ch, CURLOPT_NOBODY, true);
|
||||
#返回数据不直接输出
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$content = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $content;
|
||||
}
|
||||
#获取响应体
|
||||
function getResponseBody($url) {
|
||||
$ch = curl_init();
|
||||
#5秒超时
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5000);
|
||||
#设置默认ua 这里经常测试,尽量用手机的ua,电脑的ua获取不到数据
|
||||
curl_setopt($ch, CURLOPT_USERAGENT,'User-Agent: Mozilla/5.0 (Linux; Android 5.1.1; vivo X9 Plus Build/LMY48Z) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36');
|
||||
#把随机ip添加进请求头
|
||||
$httpheader = [];
|
||||
$httpheader[] = 'X-FORWARDED-FOR:'.Rand_IP();
|
||||
$httpheader[] = 'CLIENT-IP:'.Rand_IP();
|
||||
#请求头中添加cookie
|
||||
$httpheader[] = 'cookie:did=web_'.md5(time() . mt_rand(1,1000000)).'; didv='.time().'000;';
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
|
||||
#返回数据不直接输出
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
#设置请求地址
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
#关闭ssl验证
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
#设置默认referer
|
||||
curl_setopt($ch, CURLOPT_REFERER, 'https://www.moestack.com');
|
||||
#get方式请求
|
||||
curl_setopt($ch, CURLOPT_POST, false);
|
||||
$contents = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $contents;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user