php360网盘地址解析

$url='http://yunpan.cn/QXrZEiy92C9V5';
function get_downloadurl($url){
    $headers = get_headers($url,1);
    $zhenurl=$headers['Location'];  //Location  L大写
    $yuanma=file_get_contents($zhenurl);
    preg_match("/(?:nids:s')([sS]*)(?:',[s]*fhash)/i",$yuanma,$nid_arr);//*获取nid
    $surl_arr=explode('/',$zhenurl);
    //preg_match("/(?:/lk/)(.*)/i",$zhenurl,$surl_arr);  //print_r($surl_arr);
    $host=$surl_arr[2];
    $surl=$surl_arr[4];
    $nid=$nid_arr[1];
    $data='shorturl='.$surl.'&nid='.$nid;                        //shorturl=QXrZEiy92C9V5&nid=13771433123969454
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://'.$host.'/share/downloadfile/');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $json = curl_exec($ch);     //返回的是 json
    curl_close($ch);
    $back=json_decode($json, true);   
    $downloadurl=$back['data']['downloadurl'];
    return $downloadurl;
}
echo get_downloadurl($url);