在網路上找了很多資料都試過了不行,現在遇到的問題是在介面位址參數裡的參數值怎麼產生
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>