yf1197565391 发表于 2025-2-5 18:23:38

<?php header('Content-Type: application/json');// IPTV 频道列表 $tv_list = [   'szws' => ['AxeFRth', '7867', '深圳卫视'],   'szds' => ['ZwxzUXr', '7868', '都市频道'],   'szdsj' => ['4azbkoY', '7880', '电视剧频道'],   'szgg' => ['2q76Sw2', '7874', '公共频道'],   'szcj' => ['3vlcoxP', '7871', '财经频道'],   'szse' => ['1SIQj6s', '7881', '少儿频道'],   'szyd' => ['wDF6KJ3', '7869', '移动电视'],   'szyh' => ['BJ5u5k2', '7878', '宜和购物频道'],   'szgj' => ['sztvgjpd', '7944', '国际频道'], ];// 通用 curl GET 请求 function curl_get($url, $params = null) {   if ($params) $url .= '?' . http_build_query($params);   $ch = curl_init($url);   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);   curl_setopt($ch, CURLOPT_REFERER,'https://www.sztv.com.cn/pindao/index.html?id=7868');   curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36');   $data = curl_exec($ch);curl_close($ch);   return $data; }// 获取密钥 function get_key($url, $params) {   return json_decode(curl_get($url, $params), true); }// Base64 解码逻辑 function ba($a) {   return base64_decode(implode('', array_reverse(str_split(substr($a, strlen($a) / 2) . substr($a, 0, strlen($a) / 2))))); }// 获取 m3u8 文件内容 function get_m3u8_content($live_id, $cdn_id) {   $live_key = ba(get_key('https://hls-api.sztv.com.cn/getCutvHlsLiveKey', [         't' => time(),         'id' => $live_id,         'token' => md5(time() . $live_id . 'cutvLiveStream|Dream2017'),         'at' => '1'   ]));         $cdn_key = get_key('https://sttv2-api.sztv.com.cn/api/getCDNkey.php', [         'domain' => 'sztv-live.sztv.com.cn',         'page' => 'https://www.sztv.com.cn/pindao/index.html?id=' . $cdn_id,         'token' => md5('iYKkRHlmUanQGaNMIJziWOkNsztv-live.sztv.com.cn' . time() * 1000),         't' => time() * 1000   ])['key'];      $t = dechex(time());   $sign = md5("$cdn_key/$live_id/500/$live_key.m3u8$t");   $url = "https://sztv-live.sztv.com.cn/$live_id/500/$live_key.m3u8?sign=$sign&t=$t";      return preg_replace_callback('/(\d{13})(\/\d+\.ts)/', function ($matches) use ($live_id) {         return "https://sztv-live.sztv.com.cn/$live_id/500/{$matches}{$matches}";   }, curl_get($url)); }// 处理 IPTV 请求 $id = $_GET['id'] ?? 'szds'; if (isset($tv_list[$id])) {   header('Content-Type: application/vnd.apple.mpegurl');   echo get_m3u8_content($tv_list[$id], $tv_list[$id]); } else {   echo json_encode(['code' => 400, 'message' => 'Invalid request']); } ?>   正常输出了DIYP无法播放指点下

guoma 发表于 2025-2-6 00:45:11

yf1197565391 发表于 2025-2-5 18:23
正常输出了DIYP无法播放指点下

<?php
error_reporting(0);
$id = $_GET['id'] ?? 'szws';
$n = [
    'szws' => 'AxeFRth', //深圳卫视
    'szds' => 'ZwxzUXr', //深圳都市
    'szdsj' => '4azbkoY', //深圳电视剧
    'szcjsh' => '3vlcoxP', //深圳财经生活
    'szse' => '1SIQj6s', //深圳少儿
    'szyd' => 'wDF6KJ3', //深圳移动电视
    'szgj' => 'sztvgjpd', //深圳国际
    'szyhgw' => 'BJ5u5k2', //深圳宜和购物
   ];

$t = time();
$token = md5($t.$n[$id].'cutvLiveStream|Dream2017');
$livekey = get("https://hls-api.sztv.com.cn/getCutvHlsLiveKey?t={$t}&token={$token}&id=".$n[$id]);
$livekey = preg_replace('/"/','',$livekey);
$sign = md5("ejow6p6p6hmrm9g96beh2knecdq5kyv9bp0zxyg7/$n[$id]/500/$livekey.m3u8$t");
$m3u8 = "https://sztv-live.sztv.com.cn/$n[$id]/500/$livekey.m3u8?sign=$sign&t=$t";
$burl = "https://sztv-live.sztv.com.cn/{$n[$id]}/500/";
$php = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$ts = $_GET['ts'];
if(!$ts) {
   header('Content-Type: application/vnd.apple.mpegurl');
   print_r(preg_replace("/(.*?.ts)/i", $php."?ts=$burl$1",get($m3u8)));
   } else {
       $data = get($ts);
       header('Content-Type: video/MP2T');
       echo $data;
       }
function get($url){
   $h = [
   "Origin: https://www.sztv.com.cn",
   "Referer: https://www.sztv.com.cn/",
   "User-Agent: Mozilla/5.0 (Windows NT 6.1)",
   ];
   $ch = curl_init($url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
   curl_setopt($ch, CURLOPT_HTTPHEADER,$h);
   $data = curl_exec($ch);   
   curl_close($ch);
   return $data;
   }
?>

gzlpsycw 发表于 2025-2-6 09:16:16

都是大佬,我这样小白只会拿来用。
页: 1 [2]
查看完整版本: 江西电视台代理的疑问