获取新浪微盘文件分享直接下载地址

xlm
@Ta 2016-02-25发布,2016-03-04修改 2321点击
可以直接获取到新浪微盘分享的下载下载地址,私人分享、公开分享都可以获取到。
也不知道能用多久。
代码没多少,就直接贴出来了:
Nodejs版本:
var http = require("http");
var url = require("url");

function parseDownloadLink(htmlString){
  var matches = htmlString.match(/(?:fileDown|linkShareDown)\.init\((\{[^\{\}]+\})\)/);
  if(matches){ return JSON.parse(matches[1]).url; }
  return null;
}

function vdiskParser(req, res){
  var queries = url.parse(req.url, true).query;
  var postData;
  if(queries.l && queries.s){
    var option = url.parse("http://vdisk.weibo.com/" + queries.l + "/" + queries.s);
    option.method = "GET";
    option.headers = {
      "Connection": "Keep-Alive",
      "Accept-Encoding": "deflate",
      "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0"
    };
    if(queries.a){
      postData = new Buffer("file=" + queries.s + "&access_code=" + queries.a);
      option.method = "POST";
      option.headers["Content-Length"] = postData.length;
      option.headers["Content-Type"] = "application/x-www-form-urlencoded";
    }
  }else{
    res.writeHead(400);
    res.end();
    return;
  }

  var vdiskHtmlRequest = http.request(option, function(serverResponse){
    var serverDataBuffer = [];
    serverResponse.on("data", function(chunk){ serverDataBuffer.push(chunk); })
    .on("end", function(){
      var downloadUrl = parseDownloadLink(Buffer.concat(serverDataBuffer).toString("utf8"));
      if(downloadUrl){ res.writeHead(302, {"Location": "https://slurin.github.io/toUrl.html?" + encodeURIComponent(downloadUrl)}); }else{ res.writeHead(404); }
      res.end();
    }).on("error", function(error){ res.writeHead(506); res.write("Server request error"); res.end(); });
  });

  vdiskHtmlRequest.setTimeout(8000, function(){
    vdiskHtmlRequest.abort();
    res.writeHead(506);
    res.write("Request to server timeout.");
    res.end();
  });

  vdiskHtmlRequest.on("error", function(error){ res.end(); });
  if(queries.a){ vdiskHtmlRequest.write(postData); }
  vdiskHtmlRequest.end();
}


http.createServer(vdiskParser).listen(8081, "127.0.0.1");

PHP版本:
<?php
header('Content-Type: text/plain; charset=utf8');
if(isset($_GET['l']) and isset($_GET['s'])){
  $ch = curl_init();
  $headers = array(
      "Connection: Keep-Alive",
      "Accept-Encoding: deflate",
      "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0"
    );
  if(isset($_GET['a'])){
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'file=' . $_GET['s'] . '&access_code=' . $_GET['a']);
  }
  curl_setopt($ch, CURLOPT_HEADER, FALSE);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_URL, 'http://vdisk.weibo.com/' . $_GET['l'] . '/' . $_GET['s']);
  $pageData = curl_exec($ch);
  curl_close($ch);
  if(preg_match('/(?:fileDown|linkShareDown)\.init\((\{[^\{\}]+\})\)/', $pageData, $match)){
    $infojson = json_decode($match[1], TRUE);
    if(isset($infojson['download_list'][1])){
      //为了解决Referer问题,采用了二次跳转的方法。
      header('Location: https://slurin.github.io/toUrl.html?' . urlencode($infojson['download_list'][1]));
    }else{
      echo 'Download link not found.';
    }
  }else{ echo 'Request error or file not found.'; }
}else{ echo 'Bad request.'; }

测试:
公开分享: http://cid.feb.date/v.php?l=s&s=tl4IN00FD1EdS
私密分享: http://cid.feb.date/v.php?l=lc&s=3ViwUVk3CDDFw2RjWbn&a=GIU3
回复列表(2|隐藏机器人聊天)
添加新回复
回复需要登录