fix huya.php

pull/70/head
肥羊 2 years ago committed by GitHub
parent fdbfea3108
commit fe7daf9d3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 29
      PHP/huya.php

@ -1,10 +1,11 @@
<?php <?php
date_default_timezone_set("Asia/Shanghai"); date_default_timezone_set("Asia/Shanghai");
$type = empty($_GET['type']) ? "nodisplay" : trim($_GET['type']); $type = empty($_GET['type']) ? "nodisplay" : trim($_GET['type']);
$id = empty($_GET['id']) ? "shangdi" : trim($_GET['id']); $id = empty($_GET['id']) ? "11342412" : trim($_GET['id']);
$cdn = empty($_GET['cdn']) ? "hwcdn" : trim($_GET['cdn']); $cdn = empty($_GET['cdn']) ? "hwcdn" : trim($_GET['cdn']);
$media = empty($_GET['media']) ? "flv" : trim($_GET['media']); $media = empty($_GET['media']) ? "flv" : trim($_GET['media']);
$roomurl = "https://m.huya.com/" . $id; $roomurl = "https://mp.huya.com/cache.php?m=Live&do=profileRoom&roomid=" . $id;
function get_content($apiurl, $flag) function get_content($apiurl, $flag)
{ {
@ -44,6 +45,10 @@ function get_content($apiurl, $flag)
return $data; 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) function aes_decrypt($ciphertext, $key, $iv)
{ {
return openssl_decrypt($ciphertext, 'AES-256-CBC', $key, 0, $iv); return openssl_decrypt($ciphertext, 'AES-256-CBC', $key, 0, $iv);
@ -53,7 +58,6 @@ $key = "abcdefghijklmnopqrstuvwxyz123456";
$iv = "1234567890123456"; $iv = "1234567890123456";
$mediaurl = aes_decrypt("fIuPMpBI1RpRnM2JhbYHzvwCvwhHBF7Q+8k14m9h3N5ZfubHcDCEk08TnLwHoMI/SG7bxpqT6Rh+gZunSpYHf1JM/RmEC/S1SjRYWw6rwc3gGo3Rrsl3sojPujI2aZsb", $key, $iv); $mediaurl = aes_decrypt("fIuPMpBI1RpRnM2JhbYHzvwCvwhHBF7Q+8k14m9h3N5ZfubHcDCEk08TnLwHoMI/SG7bxpqT6Rh+gZunSpYHf1JM/RmEC/S1SjRYWw6rwc3gGo3Rrsl3sojPujI2aZsb", $key, $iv);
$uid = json_decode(get_content("https://udblgn.huya.com/web/anonymousLogin", "uid"), true)["data"]["uid"];
function get_uuid() function get_uuid()
{ {
@ -84,11 +88,11 @@ function process_anticode($anticode, $uid, $streamname)
return http_build_query($q); return http_build_query($q);
} }
function format($livearr, $uid) function format($realdata, $uid)
{ {
$stream_info = ['flv' => [], 'hls' => []]; $stream_info = ['flv' => [], 'hls' => []];
$cdn_type = ['HY' => 'hycdn', 'AL' => 'alicdn', 'TX' => 'txcdn', 'HW' => 'hwcdn', 'HS' => 'hscdn', 'WS' => 'wscdn']; $cdn_type = ['HY' => 'hycdn', 'TX' => 'txcdn', 'HW' => 'hwcdn', 'HS' => 'hscdn', 'WS' => 'wscdn'];
foreach ($livearr["roomInfo"]["tLiveInfo"]["tLiveStreamInfo"]["vStreamInfo"]["value"] as $s) { foreach ($realdata["stream"]["baseSteamInfoList"] as $s) {
if ($s["sFlvUrl"]) { if ($s["sFlvUrl"]) {
$stream_info["flv"][$cdn_type[$s["sCdnType"]]] = $s["sFlvUrl"] . '/' . $s["sStreamName"] . '.' . $s["sFlvUrlSuffix"] . '?' . process_anticode($s["sFlvAntiCode"], $uid, $s["sStreamName"]); $stream_info["flv"][$cdn_type[$s["sCdnType"]]] = $s["sFlvUrl"] . '/' . $s["sStreamName"] . '.' . $s["sFlvUrlSuffix"] . '?' . process_anticode($s["sFlvAntiCode"], $uid, $s["sStreamName"]);
} }
@ -99,15 +103,7 @@ function format($livearr, $uid)
return $stream_info; return $stream_info;
} }
$res = get_content($roomurl, "mobile"); if ($jsonStr["status"] == 200) {
$reg = "/\<script\> window.HNF_GLOBAL_INIT = (.*) \<\/script\>/i";
preg_match($reg, $res, $realres);
$realdata = json_decode($realres[1], true);
if (array_key_exists("exceptionType", $realdata)) {
header('location:' . $mediaurl);
exit();
} elseif ($realdata["roomInfo"]["eLiveStatus"] == 2) {
$realurl = format($realdata, $uid); $realurl = format($realdata, $uid);
if ($type == "display") { if ($type == "display") {
print_r($realurl); print_r($realurl);
@ -135,9 +131,6 @@ if (array_key_exists("exceptionType", $realdata)) {
} }
header('location:' . $mediaurl); header('location:' . $mediaurl);
exit(); exit();
} elseif ($realdata["roomInfo"]["eLiveStatus"] == 3) {
header('location:' . "https:" . base64_decode($realdata["roomProfile"]["liveLineUrl"]));
exit();
} else { } else {
header('location:' . $mediaurl); header('location:' . $mediaurl);
exit(); exit();

Loading…
Cancel
Save