微云网盘php解析源码_更新

作者:matrix 发布时间:2014 年 1 月 6 日 分类:零零星星

应小伙伴的留言放出源码,并考虑多文件的情况。

这代码弄了好几天才搞出来的,100多行不容易。 🙄

本人菜鸟,代码上有问题的地方欢迎指正 互相学习!! 爱好php~

版本说明:

大于100MB,有提取密码的文件外链会失败。

放到BAE上不知道啥原因 总是403  503 错误,不过我在本地测试是成功的。其他未知
解决:

bae 403错误,正如Lostape所说,正则匹配的问题。
preg_match('|\.php\??\/(.*)\.\w+|',$_SERVER["REQUEST_URI"],$ur);
大部分的bae 503错误,应该是有太长的& or ?& 导致的。具体不详
更多BUG中~

使用说明:

微云:http://share.weiyun.com/eec279cd08578598b84e92403b3d5e99

普通下载:http://localHOST/weiyun.php/eec279cd08578598b84e92403b3d5e99.flv

BAE调用下载:http://ฏ๎๎๎๎๎๎๎๎๎ฏ ้้้ฏด้้้้้็็็็็้้้้้็็.duapp.com/t.php?/eec279cd08578598b84e92403b3d5e99.flv(尝试兼容bae)

http://ฏ๎๎๎๎๎๎๎๎๎ฏ ้้้ฏด้้้้้็็็็็้้้้้็็.duapp.com/t.php?u=eec279cd08578598b84e92403b3d5e99(再度尝试兼容bae)

技术问题,BAE上常出现503错误。不保证绝对可用,欢迎测试!!

 源码(已失效):

http://pan.baidu.com/s/1c05TCK4 #密码: kh0e(再度尝试兼容bae)
http://pan.baidu.com/s/1jGt6bSa #密码: t5t1 (尝试兼容bae)
http://pan.baidu.com/s/1EeYiq%20 #密码:32my

再来mp3测试: 阅读剩余部分 »

PHP获取URL跳转后的最终地址

作者:matrix 发布时间:2013 年 12 月 31 日 分类:零零星星

仅是获得响应头Location的最终地址

$url='http://189.io/G3qrdn';
echo get_jump_url($url);
function get_jump_url($url) {
    $url = str_replace(' ','',$url);
    do {//do.while循环:先执行一次,判断后再是否循环
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_HEADER, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        $header = curl_exec($curl);
        curl_close($curl);
        preg_match('|Location:\s(.*?)\s|',$header,$tdl);
        if(strpos($header,"Location:")){
            $url=$tdl ? $tdl[1] :  null ;
        }
        else{
            return $url.'';
            break;
        }
    }while(true);
}

参考:http://bbs.csdn.net/topics/390349430
附curl常量:

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);//允许链接自动跳转
curl_setopt($curl, CURLOPT_MAXREDIRS, 3);//限定CURLOPT_FOLLOWLOCATION递归返回的数量
CURLOPT_AUTOREFERER :curl 会自动添加 Referer header 在每一个跳转链接,也就是一跟到底。

这样也就避免上面代码的do while循环。

建议使用get_headers()函数解决

参考:http://upc.gg.blog.163.com/blog/static/297984982013123970455/

更新百度网盘外链方法_无数据库缓存_仅供测试

作者:matrix 发布时间:2013 年 12 月 4 日 分类:兼容并蓄 零零星星

测试地址:

http://link.hhtjim.com

采用最新的本人无数据库缓存10min,绝对不靠谱,仅供测试!

警告:以下内容属于充字数类型且杂乱无章,需要外链功能的请戳上面的地址~

上个月,百度网添加了验证码功能导致以前抓取外链的方法都失效。度娘终于爆发了~

刚开始还没注意到验证码的存在,只要一连几次下载文件就会出现验证码窗口

验证码窗口

经过N次的文件下载,看到了度娘的脾气。

也就只允许你前3次下载免验证码,后面你要下载的话那就只有手动输入了。

抓到某个下载地址:

