PHP 实现抖音去水印
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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端