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. 31
      PHP/huya.php

@ -1,10 +1,11 @@
<?php
date_default_timezone_set("Asia/Shanghai");
$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']);
$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)
{
@ -44,6 +45,10 @@ function get_content($apiurl, $flag)
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);
@ -53,7 +58,6 @@ $key = "abcdefghijklmnopqrstuvwxyz123456";
$iv = "1234567890123456";
$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()
{
@ -84,11 +88,11 @@ function process_anticode($anticode, $uid, $streamname)
return http_build_query($q);
}
function format($livearr, $uid)
function format($realdata, $uid)
{
$stream_info = ['flv' => [], 'hls' => []];
$cdn_type = ['HY' => 'hycdn', 'AL' => 'alicdn', 'TX' => 'txcdn', 'HW' => 'hwcdn', 'HS' => 'hscdn', 'WS' => 'wscdn'];
foreach ($livearr["roomInfo"]["tLiveInfo"]["tLiveStreamInfo"]["vStreamInfo"]["value"] as $s) {
$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"]);
}
@ -99,15 +103,7 @@ function format($livearr, $uid)
return $stream_info;
}
$res = get_content($roomurl, "mobile");
$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) {
if ($jsonStr["status"] == 200) {
$realurl = format($realdata, $uid);
if ($type == "display") {
print_r($realurl);
@ -135,10 +131,7 @@ if (array_key_exists("exceptionType", $realdata)) {
}
header('location:' . $mediaurl);
exit();
} elseif ($realdata["roomInfo"]["eLiveStatus"] == 3) {
header('location:' . "https:" . base64_decode($realdata["roomProfile"]["liveLineUrl"]));
exit();
} else {
header('location:' . $mediaurl);
exit();
}
}
Loading…
Cancel
Save