http://small.cdn.baidupcs.com/file/2c808f328bec8fa44d5ac5e2e42985d2?xcode=e0ad680ebd95ea801d4878451d04d36328f07d27337bcbfd0b2977702d3e6764
&fid=1178024267-250528-2238604782
&time=1386087754
&sign=FDTAXER-DCb740ccc5511e5e8fedcff06b081203-w%2FMs%2B2m13ixmrRpD2s11F01H6b4%3D
&to=sc
&fm=Q,B,U,nc
&expires=1386088354
&rt=sh
&r=860261331
&logid=2869754983&sh=1&vuk=3238236832
&fn=文件名

上面的fid、time、sign还能从页面处找到,有些参数根本就看不到。

time和expires参数都是unix时间戳,后者的意思是过期时间。时间相差600秒,也就10分钟。

在这10分钟之内这个地址都是有效的, 😉  那就有点头绪了。

抓取页面的必备参数,获取下载地址,再用session会话缓存那个下载地址,10分钟内有效或者再自动检测。

最爽的是第一次弄免数据库缓存,庆幸书上有session会话的相关章节  哈哈。

再手动下载几次就抓到了获取下载地址的URL:

http://pan.baidu.com/share/download?bdstoken=null&uk=&shareid=&fid_list=[]&sign=&timestamp=

看到那几个参数,笑了~

之后就是好几天的编写、测试下载,期间有看书整了个最基本的类 。 额  面向对象 。

源码就暂时为空。

提醒的是度娘这回要检测referer,跟360云盘一样的只能外链下载无法外链播放。自己试试就晓得~

所以我把link.hhtjim.com页面的那个下载按钮去掉了 ,TMD浏览器发送当前URl的referer是没法改的。无语啊~

先放个测试期间最早版本的cookies缓存源码:

<?php  
error_reporting(0);//禁用错误报告  
  function curl_get($url,$post=false,$carry_header=true,$REFERER_=false,$useragent=false,$add_arry_header=null){  
        $ch=curl_init($url);  

        if($carry_header){  
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent:Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16'));  
        }  
        if($add_arry_header){  
            curl_setopt($ch, CURLOPT_HTTPHEADER, $add_arry_header);  
        }  
        if ($post) {  
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post);  
        }  
        if($REFERER_){  
            curl_setopt($ch, CURLOPT_REFERER,$REFERER_);  
        }  
        if($useragent){  
            curl_setopt($ch, CURLOPT_USERAGENT, $useragent);  
        }  

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
        $get_url = curl_exec($ch);  
        curl_close($ch);  
        return $get_url;  
    }  

preg_match('|u=(.*)|',$_SERVER["REQUEST_URI"],$bai_res);  
$bai_=curl_get($bai_res[1]);  

preg_match('|shareid=\"(\d+)\"\?\"\1\":\"\";FileUtils\.uk=\"(\d+)\"\?\"\2\"|',$bai_, $ui); 
preg_match('|fs_id\D+(\d+)\D+app_id|',$bai_,$fid); 
preg_match('|timestamp=\"(\d+)\"|',$bai_,$time); 
preg_match('|downloadsign=\"(\w+)\"|',$bai_,$login); 
$diz="http://pan.baidu.com/share/download?bdstoken=null&uk=$ui[2]&shareid=$ui[1]&fid_list=[$fid[1]]&sign=$login[1]&timestamp=$time[1]&bdstoken=null&channel=chunlei&clienttype=0&web=1";  
$header[]= 'Cookie: BAIDUID=*****';    //请使用自个儿的百度ID,度娘会检查这个的cookies

if(isset($_COOKIE["du$ui[2]-$ui[1]"])){ 
//header( "Location: $_COOKIE["du$ui[2]-$ui[1]"]"); 
echo $_COOKIE["du$ui[2]-$ui[1]"]; 
}else{ 
$dl=curl_get($diz,null,$header,$bai_res[1],null,$header); 
$obj=json_decode($dl,true); 
if($obj['errno']!='0'){ 
//header( "Location: $bai_res[1]"); 
echo $bai_res[1]; 
} 
setcookie("du$ui[2]-$ui[1]",$obj['dlink'],time()+3600*24); 
//header( "Location: $obj['dlink']");  
echo $obj['dlink'];  
}  
?>  

这个能不能用就靠你怎么使了,仅是原理。

如果你即刻需要外链,请到http://link.hhtjim.com玩玩~

祝你好运!

博客也快一个月都没有更新了,不码点字不好~

php获取xml数据

作者:matrix 发布时间:2013 年 10 月 27 日 分类:零零星星

