找回密码
 立即注册
搜索
查看: 198|回复: 3

哪位大神能写这个php

[复制链接]

32

主题

218

回帖

355

积分

等离子电视迷

积分
355
发表于 2025-12-21 09:11:54 | 显示全部楼层 |阅读模式
本帖最后由 11612158 于 2025-12-21 09:16 编辑

哪位大神能写一下这个鹦鹉台的php
http://tv.zimtv.cn



代码如下写的不全
<?php
error_reporting(0);
header('Content-Type:text/plain;charset=UTF-8');
define('hqid','id');
define('lb','vid');
if (isset($_GET[hqid])) {
    $query = $_SERVER['QUERY_STRING'];
$url = "http://tv.zimtv.cn/";
$info = extractChannelInfo($url);
preg_match('#var channelImgData = (.*?);</script>#i',$info,$ht);
$html = str_replace('var channelImgData = ','',$ht[0]);
$html = str_replace(';</script>','',$html);

//header("content-type:application/json;charset=utf8");
//die($html);
$data = json_decode($html,true);
foreach ($data as $key=>$itne){
    $id = str_replace('p=f&url=','',$itne['playurl']);
    echo "'".$itne['name']."'=>["."'channel_id'=>"."'".$id."'],"."\n";
}
}
//die($html);
// ------------------- 调用示例 -------------------
$cohd = [
   
'CCTV-1'=>['channel_id'=>'api/tj-edu.php?id=cctv1'],
'CCTV-2'=>['channel_id'=>'api/cctvlive.php?id=cctv2'],
'CCTV-3'=>['channel_id'=>'http://iptv.huuc.edu.cn/player.html?channel=cctv3hd'],
'CCTV-4'=>['channel_id'=>'api/cctvlive.php?id=cctv4'],
'CCTV-5'=>['channel_id'=>'https://www.nettvpro.xyz/embed/cctv/pc.php?id=5'],
'CCTV-6'=>['channel_id'=>'http://iptv.huuc.edu.cn/player.html?channel=cctv6hd'],
'CCTV-7'=>['channel_id'=>'api/cctvlive.php?id=cctv7'],
'CCTV-8'=>['channel_id'=>'http://iptv.huuc.edu.cn/player.html?channel=cctv8hd'],
'CCTV-9'=>['channel_id'=>'api/cctvlive.php?id=cctv9'],
'CCTV-10'=>['channel_id'=>'api/cctvlive.php?id=cctv10'],
'CCTV-11'=>['channel_id'=>'http://iptv.huuc.edu.cn/player.html?channel=cctv11hd'],
'CCTV-12'=>['channel_id'=>'api/cctvlive.php?id=cctv12'],
'CCTV-13'=>['channel_id'=>'api/tj-edu.php?id=cctv13'],
'CCTV-14'=>['channel_id'=>'http://iptv.huuc.edu.cn/player.html?channel=cctv14hd'],
'CCTV-15'=>['channel_id'=>'api/cctv.php?id=cctv15&tp=/tv/player/api/img-cctv2.php?id=cctv15'],
'CCTV-16'=>['channel_id'=>'api/cctv.php?id=cctv16&tp=/tv/player/api/img-cctv2.php?id=cctv16'],
'CCTV-17'=>['channel_id'=>'api/cctvlive.php?id=cctv17'],
'CCTV-5+'=>['channel_id'=>'api/cctv.php?id=cctv5plus&tp=/tv/player/api/img-cctv2.php?id=cctv5plus'],
'CCTV-4K'=>['channel_id'=>'api/cctvlive.php?id=cctv4k'],
'CCTV-4欧(美)洲'=>['channel_id'=>'api/cctv.php?id=cctveurope&tp=/tv/player/api/img-cctv2.php?id=cctveurope'],
    ];
    $current_path = rtrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
$current_script =  basename($current_path) . '?token=';
$current_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$parsed_url = parse_url($current_url);
$path = dirname($parsed_url['path']);
if ($path === '/') {
$path = '/';
} else {
$path = rtrim($path, '/') . '/';
}
$base_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . (isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '') . $path;
if (isset($_GET[lb])) {
    $query = $_SERVER['QUERY_STRING'];
     foreach ($cohd as $name => $config) {
        $output .= $name . "," . $base_url . $current_script . $name."\n";
    }
    exit($output);
}
// 执行多线程请求(最大5并发)
$token = isset($_GET['token']) ? $_GET['token'] : '';
$id = $cohd[$token]['channel_id'];
//die($id);
$api = "http://tv.zimtv.cn/tv/player/$id";
$output = getRedirectUrl($api);
//die(json_encode($cohd));
$pattern = '/https?:\/\/[^\s]+\.m3u8[^\s]*/i';

// 执行匹配
preg_match($pattern, $output, $matches);
header("Content-Type: application/vnd.apple.mpegURL");
header('Location:' . $matches[0] );
       // die($matches[0]); ;


function getRedirectUrl($url) {
    $ch = curl_init();
   
    // 设置 cURL 选项
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, true); // 获取响应头
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); // 不自动跟随重定向(手动处理)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 结果返回为字符串
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过 SSL 证书验证(生产环境谨慎使用)
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
   
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
   
    // 处理 302 重定向
    if ($httpCode == 302 || $httpCode == 301) {
        // 从响应头中提取 Location(重定向地址)
        preg_match('/Location: (.*?)\r\n/', $response, $matches);
        if (!empty($matches[1])) {
            // 递归获取最终地址(处理多次重定向)
            return getRedirectUrl($matches[1]);
        }
    }
   
    // 非重定向状态,返回原 URL 或最终 URL
   
    return $url;
}
function extractM3U8Urls($content) {
    $patterns = [
        '/["\'](https?["\']*\.m3u8["\']*)["\']/i',
        '/source.*?src=["\'](["\']+)["\']/i',
        '/video.*?src=["\'](["\']+)["\']/i',
        '/["\'](https?["\']*\/index\.m3u8["\']*)["\']/i',
        '/["\'](https?["\']*\/playlist\.m3u8["\']*)["\']/i',
        '/url.*?["\'](https?["\']*\.m3u8["\']*)["\']/i'
    ];
   
    $foundUrls = [];
   
    foreach ($patterns as $pattern) {
        if (preg_match_all($pattern, $content, $matches)) {
            foreach ($matches[1] as $url) {
                if (filter_var($url, FILTER_VALIDATE_URL) && strpos($url, '.m3u8') !== false) {
                $foundUrls[] = $url;
            }
        }
    }
    }
    return array_unique($foundUrls);
}
function extractChannelInfo($url)
{
   $curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_HTTPHEADER => [
    "Host: tv.zimtv.cn",
    "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0"
  ],
]);
    $data = curl_exec($curl);
    // $cookie = curl_getinfo($ch, CURLINFO_COOKIELIST);
    curl_close($curl);
    return $data;
}
?>

2

主题

272

回帖

280

积分

等离子电视迷

积分
280
发表于 2025-12-21 11:26:10 | 显示全部楼层
说实话他这个模板挺好的,早就看上了他这个模板了做的不错哈哈哈

3

主题

228

回帖

343

积分

等离子电视迷

积分
343
发表于 2025-12-21 12:34:30 | 显示全部楼层
能够补全使用吗?

0

主题

112

回帖

131

积分

彩电迷

积分
131
发表于 2025-12-21 13:24:41 | 显示全部楼层
  谢谢
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋

创办于 2025 年 5 月 5 日

快速回复 返回顶部 返回列表