diff --git a/api/sjsp/index.php b/api/sjsp/index.php new file mode 100644 index 0000000..a691b6e --- /dev/null +++ b/api/sjsp/index.php @@ -0,0 +1,103 @@ +$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; + } +} + +?> diff --git a/api_info.json b/api_info.json index 498cc11..d95cbc9 100644 --- a/api_info.json +++ b/api_info.json @@ -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返回格式化文本" + } + ] } ] } diff --git a/curl.php b/curl.php new file mode 100644 index 0000000..45060db --- /dev/null +++ b/curl.php @@ -0,0 +1,147 @@ + $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; +} + +