调用某些api后返回的数据可能会是xml格式,这就需要提取相关数据。

如果了解正则匹配的话可以用preg_match()来提取,最好还是用php内置的专用函数来处理xml

 

代码:

$xml = new DOMDocument(); // 首先要建一个DOMDocument对象    
$xml->load('http://api.189.cn/EMP/shorturl/long2short?access_token=76327c4e405b725021640fd629bfc3511382853781284&app_id=120032470000032374&longurl=hhtjim.COM'); // 加载Xml文件     
$postDom = $xml->getElementsByTagName("shorturl")->item(0)->nodeValue;    
echo $postDom;  

 

说明:

第3行"shorturl"为读取的标签名,运行结果将显示http://189.io/ReRTnn

第2行是读取xml文件:


This XML file does not appear to have any style information associated with it. The document tree is shown below. <result> <res_code>0</res_code> <res_message>短地址生成成功。</res_message> <shorturl>http://189.io/ReRTnn</shorturl> </result>

参考:http://developer.51cto.com/art/200912/166247.htm


貌似这个代码也行

$xml = new DOMDocument();  
$xml->load('http://api.189.cn/EMP/shorturl/long2short?access_token=76327c4e405b725021640fd629bfc3511382853781284&app_id=120032470000032374&longurl=hhtjim.COM'); // 加载Xml文件     
foreach($xml->getElementsByTagName('shorturl') as $shorturl);
$value = $shorturl->firstChild->nodeValue;   
echo $value;  

新浪乐库php解析源码

作者:matrix 发布时间:2013 年 10 月 26 日 分类:零零星星

demo:http://link.hhtjim.com

外链测试:

http://music.sina.com.cn/yueku/i/2850351.html 阅读剩余部分 »

微云网盘外链php源码

作者:matrix 发布时间:2013 年 10 月 26 日 分类:兼容并蓄 零零星星

微云

微云网盘的10TB空间也要全部利用起来。

申明:此页面的源码已失效,走这里查看最新>>微云网盘php解析源码_更新

外链转换工具:http://link.hhtjim.com/

代码来自破博客

<?php  
//提取微云分享地址  
preg_match('|\/.+\/(\w+)|', $_SERVER['REQUEST_URI'], $res);  
$key = $res ? $res[1] : exit("weiyun URL error!");  
$url = $referer = "http://share.weiyun.com/$key";  
$useragent = "BlackBerry/3.6.0";  

//匹配出下载地址  
$curl = curl_init($url);  
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($curl, CURLOPT_USERAGENT, $useragent);  
curl_setopt($curl, CURLOPT_TIMEOUT, 10);  
$src = curl_exec($curl);  
curl_close($curl);  
preg_match('|http://.+sharekey[^"]+|', $src, $res);  
$url = $res ? $res[0] : exit("weiyun URL error! Not find weiyun code!"); 

//伪造referer,获取返回的响应头信息 
$curl = curl_init($url); 
curl_setopt($curl, CURLOPT_HEADER, 1); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curl, CURLOPT_REFERER, $referer);  
curl_setopt($curl, CURLOPT_USERAGENT, $useragent); 
curl_setopt($curl, CURLOPT_TIMEOUT, 10); 
$src = curl_exec($curl); 
curl_close($curl); 

//从响应信息头匹配出真实的文件地址并下载 
preg_match('|Location: (.+)\r|', $src, $res); 
$songurl = $res ? $res[1] : exit("Can not get WeiYun Download url!"); 
header("Location: $songurl");  
//echo $songurl;  
?>  

这种方法该不错滴。

使用示例:http://XXX.php/微云URL

http://share.weiyun.com/b500a423288e8d0095d49657fe21438b 阅读剩余部分 »

360云盘外链解析php源码

作者:matrix 发布时间:2013 年 10 月 19 日 分类:兼容并蓄 零零星星

用火狐的firebug插件看到云盘的下载过程是通过post提交获得json数据(期间会检查REFERER),之后再跳转到下载地址。

查看post提交数据

图片外链演示:

360yunpan图片外链演示

mp3外链失败,但是下载的话没问题(后来才知道是360防盗链的Referer缘故):

源码下载[已失效]:

城通  http://www.400gb.com/file/55758296
baidu http://pan.baidu.com/s/1kTGjyZX
代码[已失效]:

