抖音提取封面php,抖音解析php API现在能解析出图片视频不行了

[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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值