<?php
// 定义频道映射关系
$channelMap = [
'gzzh' => '31', // 广州综合
'gzxw' => '32', // 广州新闻
'ngds' => '33', // 4K南国都市
'gzfz' => '34' // 广州法治
];
// 获取API数据
$apiUrl = 'https://gzbn.gztv.com:7443/plus-cloud-manage-app/liveChannel/queryLiveChannelList?type=1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
curl_close($ch);
// 解析JSON数据
$data = json_decode($response, true);
if ($data['code'] != 200 || empty($data['data'])) {
die('无法获取频道数据');
}
// 创建频道URL映射
$channelUrls = [];
$channelNames = [];
foreach ($data['data'] as $channel) {
$channelUrls[$channel['stationNumber']] = $channel['httpUrl'];
$channelNames[$channel['stationNumber']] = $channel['name'];
}
// 处理请求
if (isset($_GET['list'])) {
// 显示频道列表
header('Content-Type: text/plain; charset=utf-8');
$output = [];
foreach ($channelMap as $key => $stationNumber) {
if (isset($channelNames[$stationNumber])) {
$serverUrl = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
$output[] = $channelNames[$stationNumber] . ',' . $serverUrl . '?id=' . $key;
}
}
echo implode("\n", $output);
} elseif (isset($_GET['id'])) {
$id = $_GET['id'];
if (isset($channelMap[$id])) {
$stationNumber = $channelMap[$id];
if (isset($channelUrls[$stationNumber])) {
header("Location: " . $channelUrls[$stationNumber]);
exit;
}
}
die('无效的频道ID');
} else {
// 默认显示使用说明
header('Content-Type: text/plain; charset=utf-8');
echo "广州电视台直播源\n\n";
echo "使用方法:\n";
echo "1. 访问 http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?list 查看频道列表\n";
echo "2. 访问 http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?id=频道ID 跳转到对应直播源\n";
echo "\n示例:\n";
echo "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?id=gzzh\n";
echo "\n当前可用的频道ID:\n";
echo implode(",", array_keys($channelMap));
}
?>