[PHP] 纯文本查看 复制代码
<?php
if ($_REQUEST['url']) {
$ids = explode('/', parse_url(restoreUrl(matchUrl($_REQUEST['url'])))['path'])[3];
$videoinfo = get_curl('https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=' . $ids)->item_list[0];
$video = geturl(str_ireplace('playwm', 'play', $videoinfo->video->play_addr->url_list[0]));
$code = $videoinfo->status_code;
if ($code == 0) {
$pic = $videoinfo->video->cover->url_list[0];
$desc = $videoinfo->desc;
$data['code'] = 'success';
$data['title'] = $desc;
$data['pic'] = $pic;
$data['video'] = json_decode($video)->longUrl;
} else {
$data['code'] = 'error';
$data['msg'] = '接口异常,请联系接口管理员!';
}
echo json_encode($data);
} else {
$data['code'] = 'error';
$data['msg'] = '请输入抖音链接!';
die(json_encode($data));
}// 短网址转换长网址
function restoreUrl($shortUrl)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $shortUrl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1');
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_NOBODY, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
$data = curl_exec($curl);
$curlInfo = curl_getinfo($curl);
curl_close($curl);
if ($curlInfo['http_code'] == 301 || $curlInfo['http_code'] == 302) {
return $curlInfo['redirect_url'];
} else {
return;
}
}
//curl
function get_curl($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua = 0, $nobaody = 0)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$httpheader[] = "Accept: */*";
$httpheader[] = "Accept-Encoding: gzip,deflate,sdch";
$httpheader[] = "Accept-Language: zh-CN,zh;q=0.8";
$httpheader[] = "Connection: close";
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
if ($header) {
curl_setopt($ch, CURLOPT_HEADER, true);
}
if ($cookie) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
if ($referer) {
if ($referer == 1) {
curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
} else {
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
}
if ($ua) {
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
} else {
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36');
}
if ($nobaody) {
curl_setopt($ch, CURLOPT_NOBODY, 1);
}
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
?>