|
发表于 2023-9-12 11:37:14
|
显示全部楼层
安徽省亳州市
<?php
//抖音短视频解析
function DYVideoUrl($url) {
$options = array(
'http' => array(
'header' => "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36\r\n" .
"Cookie: __ac_nonce=064c912c900c3ac916623; __ac_signature=_02B4Z6wo00f01L5qHOgAAIDB3WDcglmtBJi-ShhAAEtYVgMD32HEO-sBLFW3NB8iuzXNM-cBDL.9HYj-8pkRvxyUDQzT6PbjbqQIILoLL4yFDGFUORDaXVHpfsPGd-w5IOqnoXcNRCA6sNgLf0\r\n",
'method' => 'GET',
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
$response = array(
'status' => 201,
'erro' => '信息处理失败!'
);
$jsonResponse = json_encode($response);
return $jsonResponse;
}
$start='<script id="RENDER_DATA" type="application/json">';
$end = '</script><script type="text/javascript';
$jsonData = urldecode(extractTextBetween($result, $start, $end));
$data = json_decode($jsonData, true);
if ($data === null) {
$response = array(
'status' => 201,
'erro' => "JSON 解码失败,错误信息:" . json_last_error_msg()
);
$jsonResponse = json_encode($response);
return $jsonResponse;
} else {
// 处理解码后的数据
$playApi = $data['74931a6b75e09238f154ab1577c994c9']['aweme']['detail']['video']['playApi'];
$title = $data['74931a6b75e09238f154ab1577c994c9']['aweme']['detail']['desc'];
if (empty($playApi)) {
$playApi = $data['0d41ff35420bb89de9d42bbcdbc79ec0']['aweme']['detail']['images'];
$title = $data['0d41ff35420bb89de9d42bbcdbc79ec0']['aweme']['detail']['desc'];
}
$response = array(
'status' => 200,
'playApi' => $playApi,
'title' => $title
);
$jsonResponse = json_encode($response);
return $jsonResponse;
}
$response = array('status' => 201,'erro' => '信息处理失败!');
$jsonResponse = json_encode($response);
return $jsonResponse;
}
//请求参数接口
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (isset($_GET['url'])) {
$shareUrl = $_GET['url'];
if (strpos($shareUrl, "douyin") !== false) {
$videoUrl = DYVideoUrl($shareUrl);
}
echo $videoUrl;
} else {
http_response_code(400);
echo '缺少url参数';
}
} else {
http_response_code(405);
echo '请求方法不支持';
}
function extractTextBetween($string, $start, $end) { //提取内容
$pattern = sprintf(
'/%s(.*?)%s/',
preg_quote($start, '/'),
preg_quote($end, '/')
);
preg_match($pattern, $string, $matches);
if (isset($matches[1])) {
return $matches[1];
}
return null;
}
$result = extractTextBetween($text, $start, $end);
if ($result !== null) {
return $result;
} else {
return "未找到匹配的内容";
}
?>
然后呢,没有打包的易源码或者模块吗?发现这个py的语言看不懂,不会用啊,谢谢老板,给你点赞,搞个易语言作者能用吧 |
|