抓包天翼云盘链接,实现免登录下载

作者: JONE 分类: PHPer 发布时间: 2020-12-05 16:17

天翼云盘下载文件不限速,但是要想下载文件必须先登录。假如我不想注册登录就能下载天翼云盘的文件岂不快哉。

分析天翼云盘的网页发现天翼云盘的下载链接获取并不需要登录,即不需要传入相应的cookie参数,只需要获取 verifyCode  shareId 这两个参数再配合网盘文件分享链接和提取码这4个参数,然后找到对应的接口即可。

废话不多说,直接上代码(本示例使用的是laravel框架)

<?php

namespace App\Http\Controllers\Tools;

use GuzzleHttp\Client;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;


class TianYiController extends Controller
{
    public function index(Request $request)
    {
        $url = $request->get('url');
        $access_code = $request->get('code');

        
        $res =  $this->requestTianYi($url,$access_code);
        
        dd($res);
        
    }

    /**
     * 模拟http请求获取抓包数据
     * @param $url string 天翼云盘分享链接
     * @param $access_code string 天翼云盘提取码
     * @param $pageNum  int 获取数据页码
     * @param $pageSize int 获取数据每页内容数量
     * @return array 返回值有数据时返回数组 否则返回空字符串
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    private function requestTianYi($url,$access_code='',$pageNum=1,$pageSize=60)
    {
        if(!preg_match('/^http[s]?\:\/\/cloud.189.cn\/t\/[\w]{3,}/',$url)) return [];

        $client = new Client();

        $r1 = $client->request('GET', $url, [
            'allow_redirects' => false,
            'headers' => [
                'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
            ]
        ]);

        $body =$r1->getBody()->getContents();

        if(empty($body)) return [];

        $shareId_preg = '/var[ ]{1,}\_shareId = [\'\"]([\d]{1,})[\'\"]\;/';

        $verifyCode_preg = '/var[ ]{1,}\_verifyCode = [\'\"]([\d]{1,})[\'\"]\;/';

        preg_match($shareId_preg,$body,$shareid);

        preg_match($verifyCode_preg,$body,$verify);

        if(!empty($shareid[1]) && !empty($verify[1])){

            $r2 = $client->request('GET', 'https://cloud.189.cn/v2/listShareDir.action?shareId='.$shareid[1].'&accessCode='.$access_code.'&verifyCode='.$verify[1].'&orderBy=1&order=ASC&pageNum='.$pageNum.'&pageSize='.$pageSize.'&noCache=0.5371363944463458', [
                'allow_redirects' => false,
                'headers' => [
                    'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
                ]
            ]);

             $data=json_decode($r2->getBody()->getContents() ,true);
             $data['shareId'] = $shareid[1];
             $data['verifyCode'] = $verify[1];

             return $data;
        }
// https://cloud.189.cn/v2/listShareDir.action?fileId=41304112220510288&shareId=170548093&verifyCode=023756&orderBy=1&order=ASC&pageNum=1&pageSize=60&noCache=0.013857399210753907

        return [];
    }
}

当根目录里有文件夹时需要使用下面这个接口去获取文件夹里的信息,fileId 可以从以上示例接口返回的数据中得到。
https://cloud.189.cn/v2/listShareDir.action?fileId=41304112220510288&shareId=170548093&verifyCode=023756&orderBy=1&order=ASC&pageNum=1&pageSize=60&noCache=0.013857399210753907

需要注意的是此抓包实验会被封IP。