首页 >后端开发 >php教程 >抓取源码 - PHP怎么获得斗鱼TV源地址

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

WBOY
WBOY原创
2016-12-01 00:56:404140浏览

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

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

<code>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));</code>

回复内容:

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

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

<code>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));</code>

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


php:

<code><?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请求错误';
}</code>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn