360云盘分析直链解析

大体思路
1、curl模拟登录分享链接页面,post提取码到指定的链接获取cookie,这个链接可以通过火狐浏览器的开发者模式-网络获得,还可以查看请求头获得post的内容。
2、保存cookie并且再次用curl的方式带cookie模拟访问分享页面继续post指定的链接即可返回一串json数据。
3、从json数据中反编译出下载/播放链接
具体php代码
<?php
/*
 * CURL 带Cookie 获取360云盘直链
 * @ microshe.com
 * 以yunpan.cn/OcL3nwa8qX6s9G (提取码:155e)为演示
 * 获取方式 ck.php?link=https://yunpan.cn/OcL3nwa8qX6s9G&code=155e
*/
$link = $_GET["link"]; // 链接
$code = $_GET["code"]; // 提取码
$shareCode = basename($link); // 链接后半部分的分享码
$header = get_headers( $link , 1 ); // 头部信息
$info = $header['Location']; // 301跳转后的动态地址
$nakeurl = strstr ( $info ,  'lk' ,true); // 截断lk后的部分
$posturl = $nakeurl.'share/verifyPassword'; // POST对象地址 - 这是提取码错误时的POST地址,可以用debug模式获取

$postPw = "shorturl=".$shareCode."&linkpassword=".$code;   // POST数据 - 编辑POST对象可获取
$cookie_file = dirname(__FILE__)."/cookie.txt"; // cookie保存地址

//$ua = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:32.0) Gecko/20100101 Firefox/32.0"; // 模拟浏览器

$ua = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us)";

$ch = curl_init($posturl); //初始化
curl_setopt($ch, CURLOPT_URL, $posturl);// 模拟打开POST对象链接
curl_setopt($ch, CURLOPT_USERAGENT, $ua); // 模拟浏览器打开
curl_setopt($ch, CURLOPT_HEADER, 0); // 头部信息
curl_setopt($ch, CURLOPT_REFERER, $posturl); // Referer 地址,缺少这个就无法生成cookie
curl_setopt($ch, CURLOPT_POST, 1); // 开启POST方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $postPw); // POST数据
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); // 生成 cookie 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec ($ch); 
curl_close ($ch);



// 使用cookie访问分享地址 - 获取nid
$ch = curl_init($info); // 这是分享跳转后的动态地址
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$html = curl_exec($ch);
curl_close($ch);
preg_match("|nid : '(.*)'|U",$html, $nid); // 正在匹配出源码内的nid参数放入$nid数组


// 再度使用cookie去POST下载链接 - Share/getAudioUrl/
$postNid = "nid=".$nid[1]."&shorturl=".$shareCode;   // POST数据 - 编辑POST对象可获取
$audioUrl = $nakeurl.'Share/getAudioUrl'; // 媒体播放链接

$ch = curl_init($audioUrl); //初始化
curl_setopt($ch, CURLOPT_URL, $audioUrl);// 模拟打开POST对象链接
curl_setopt($ch, CURLOPT_USERAGENT, $ua); // 模拟浏览器打开
curl_setopt($ch, CURLOPT_HEADER, 0); // 头部信息
curl_setopt($ch, CURLOPT_REFERER, $audioUrl); // Referer 地址,缺少这个就无法生成cookie
curl_setopt($ch, CURLOPT_POST, 1); // 开启POST方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $postNid); // POST数据
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$jsonResult = curl_exec ($ch); // 返回json数据
$jsonResult = json_decode($jsonResult,true); // 反编译
curl_close ($ch);
// unlink($cookie_file);  // 清除cookie  
header("Location: ".$jsonResult['data']['audio_url']); 

?>

赞(0)