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/