没学过PHP,简单手打拼写的,但能够实现解析功能,这个是比较稳定的接口和方式,欢迎懂PHP的精简和指正
- <?php
- if(empty($_GET['url'])){
- $_GET['url']="http://v.douyin.com/UvnoCP/";
- };
- $url = @$_GET['url'];
- $UserAgent = 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1';
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_HEADER, 0);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_ENCODING, '');
- curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
- $html = curl_exec($curl);
- function getSubstr($str, $leftStr, $rightStr) {
- $left = strpos($str, $leftStr);
- $right = strpos($str, $rightStr, $left);
- if ($left < 0 or $right < $left) return '';
- return substr($str, $left + strlen($leftStr) , $right - $left - strlen($leftStr));
- }
- $Dytk = getSubstr($html, 'dytk: "', '" }');
- $ItemId = getSubstr($html, 'itemId: "', '",');
- $url = 'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids='.$ItemId.'&dytk='.$Dytk;
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_HEADER, 0);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_ENCODING, '');
- curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
- $a = curl_exec($curl);
- $Array = json_decode($a,true);
- $mp4 = $Array["item_list"][0]["video"]["play_addr_lowbr"]["url_list"][0];
- ?>
复制代码
|