[PHP] 纯文本查看 复制代码<?php
//
application/json");
$url=$_POST['url'];
for ($i=1;$i<=strlen($_POST['url']);$i++){
if(substr($_POST['url'],$i,1)==' '){
$url=substr($url,0,$i-1);
}
}
$url = isset($url) ? $url : die("参数不能为空");
$UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36";
$html = VideoCurlGet($url,true,$UserAgent);
preg_match('~video_id=(.*?)&line~', $html, $video_id);
preg_match('~cover: "(.*?)"~', $html, $cover);
if(!isset($video_id[1]) || !isset($cover[1])){
$result['code'] = 400;
$result['msg'] ="链接错误";
exit(json_encode($result));
}
$video_id = trim($video_id[1]);
$cover = trim($cover[1]);
$html = VideoCurlGet("https://aweme.snssdk.com/aweme/v1/play/?video_id=".$vid."&line=0",0);
preg_match('~Location: (.*?)\n~', $html, $location);
if(!isset($location[1])){
$result['code'] = 400;
$result['msg'] = '获取错误';
$result['code']="0";
exit(json_encode($result));
}
$location = trim($location[1]);
$result['code'] = 200;
$result['msg'] = "获取成功";
$result['video_url'] = $location;
$result['cover_url'] = $cover;
$result['code']="1";
//加入数据库
exit(json_encode($result));
function VideoCurlGet($url, $idFllow=false, $UserAgent = '')
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
#关闭重定向
if($idFllow){
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
}
if($UserAgent){
curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
}
curl_setopt($curl, CURLOPT_HEADER, 1);
if($cookie!=""){
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
}
#关闭SSL
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
#返回数据不直接显示
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}