<?php
/** 
 * 2014-1-27更新  
 修改正则匹配
 * Author:不懂就乱来
 * Website:https://www.hhtjim.com
 **/
    error_reporting(0);
    function curl_get($url,$post=0,$carry_header=true,$REFERER_=0,$useragent=0,$add_arry_header=0){
        $ch=curl_init($url);
        //curl_setopt($ch, CURLOPT_HEADER, 1);
        if($carry_header){
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent:Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16'));
        }
        if($add_arry_header){
            curl_setopt($ch, CURLOPT_HTTPHEADER, $add_arry_header);
        }
        if ($post) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        }
        if($REFERER_){
            curl_setopt($ch, CURLOPT_REFERER,$REFERER_);
        }
        if($useragent){
            curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $get_url = curl_exec($ch);
        curl_close($ch);
        return $get_url;
    }
    function curl_get_http($url,$REFERER_,$add_arry_header=0){
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_HEADER, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        if($REFERER_){curl_setopt($curl, CURLOPT_REFERER,$REFERER_);}
        if($add_arry_header){
            curl_setopt($curl, CURLOPT_HTTPHEADER, $add_arry_header);
        }
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        $src = curl_exec($curl);
        curl_close($curl);
        return $src ;
    }
if(isset($_GET['360'])){//360云盘下载
        $_url=$_GET['360'];
        $yunpanhtml=curl_get($_url);
        if(emptyempty($yunpanhtml)){
            $_yunpanur__=curl_get_http($_url);
            preg_match("|http:\/\/\w+\.\w+\.yunpan\.cn\/lk\/\w+|",$_yunpanur__,$yunpanhtml_n);
            $yunpanhtml_new=curl_get($yunpanhtml_n[0]);
            }else{
            $yunpanhtml_new=$yunpanhtml;
            }
        $yunpanzz="|SYS_CONF = {[^}]+surl: '(\w+)'[^}]+nid : '(\d+)'[^}]+}|";
        preg_match($yunpanzz,$yunpanhtml_new,$yunpancs);
        $nid = $yunpancs[2] ? $yunpancs[2] : exit('ERROR code: Not found SYS_CONF {nid}');
        $shorturl = $yunpancs[1] ? $yunpancs[1] : exit('ERROR code: Not found SYS_CONF {shorturl}');
        if(!strpos($_url,"yunpan.cn/lk")){//获取postURL地址
            $postht_get=curl_get_http($_url);
            preg_match('|(http:\/\/\w+\.\w+\.yunpan\.cn)\/lk\/\w+|',$postht_get,$posthttpu);
            $post_url=$posthttpu[1].'/share/downloadfile/';
        }
        else{
            preg_match('|(http:\/\/\w+\.\w+\.yunpan\.cn)\/lk\/\w+|',$_url,$yun_url);
            $post_url=$yun_url[1].'/share/downloadfile/';
        }
        $post_data = array('nid' => $nid, 'shorturl' => $shorturl);
        $useragent = "BlackBerry/3.6.0";
        $rt=curl_get($post_url,$post_data,0,$_url,$useragent,0);
        $obj = json_decode($rt);
        $errmsg=$obj->errmsg;
        if(strpos($errmsg,"成功")){
            $dll=$obj->data->downloadurl;
            $dl_out = $dll ? $dll : exit('Can not get YunPan Download url!Please Check <a href="https://www.hhtjim.com/message-wall">here</a> .') ;
            header("Location: $dl_out");}
        else{
            header("Content-Type: text/html; charset=utf-8");
            echo '360云盘:'.$errmsg.'</br>Please Check <a href="https://www.hhtjim.com/message-wall">here</a> .';
        }
    }
    exit('DIE!');
?>

说明:将以上代码保存为yunpan.php

若放在360目录需要修改22行/yunpan.php为/360/yunpan.php

代码不够精简,只有这样了。

1-27更新正则匹配,可保存为任意php文件名。

调用下载:http://XXX/yunpan.php?360=360云盘地址

支持两种360云盘URL格式

http://yunpan.cn/QXJ786DeBjeiW

http://ajvvqzy2v8.l29.yunpan.cn/lk/QXJ786DeBjeiW

转换地址:http://link.hhtjim.com/

 

整理外链转换工具-陆续加强版

