|
发表于 2020-5-22 11:54:54
|
显示全部楼层
安徽省合肥市
看了下你的代码有很多BUG,运行根本无法获取无水印链接,这里给修复优化版:做成API接口就是输出json数据:
- <?php
- ini_set("display_errors", "Off");
- error_reporting(E_ALL^E_NOTICE^E_WARNING);
- header("content-type:application/json");
- $url = $_GET['url'];
- if (preg_match('/https:\/\/.*\/\w+/', $url, $url)) {
- $url = $url[0];
- $Referer = $url;
- $header_arr = get_headers($url,1);
- $UserAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_4_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Mobile/15E148 Safari/604.1';
- $header = array(
- "Cookie:".$header_arr["Set-Cookie"][0],
- "Referer:".$Referer
- );
- $url = $header_arr["Location"][0];
- $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_HTTPHEADER, $header);
- curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
- $data = curl_exec($curl);
- curl_close($curl);
- preg_match('/https:\/\/txmov2\.a\.yximgs\.com\/.*\.mp4/U', $data, $mat);
- if ($mat[0]) {
- exit(json_encode(['code' => 'ok','play' => $mat[0]]));
- } else {
- exit(json_encode(['code' => 'error']));
- }
- } else {
- exit(json_encode(['code' => 'error','msg' => '快手分享链接有误,url参数不正确']));
- }
复制代码
|
|