标签:ch setopt url 水印 抖音 location curl PHP CURLOPT
废话不多说,直接上代码!!!
1 <?php 2 $url = $_GET['url']; 3 //获取视频url 4 $url = get_redirect_url($url); 5 //获取视频ID 6 $str = dirname($url); 7 $id = substr($str,strripos($str,'video')+6); 8 //调用抖音官方API 9 $str = file_get_contents('https://www.douyin.com/web/api/v2/aweme/iteminfo/?item_ids='.$id); 10 //将返回的json数据转为数组 11 $data = json_decode($str,true); 12 //获取有水印的视频地址 13 $url = $data['item_list'][0]['video']['play_addr']['url_list'][0]; 14 //将playvm替换为play,从而获取无水印的视频地址 15 $url = str_replace('playwm','play',$url); 16 //获取重定向后的真实地址 17 $video_url = get_redirect_url($url); 18 echo "<a href='$video_url' target='_blank'>$video_url</a>"; 19 20 function get_redirect_url($url) { 21 $ch = curl_init(); 22 curl_setopt($ch, CURLOPT_URL, $url); 23 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 24 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 25 curl_setopt($ch, CURLOPT_HTTPHEADER, array( 26 'Accept: */*', 27 'Accept-Encoding: gzip', 28 'Connection: Keep-Alive', 29 'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)' 30 )); 31 curl_setopt($ch, CURLOPT_HEADER, true); 32 curl_setopt($ch, CURLOPT_NOBODY, 1); 33 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 34 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 35 $ret = curl_exec($ch); 36 curl_close($ch); 37 preg_match("/Location: (.*?)\r\n/iU",$ret,$location); 38 return $location[1]; 39 }
原理可参考:https://baijiahao.baidu.com/s?id=1710928885019968429&wfr=spider&for=pc
函数可参考:https://blog.csdn.net/weixin_29924799/article/details/116287105
标签:ch,setopt,url,水印,抖音,location,curl,PHP,CURLOPT 来源: https://www.cnblogs.com/leonliuo/p/16304060.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。