<?php
// 滨州电视台直播源代理
// 标准化改进版
// 添加严格的HTTP头部控制
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('Expires: 0');
header('X-Content-Type-Options: nosniff');
header('X-Frame-Options: DENY');
header('X-XSS-Protection: 1; mode=block');
header('Access-Control-Allow-Origin: *');
// 配置常量
const API_URL = 'https://app.binzhouw.com/cms_mob/v200/cms_oth/chan.json';
const TIMEOUT = 10;
/**
* 获取API数据
* @return array|false 解析后的API数据或false
*/
function fetchApiData() {
$ch = curl_init();
// 配置curl选项
curl_setopt_array($ch, [
CURLOPT_URL => API_URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => TIMEOUT,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
CURLOPT_FOLLOWLOCATION => true
]);
$response = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
error_log('Curl error: ' . $error);
return false;
}
// 解析JSON数据
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
error_log('JSON decode error: ' . json_last_error_msg());
return false;
}
return $data;
}
// 短ID映射
$shortIdMap = [
'zh' => 'tvZongHe', // 新闻综合频道短ID
'ms' => 'tvMinSheng' // 民生频道短ID
];
// 获取请求参数
$channel_id = isset($_GET['id']) ? trim($_GET['id']) : '';
// 转换短ID为完整ID
if (isset($shortIdMap[$channel_id])) {
$channel_id = $shortIdMap[$channel_id];
}
// 主逻辑
if (empty($channel_id)) {
// 显示频道列表
header('Content-Type: text/html; charset=UTF-8');
$data = fetchApiData();
if ($data && isset($data['code']) && $data['code'] == 1 && isset($data['result']['data'])) {
echo '<!DOCTYPE html>';
echo '<html lang="zh-CN">';
echo '<head>';
echo '<meta charset="UTF-8">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
echo '<title>滨州电视台频道列表</title>';
echo '<style>';
echo 'body { font-family: Arial, sans-serif; margin: 20px; background-color: #f5f5f5; }';
echo 'h1 { color: #333; }';
echo 'a { display: block; margin: 10px 0; padding: 10px; background-color: #007bff; color: white; text-decoration: none; border-radius: 4px; }';
echo 'a:hover { background-color: #0056b3; }';
echo '</style>';
echo '</head>';
echo '<body>';
echo '<h1>滨州电视台频道列表</h1>';
foreach ($data['result']['data'] as $id => $url) {
if (!empty($url) && filter_var($url, FILTER_VALIDATE_URL)) {
echo "<a href='?id=$id'>$id</a>";
}
}
echo '</body>';
echo '</html>';
} else {
http_response_code(500);
header('Content-Type: text/plain; charset=UTF-8');
echo '获取频道列表失败';
}
} else {
// 重定向到指定频道
$data = fetchApiData();
if ($data && isset($data['code']) && $data['code'] == 1 && isset($data['result']['data'][$channel_id])) {
$stream_url = $data['result']['data'][$channel_id];
// 验证URL格式
if (filter_var($stream_url, FILTER_VALIDATE_URL)) {
header('Location: ' . $stream_url);
exit;
} else {
http_response_code(500);
header('Content-Type: text/plain; charset=UTF-8');
echo '无效的直播源URL';
}
} else {
http_response_code(404);
header('Content-Type: text/plain; charset=UTF-8');
echo '频道不存在';
}
}
?>
- 新闻综合频道:使用id=zh或id=tvZongHe
- 民生频道:使用id=ms或id=tvMinSheng |