此版本已失效
百度网盘外链获取工具上线之后,一直有人要源码,但是由于我的源码是和其他网站代码混在一起的,所以要发布需要专门整理出来。今天闲着,就放出来吧。
前端修改自退避九舍的网盘工具,在此表示感谢。
你可以随意使用这份源码,但请在首页保留作者链接
使用方法:
1.将下面的代码保存为Index.php放入根目录(亦可在文末直接下载)。如果需要放入子目录,需要按提示修改。
<?PHP /** 百度网盘外链获取工具 Version:1.0 Author:Gimhoy url:https://blog.gimhoy.com/archives/baidu-pan-external-link-source-code.html */ $uri = $_SERVER["REQUEST_URI"]; // $uri = str_replace("/Gimhoy/", "", $uri); //若放在子目录,请去掉本行最前面的双杠,并修改中间的Gimhoy为子目录名称 if(empty($uri) || $uri == "/" || $uri == "index.php" ){ require_once'static.php'; exit; } else{ $uri = str_replace("/", "", $uri); $array = explode('.',$uri); $uri = $array[0]; $array = explode('.',base64_decode($uri)); $id = $array[0]; $uk = $array[1]; if(!empty($id)){ $url = 'https://pan.baidu.com/share/link?shareid=' . $id . '&uk='. $uk; $src = Gimhoy_get_file_contents($url); $pattern = '/<a class="btn blue-btn"(.*?)href=(.*?) id="fileDownload">/is'; preg_match_all($pattern, $src, $result); $result = implode("", $result[2]); $url = str_replace(""", "", $result); $url = str_replace("&", "&", $url); header("location:$url"); }else{ header("location:https://pan.gimhoy.com"); } } function Gimhoy_get_file_contents($URL){ $user_agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5"; $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_USERAGENT, $user_agent); curl_setopt($c, CURLOPT_URL, $URL); $contents = curl_exec($c); curl_close($c); if ($contents) {return $contents;} else {return FALSE;} } ?>
2.将下面的代码保存为static.php放入与上述index.php同级目录
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="author" content="Gimhoy" /> <meta name="copyright" content="Gimhoy Studio, Gimhoy.com" /> <title>获取百度网盘外链地址</title> <link rel="shortcut icon" href="https://hicdn.org/frontend/favicon.ico" /> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?607c826f83494c52ea58db88292bb5b0"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <style type="text/css"> body{padding-top:40px;padding-bottom:40px;background-color:#f5f5f5;font-family:"Open Sans","Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",Arial,Verdana,Tahoma,sans-serif;line-height:1.5em;}.form_pan{max-width:650px;padding:19px 29px 29px;margin:0 auto 20px;background-color:#fff;border:1px solid #e5e5e5;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;-webkit-box-shadow:0 1px 2px rgba(0,0,0,.05);-moz-box-shadow:0 1px 2px rgba(0,0,0,.05);box-shadow:0 1px 2px rgba(0,0,0,.05);}.form_pan .form_pan-heading{margin-bottom:10px;text-align:center;}.copyright{text-align:center;}button,input,select,textarea{margin:0;font-size:100%;vertical-align:middle}button,input{*overflow:visible;line-height:28px;}button::-moz-focus-inner,input::-moz-focus-inner{padding:0;border:0}button,input[type="button"],input[type="reset"],input[type="submit"]{cursor:pointer;-webkit-appearance:button}textarea{overflow:auto;vertical-align:top}textarea,input[type="text"],input[type="url"],.uneditable-input{background-color:#fff;border:1px solid #ccc;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border linear .2s,box-shadow linear .2s;-moz-transition:border linear .2s,box-shadow linear .2s;-ms-transition:border linear .2s,box-shadow linear .2s;-o-transition:border linear .2s,box-shadow linear .2s;transition:border linear .2s,box-shadow linear .2s}textarea:focus,input[type="text"]:focus,input[type="url"]:focus,.uneditable-input:focus{border-color:rgba(82,168,236,0.8);outline:0;outline:thin dotted \9;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6)}.btn{display:inline-block;*display:inline;margin-bottom:0;*margin-left:.3em;width:100px;*line-height:20px;color:#333;text-align:center;text-shadow:0 1px 1px rgba(255,255,255,0.75);vertical-align:middle;cursor:pointer;background-color:#f5f5f5;*background-color:#e6e6e6;background-image:-ms-linear-gradient(top,#fff,#e6e6e6);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6));background-image:-webkit-linear-gradient(top,#fff,#e6e6e6);background-image:-o-linear-gradient(top,#fff,#e6e6e6);background-image:linear-gradient(top,#fff,#e6e6e6);background-image:-moz-linear-gradient(top,#fff,#e6e6e6);background-repeat:repeat-x;border:1px solid #ccc;*border:0;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);border-color:#e6e6e6 #e6e6e6 #bfbfbf;border-bottom-color:#b3b3b3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;filter:progid:dximagetransform.microsoft.gradient(startColorstr='#ffffff',endColorstr='#e6e6e6',GradientType=0);filter:progid:dximagetransform.microsoft.gradient(enabled=false);*zoom:1;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05)}.btn:hover,.btn:active,.btn.active,.btn.disabled,.btn[disabled]{background-color:#e6e6e6;*background-color:#d9d9d9}.btn:active,.btn.active{background-color:#ccc \9}.btn:first-child{*margin-left:0}.btn:hover{color:#333;text-decoration:none;background-color:#e6e6e6;*background-color:#d9d9d9;background-position:0 -15px;-webkit-transition:background-position .1s linear;-moz-transition:background-position .1s linear;-ms-transition:background-position .1s linear;-o-transition:background-position .1s linear;transition:background-position .1s linear}.btn:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.btn.active,.btn:active{background-color:#e6e6e6;background-color:#d9d9d9 \9;background-image:none;outline:0;-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);box-shadow:inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05)}.btn.disabled,.btn[disabled]{cursor:default;background-color:#e6e6e6;background-image:none;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none} </style> <script type="text/javascript"> function getNewLink(){var inputUrl=document.getElementById("inputUrl");var file_value="";var file_type=document.getElementsByName("file_type");var hostname="https://"+window.location.hostname+"/";for(var i=0;i<file_type.length;i++){if(file_type[i].checked){file_value=file_type[i].value;break}};var file_other=document.getElementById("file_other");file_other_text=document.getElementById("file_other_text");var outputUrl=document.getElementById("outputUrl");var abc=inputUrl.value.substring(inputUrl.value.indexOf('=')+1).replace('&uk=','.');var reg=/^\d+.\d+$/;if(!reg.test(abc)){alert("链接错误!");inputUrl.focus();return false};var b=new Base64();var abc=b.encode(abc);if(file_value=='other'){if(file_other_text.value.length==0){alert("扩展名不能为空!");inputUrl.focus();return false};outputUrl.value=hostname+abc+"."+file_other_text.value}else{outputUrl.value=hostname+abc+"."+file_value}};function fileOtherTextChange(){if(file_other.checked==true){file_other_text.disabled=false;file_other_text.focus()}else{file_other_text.disabled=true}};function Base64(){_keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";this.encode=function(input){var output="";var chr1,chr2,chr3,enc1,enc2,enc3,enc4;var i=0;input=_utf8_encode(input);while(i<input.length){chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=((chr1&3)<<4)|(chr2>>4);enc3=((chr2&15)<<2)|(chr3>>6);enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64}else if(isNaN(chr3)){enc4=64};output=output+_keyStr.charAt(enc1)+_keyStr.charAt(enc2)+_keyStr.charAt(enc3)+_keyStr.charAt(enc4)};return output};_utf8_encode=function(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c)}else if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128)}else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128)}};return utftext}} </script> </head> <body> <div class='container'> <form class="form_pan" id="pan_form"> <h2 class="form_pan-heading">百度网盘文件永久外链</h2> <p> 请输入百度网盘分享链接: <input type="text" class="input-medium search-query" style="width:550px;" id="inputUrl" value="" onmouseover="this.select()" onkeydown='if(event.keyCode==13){getLinkBtn.click()}' /> </p> <p> (例如:<a target="_blank" style="text-decoration:none" href="https://pan.baidu.com/share/link?shareid=2657388071&uk=537315566">https://pan.baidu.com/share/link?shareid=2657388071&uk=537315566</a>) </p> <p> 文件的扩展名: <input type="radio" class="radio" name="file_type" id="file_mp3" value="mp3" onchange="fileOtherTextChange()" checked /> mp3 <input type="radio" class="radio" name="file_type" id="file_png" value="png" onchange="fileOtherTextChange()" /> png <input type="radio" class="radio" name="file_type" id="file_exe" value="exe" onchange="fileOtherTextChange()" /> exe <input type="radio" class="radio" name="file_type" id="file_zip" value="zip" onchange="fileOtherTextChange()" /> zip <input type="radio" class="radio" name="file_type" id="file_mp4" value="mp4" onchange="fileOtherTextChange()" /> mp4 <input type="radio" class="radio" name="file_type" id="file_other" value="other" onchange="fileOtherTextChange()" /> 其他格式 <input type="text" class="input-medium search-query" style="width:80px;" id="file_other_text" disabled /> </p> <p> <input type="button" class="btn" id="getLinkBtn" value="获取" onclick="getNewLink()" /> <input type="reset" class="btn" value="清空" onclick="this.form.reset();" /> </p> <p> <b>永久链接为</b>(可直接下载): <input type="text" class="input-medium search-query" style="width:550px;" id="outputUrl" value="" onmouseover="this.select()" /> </p> <p> mp3试听: <embed src="https://hicdn.org/archives/dewplayer.swf?mp3=https://pan.gimhoy.com/MjY1NzM4ODA3MS41MzczMTU1NjY=.mp3&autostart=0&autoreplay=1&volume=90" type="application/x-shockwave-flash" width="180" height="20" quality="high" /> </p> <p> 图片外链:<br/> <center><img src="https://pan.gimhoy.com/MjkyNDQ1MTg1Mi41MzczMTU1NjY=.jpg" ></center> </p> <p class="copyright"> © 2007-<?php echo date('Y'); ?> <a href="https://gimhoy.com" >Gimhoy Studio</a> | Code by <a href="https://blog.gimhoy.com" >Gimhoy</a> | 前端感谢<a href="https://acgfan.duapp.com" >退避九舍</a> </p> </form> </div> </body> </html>
源码打包下载:https://download.gimhoy.com/source/baidupan
若需要v2.0的源码请先赞助本博,谢谢支持。
这个代码的原理是每次请求都现抓一次下载链接是吧?
现抓还有效吗?
无效了
老大 2.0源码给我一份好吗 谢谢啊 这个博客怎么赞助啊
还可以用么?
很是不错的哟。。哈哈~
你好,无法下载,赞助是怎么赞助的呢
百度规则这一段变动比较快,还是用网盘api靠谱些,而且现在获取的链接限速了!