百度网盘直链原理解析
前言:
感觉网上没几个讲明如何获取百度直链的原理,就自己试试获取直链
本身是为学习而已,而一般网上高速链接是使用会员账号获取,所以就不要妄想某某了,当然也可以当做参考
过程其实很简单,首先,我们通过安装正常下载步奏获取到2个关键API
API1. https://pan.baidu.com/share/tplconfig
API2. https://pan.baidu.com/api/sharedownload
API1需要参数:
- surl:xxx
- fields:sign,timestamp
- app_id:xxx
- bdstoken:xxx
在分享页面源码中搜索window.yunData,可以得到上方3个未知参数
后2个参数分别在yunData和mset中,通过筛选补齐:
tplconfigData.put("surl", url.substring(url.lastIndexOf("/") + 1, url.indexOf("?")));tplconfigData.put("fields", "sign");tplconfigData.put("app_id", msetInfo.getJSONArray("file_list").getJSONObject(0).getString("app_id"));tplconfigData.put("bdstoken", yunDataInfo.getString("bdstoken"));
API2的参数就比较多了:
- encrypt:0
- product:share
- sign:xxx;
- timestamp:xxx;
- app_id:xxx;
- bdstoken:xxx;
- uk:xxx;
- primaryid:xxx;
- fid_list:xxx;
- extra:{"sekey":"xxx"}; #JSON格式实际上是COOKIE里的BDCLND参数
API2的未知参数分别在API1的返回值和源码的mset里:
shareData.put("encrypt", "0");
shareData.put("product", "share");
shareData.put("sign", tplconfigInfo.getString("sign"));
shareData.put("timestamp", tplconfigInfo.getString("timestamp"));
shareData.put("app_id", tplconfigData.get("app_id"));
shareData.put("bdstoken", tplconfigData.get("bdstoken"));
shareData.put("uk", msetInfo.getString("share_uk"));
shareData.put("primaryid", msetInfo.getString("shareid"));
shareData.put("fid_list", "[" + msetInfo.getJSONArray("file_list").getJSONObject(0).getString("fs_id") + "]");
shareData.put("extra", new JSONObject().fluentPut("sekey", sekey).toJSONString());
最后拿着API2的请求参数请求API2即可,源码:
基于 hnuuhc/often-utils: Java网络常用工具类 (github.com) 编写
import java.util.HashMap;
import java.util.Map;import org.haic.often.chrome.browser.LocalCookie;
import org.haic.often.net.URIUtil;
import org.haic.often.net.http.HttpsUtil;
import org.haic.often.net.http.Response;
import org.haic.often.util.StringUtil;import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONReader;/*** 百度网盘直链*/
public class App_Baidu {public static void main(String[] args) {String url = "https://pan.baidu.com/s/xxxxxxxx?pwd=1234";String tplconfigUrl = "https://pan.baidu.com/share/tplconfig";String sharedownloadUrl = "https://pan.baidu.com/api/sharedownload";Map<String, String> cookies = LocalCookie.home().getForDomain("baidu.com"); // 获取本地浏览器cookiesString sekey = URIUtil.decode(cookies.get("BDCLND"));JSON.config(JSONReader.Feature.AllowUnQuotedFieldNames);String info = HttpsUtil.connect(url).cookies(cookies).execute().body();info = info.substring(info.indexOf("window.yunData"));info = info.substring(0, info.indexOf("window.BadSDK"));String yunData = StringUtil.extract(info, "window.yunData.*");yunData = yunData.substring(yunData.indexOf("=") + 1, yunData.length() - 1);JSONObject yunDataInfo = JSONObject.parseObject(yunData);String mset = StringUtil.extract(info, "locals.mset.*");JSONObject msetInfo = JSONObject.parseObject(mset.substring(mset.indexOf("(") + 1, mset.lastIndexOf(")")));Map<String, String> tplconfigData = new HashMap<String, String>();tplconfigData.put("surl", url.substring(url.lastIndexOf("/") + 1, url.indexOf("?")));tplconfigData.put("fields", "sign,timestamp");//tplconfigData.put("app_id", msetInfo.getJSONArray("file_list").getJSONObject(0).getString("app_id"));tplconfigData.put("bdstoken", yunDataInfo.getString("bdstoken"));String tplconfig = HttpsUtil.connect(tplconfigUrl).data(tplconfigData).cookies(cookies).execute().body();JSONObject tplconfigInfo = JSONObject.parseObject(tplconfig).getJSONObject("data");Map<String, String> shareData = new HashMap<>();shareData.put("encrypt", "0");shareData.put("product", "share");shareData.put("sign", tplconfigInfo.getString("sign"));shareData.put("timestamp", tplconfigInfo.getString("timestamp"));shareData.put("app_id", tplconfigData.get("app_id"));shareData.put("bdstoken", tplconfigData.get("bdstoken"));shareData.put("uk", msetInfo.getString("share_uk"));shareData.put("primaryid", msetInfo.getString("shareid"));shareData.put("fid_list", "[" + msetInfo.getJSONArray("file_list").getJSONObject(0).getString("fs_id") + "]");shareData.put("extra", new JSONObject().fluentPut("sekey", sekey).toJSONString());Response share = HttpsUtil.connect(sharedownloadUrl).data(shareData).userAgent("netdisk").execute();JSONObject body = JSONObject.parseObject(share.body());int errno = body.getInteger("errno");if (errno == 0) {String link = JSONArray.parseArray(body.getString("list")).getJSONObject(0).getString("dlink");System.out.println(link);} else if (errno == -20) {System.out.println("获取直链失败,需要验证码");} else {System.out.println("未知错误 - errno: " + body);}}}
百度网盘直链原理解析相关推荐
- 百度网盘——下载限速问题解决方案(油猴(Tampermonkey)+百度网盘直链下载助手+IDM)
一.基本概念 Tampermonkey(油猴):Tampermonkey插件是一个免费的浏览器扩展和最为流行的用户脚本管理器,拥有适用于 Chrome, Microsoft Edge, Safari, ...
- 百度网盘直链下载助手(MacOSChrome)
简介 众所周知,通过百度网盘(未开通会员)直接下载文件的速度极慢,通过安装浏览器插件可以极大的提高下载速度. 安装文件 Tampermonkey NeatDownloadManager Extensi ...
- 百度网盘直链下载助手 油猴脚本
百度网盘直链下载助手 https://www.youhou8.com/scripts/max/%E7%99%BE%E5%BA%A6%E7%BD%91%E7%9B%98%E7%9B%B4%E9%93%B ...
- 直链站php源码,源码库分享PHP版百度网盘直链/外链源码
时间:2013-10-22来源:Aspku 作者:源码库 文章热度: ℃ PHP版百度网盘直链/外链源码分享,使用方法: 一.复制下面的php代码,另存为文件baidupan.php,然后将php文件 ...
- ubuntu服务器下载文件|aria2|百度网盘直链下载崩溃
最常用的还是ssh传输文件 查看ubuntu服务器当前路径可以在terminal命令行使用 pwd (base) yanxudembp:~ yanxu$ pwd /Users/yanxu 如果是mac ...
- 百度网盘直链下载教程
地址:https://www.baiduyun.wiki/zh-cn/ 我用的是Windows平台的"360极速浏览器",其他平台的其他浏览器请自测.
- 生成直链——百度网盘、微云
微云直链解析 https://pan.abn.cc/ 经测试,可任意选择扩展名. 百度网盘直链分享平台 http://wp.cccyun.cc/ http://fq.wc.lt(该站点云服务器已到期) ...
- 百度网盘Motrix直链下载js脚本
介绍: 百度网盘Motrix直链下载js脚本是一款非常好用的百度网盘直链下载工具,搭配Motrix下载软件使用,能够帮助用户去掉网盘限速限制,让你能够满速下载你需要的文件,有需要的用户不要错过了,赶快 ...
- 2022年11月最新百度网盘扩容技术,扩容技术原理分析拆解
百度网盘是我们大家喜闻乐见的一个存储网盘,相信有很多人都在用着这个软件,平时我们有一些电影什么的还有其他资源都喜欢往里面存,但是百度网盘的实际容量是有限的,我们有更多的东西要存,网盘官方扩容价格有很高 ...
- IDM——服务器响应显示您没有权限下载此文件(百度网盘下载问题)
分析 测试发现是受cookie的影响,百度为了防止用外部下载工具突破限速加入了cookie验证,因为一般的下载工具请求下载的时候不会附加cookie信息. IDM就是这样,它请求下载文件时只知道文件的 ...
最新文章
- ecshop入门第一步,替换ecshop模板的显示图片
- No module named 'xxx’
- abap git - commnication failure错误消息的分析和定位
- hdu java_HDU Java8 集锦
- SparseArray代替HashMap
- openCV之图像基础(笔记02)
- c 命令行简易计算器
- 导航菜单点击后高亮显示
- linux 用户操作相关命令
- 如何下载股票历史数据?
- Python语言翻译包translate,支持翻译多语种
- c语言第七章函数实验总结,C语言学习与总结---第七章:函数 [01]
- CPU、GPU、TPU、NPU等到底是什么?
- Openfire 即时通讯系统(服务器端+Android客户端)一
- 解除百度网盘下载限制的办法
- PS_一寸照片换背景底色
- 这个时代,“寒门再难处贵子”【转载】
- ArcGIS栅格数据四参数七参数投影变换
- 踩坑记录丨记Jekyll + Github Pages搭建个人博客时遇到的各种问题
- 955 互联网公司白名单来了!这些公司月薪20k,没有996!福利榜国内大厂只有这家!