1246406933 发表于 2024-12-8 13:30:59

求修改虎牙php代理源码,解决断流问题

求修改虎牙php代理源码,解决断流问题!


断流的源码如下


<?php
date_default_timezone_set("Asia/Shanghai");
$type = empty($_GET['type']) ? "nodisplay" : trim($_GET['type']);
$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://mp.huya.com/cache.php?m=Live&do=profileRoom&roomid=" . $id;


function get_content($apiurl, $flag)
{
    if ($flag == "mobile") {
      $headers = array(
            'Content-Type: application/x-www-form-urlencoded',
            'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 16_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Mobile/15E148 Safari/604.1'
      );
    } else {
      $arr = [
            "appId" => 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();
}

闽泉川 发表于 2024-12-8 18:44:44

这个是肥羊的吧

tombin 发表于 2024-12-8 23:10:58

闽泉川 发表于 2024-12-8 18:44
这个是肥羊的吧

我的php虎牙不断流。肥羊的docker也不断流!

闽泉川 发表于 2024-12-9 11:26:45

我的php也是不断流

love2310 发表于 2024-12-9 15:07:27

tombin 发表于 2024-12-8 23:10
我的php虎牙不断流。肥羊的docker也不断流!


分享一下php呗

love2310 发表于 2024-12-9 15:07:44

闽泉川 发表于 2024-12-9 11:26
我的php也是不断流


分享一下php呗
分享一下php呗

true 发表于 2024-12-13 11:05:16

<?php
$type = empty($_GET['type']) ? "nodisplay" : trim($_GET['type']);
$id = empty($_GET['id']) ? "116" : trim($_GET['id']);
$cdn = empty($_GET['cdn']) ? "txcdn" : trim($_GET['cdn']);
$media = empty($_GET['media']) ? "flv" : trim($_GET['media']);
$roomurl = "https://mp.huya.com/cache.php?m=Live&do=profileRoom&roomid=" . $id;


function get_content($apiurl, $flag)
{
    if ($flag == "mobile") {
      $headers = array(
            'Content-Type: application/x-www-form-urlencoded',
            'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 16_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Mobile/15E148 Safari/604.1'
      );
    } else {
      $arr = [
            "appId" => 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;
}
$d=get_content($roomurl, "mobile");
//echo $d;
$jsonStr = json_decode($d, true);
$realdata = $jsonStr["data"];
$uid = json_decode(get_content("https://udblgn.huya.com/web/anonymousLogin", "uid"), true)["data"]["uid"];

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"]);
            //echo $s["sFlvUrl"] . '/' . $s["sStreamName"] . '.' . $s["sFlvUrlSuffix"] . '?' . process_anticode($s["sFlvAntiCode"], $uid, $s["sStreamName"]).chr(10);   
      }
      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);
    echo $mediaurl;
    exit();
} else {
    header('location:' . $mediaurl);
    echo $mediaurl;
    exit();
}

true 发表于 2024-12-14 08:25:47

你用flv,php默认格式

true 发表于 2024-12-14 15:34:24

卡是你网络问题,只要不断流就行

1246406933 发表于 2024-12-14 16:10:36

true 发表于 2024-12-14 08:25
你用flv,php默认格式

用了这个帖子里面的代码不断流了 https://iptv.cc/thread-4895-1-1.html
页: [1]
查看完整版本: 求修改虎牙php代理源码,解决断流问题