recherche

Maison  >  Questions et réponses  >  le corps du texte

抓取源码 - PHP怎么获得斗鱼TV源地址

在网上找了很多资料都试过了不行,现在遇到的问题是在接口地址参数里的参数值怎么生成
http://live.qq.com/swf_api/ro...
这面这个是接口地址每次刷新t和sign的参数都会变化,请教怎么获得这里参数,或者生成出

我之前在网上找到的Python语言写的抓钱改成PHP的生成出来的地址访问接口提示出错

function getmd5($str){
    $m=md5($str);
    return $m;
}
function l_request($action){
    $baseUrl = "http://www.douyutv.com/api/v1/room/";
    $midReq = "?aid=android&cdn=ws&client_sys=android&time=";
    $t=time();


    $md5_url= $action . $t . 1231;
    //$auth = getmd5($md5_url);

    $requrl= $baseUrl . $action . $midReq . $t . "&auth=" . getmd5($md5_url);
    return $requrl;
}
echo (l_request(10000346));
PHP中文网PHP中文网2817 Il y a quelques jours431

répondre à tous(1)je répondrai

  • 怪我咯

    怪我咯2017-04-10 17:45:27

    https://github.com/soimort/yo...
    这是python版的 自行改成php的


    php:

    <?php
    function curl($url,$cat='get',$post_data=''){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        if($cat=='post')
            curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        // curl_setopt($ch, CURLOPT_USERAGENT, "Python-urllib/3.5");
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36");
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
    $room_id = 55955;
    $url = "https://m.douyu.com/html5/live?roomId=" . $room_id ;
    $ret = curl($url);
    $ret = json_decode($ret,1);
    //print_r($ret);
    if($ret['msg'] != 'OK' || $ret['data']['show_status'] != 1){
        echo "直播未开播";exit;
    }
    $tt = time()/60;
    $did = md5(uniqid());
    $sign = md5("{$room_id}{$did}A12Svb&%1UUmf@hC{$tt}");
    
    $d = ['cdn'=>'ws', 'rate'=> '0', 'tt'=> $tt, 'did'=> $did, 'sign'=> $sign];
    $api_url = "http://www.douyu.com/lapi/live/getPlay/" . $room_id;
    
    $api_data = curl($api_url,'post',http_build_query($d));
    $api_data = json_decode($api_data,1);
    //print_r($api_data);
    if($api_data['error'] === 0){
        echo '直播流地址:' .  $api_data['data']['rtmp_url'] . '/' . $api_data['data']['rtmp_live'];
    }else{
        echo 'api请求错误';
    }

    répondre
    0
  • Annulerrépondre