5002, "byPass" => 3, "context" => "", "version" => "2.4", "data" => new stdClass(), ]; $postData = json_encode($arr); $headers = array( 'Content-Type: application/json', 'Content-Length: ' . strlen($postData), 'upgrade-insecure-requests: 1', 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36' ); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $apiurl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); if ($flag == "uid") { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); } $data = curl_exec($ch); curl_close($ch); return $data; } $jsonStr = json_decode(get_content($roomurl, "mobile"), true); $realdata = $jsonStr["data"]; $uid = json_decode(get_content("https://udblgn.huya.com/web/anonymousLogin", "uid"), true)["data"]["uid"]; function aes_decrypt($ciphertext, $key, $iv) { return openssl_decrypt($ciphertext, 'AES-256-CBC', $key, 0, $iv); } $key = "abcdefghijklmnopqrstuvwxyz123456"; $iv = "1234567890123456"; $mediaurl = aes_decrypt("fIuPMpBI1RpRnM2JhbYHzvwCvwhHBF7Q+8k14m9h3N5ZfubHcDCEk08TnLwHoMI/SG7bxpqT6Rh+gZunSpYHf1JM/RmEC/S1SjRYWw6rwc3gGo3Rrsl3sojPujI2aZsb", $key, $iv); function get_uuid() { $now = intval(microtime(true) * 1000); $rand = rand(0, 1000) | 0; return intval(($now % 10000000000 * 1000 + $rand) % 4294967295); } function process_anticode($anticode, $uid, $streamname) { parse_str($anticode, $q); $q["t"] = '102'; $q["ctype"] = 'tars_mp'; $q["wsTime"] = dechex(time() + 21600); $q["ver"] = "1"; $q["sv"] = date('YmdH'); $q["seqid"] = strval(intval($uid) + intval(microtime(true) * 1000)); $q["uid"] = strval($uid); $q["uuid"] = strval(get_uuid()); $ss = md5("{$q["seqid"]}|{$q["ctype"]}|{$q["t"]}"); $q["fm"] = base64_decode($q["fm"]); $q["fm"] = str_replace(["$0", "$1", "$2", "$3"], [$q["uid"], $streamname, $ss, $q["wsTime"]], $q["fm"]); $q["wsSecret"] = md5($q["fm"]); unset($q["fm"]); if (array_key_exists("txyp", $q)) { unset($q["txyp"]); } return http_build_query($q); } function format($realdata, $uid) { $stream_info = ['flv' => [], 'hls' => []]; $cdn_type = ['HY' => 'hycdn', 'TX' => 'txcdn', 'HW' => 'hwcdn', 'HS' => 'hscdn', 'WS' => 'wscdn']; foreach ($realdata["stream"]["baseSteamInfoList"] as $s) { if ($s["sFlvUrl"]) { $stream_info["flv"][$cdn_type[$s["sCdnType"]]] = $s["sFlvUrl"] . '/' . $s["sStreamName"] . '.' . $s["sFlvUrlSuffix"] . '?' . process_anticode($s["sFlvAntiCode"], $uid, $s["sStreamName"]); } if ($s["sHlsUrl"]) { $stream_info["hls"][$cdn_type[$s["sCdnType"]]] = $s["sHlsUrl"] . '/' . $s["sStreamName"] . '.' . $s["sHlsUrlSuffix"] . '?' . process_anticode($s["sHlsAntiCode"], $uid, $s["sStreamName"]); } } return $stream_info; } if ($jsonStr["status"] == 200) { $realurl = format($realdata, $uid); if ($type == "display") { print_r($realurl); exit(); } if ($media == "flv") { switch ($cdn) { case $cdn: $mediaurl = str_replace("http://", "https://", $realurl["flv"][$cdn]); break; default: $mediaurl = str_replace("http://", "https://", $realurl["flv"]["hwcdn"]); break; } } if ($media == "hls") { switch ($cdn) { case $cdn: $mediaurl = str_replace("http://", "https://", $realurl["hls"][$cdn]); break; default: $mediaurl = str_replace("http://", "https://", $realurl["hls"]["hwcdn"]); break; } } header('location:' . $mediaurl); exit(); } else { header('location:' . $mediaurl); exit(); }