Home  >  Article  >  Backend Development  >  Grab the source code - How to get the source address of Douyu TV with PHP

Grab the source code - How to get the source address of Douyu TV with PHP

WBOY
WBOYOriginal
2016-12-01 00:56:404109browse

I have tried a lot of information on the Internet but it doesn’t work. The problem I am encountering now is how to generate the parameter value in the interface address parameter
http://live.qq.com/swf_api/ro...
This is this The parameters of t and sign will change every time the interface address is refreshed. Please tell me how to obtain these parameters, or generate them

The money-grabbing program written in Python that I found on the Internet before was changed to PHP. The generated address access interface prompted an error

<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>

Reply content:

I have tried a lot of information on the Internet but it doesn’t work. The problem I am encountering now is how to generate the parameter value in the interface address parameter
http://live.qq.com/swf_api/ro...
This is this The parameters of t and sign will change every time the interface address is refreshed. Please tell me how to obtain these parameters or generate them

The money-grabbing program written in Python that I found on the Internet was changed to PHP. The generated address access interface prompted an error

<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...
This is the python version. Change it to php by yourself


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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:ThinkPHP 5 Big U MethodsNext article:ThinkPHP 5 Big U Methods