作者:matrix 发布时间:2013 年 10 月 14 日 分类:兼容并蓄 零零星星

图片4802-整理外链转换工具-陆续加强版

地址:http://link.hhtjim.com

说明:

外链转换没有永久的,请酌情使用!!

链接地址可自动识别并相应的简单处理,有的显示文件名以及后缀。

链接地址可不用输入HTTP://,如果没有HTTP://会自动添加在链接开头位置。

将就各种奇葩,自动去掉空格,URL后面的/,有些还有报错提示。

支持的链接格式:

百度网盘:

http://pan.baidu.com/s/13isoZ

http://pan.baidu.com/share/link?shareid=3760603697&uk=3238236832

虾米音乐:

http://www.xiami.com/song/1772222342

http://www.xiami.com/song/33112?spm=a1z1s.3521865.23309997.2.RAsL1F

http://www.xiami.com/song/play?ids=/song/playlist/id/1772222342/object_name/default/object_id/0

程序的死的,如果没有得到那个ID它会开小差,所以建议你手动获取id,其他相同外链同理

转换后的直链地址形如:

http://link.hhtjim.com/xiami/音乐ID.mp3

Songtaste音乐:

http://www.songtaste.com/song/262121

http://songtaste.com/song/262121

一听音乐:

http://www.1ting.com/player/f4/player_944464.html

新浪微盘:

http://vdisk.weibo.com/s/zb_f-vRa57H7-

金山快盘:

http://www.kuaipan.cn/file/id_9732344353166091.htm

360云盘:

http://ajvvqzy2v8.l29.yunpan.cn/lk/QXJ786DeBjeiW

http://yunpan.cn/QXJ786DeBjeiW

......

想着把这个web app放到bae上速度会很快,但bae伪静态跟普通空间的.htaccess文件设置伪静态不同

需要在BAE的根目录新建app.conf文件,添加相应的伪静态规则。

BAE:

handlers:
  - expire : .jpg modify 10 years
  - expire : .swf modify 10 years
  - expire : .png modify 10 years
  - expire : .gif modify 10 years
  - expire : .JPG modify 10 years
  - expire : .ico modify 10 years

  - url : /bdwl/((.*)/(.*)/.*\..* 
    script : /d.php?/$1/$2

  - url : /xiami/(.*)\.mp3
    script : /wailian.php?xiaurl=http://www.xiami.com/song/$1
  - url : /st/(.*)\.mp3
    script : /wailian.php?sturl=http://songtaste.com/song/$1
  - url : /yt/(.*)/(.*)\.wma
    script : /wailian.php?yt=http://www.1ting.com/player/$1/player_$2.html
  - url : /vp/(.*)/.*\..*
    script : /wailian.php?vp=http://vdisk.weibo.com/s/$1
  - url : /jins/(.*)/.*\..*
    script : /wailian.php?jins=http://www.kuaipan.cn/file/id_$1.htm

比较.htaccess文件:

RewriteRule ^bdwl/([0-9]+)/([0-9]+)/([\s\S]+)\.([a-zA-Z0-9]+)?$ /d.php/$1/$2 [L]  
RewriteRule ^xiami/([0-9]+)\.mp3?$ /wailian.php?xiaurl=http://www.xiami.com/song/$1 [L]
RewriteRule ^st/([0-9]+)\.mp3?$ /wailian.php?sturl=http://songtaste.com/song/$1 [L]  
RewriteRule ^yt/(\w+)/([0-9]+)\.wma?$ /wailian.php?yt=http://www.1ting.com/player/$1/player_$2.html [L]  
RewriteRule ^vp/([\w-]+)/([\s\S]+)\.([a-zA-Z0-9]+)?$ /wailian.php?vp=http://vdisk.weibo.com/s/$1 [L]  
RewriteRule ^jins/(\d+)/([\s\S]+)\.([a-zA-Z0-9]+)?$ /wailian.php?jins=http://www.kuaipan.cn/file/id_$1.htm [L]

这个小工具其实早就在国庆期间弄出来了,一直都是出于自用阶段。博客的空间也换了,完全没有以前天翼云vps 的高响应速度,就一直拖着。

这才整理之前的外链转换工具:虾米、songtaste、百度网盘,还添加金山快盘、一听音乐的php外链。此工具代码参考于度娘或者谷歌,部分来自ifoouu.com。感谢分享!