此代码为“西藏卫视”系列电视直播代理源码,此代码无需PHP环境,可在纯前端(静态)环境中运行。

演示地址:
源码:(html+javascript)
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>西藏卫视</title>
</head>
<body>
<script>
// 使用严格模式
"use strict";
/**
* 获取西藏卫视的电视直播流地址
* @param {string|number} id 频道ID(可选:0,1,2)
* @returns {Promise<string|null>} 播放流地址
*/
(async () => {
try {
// 发送GET请求
const response = await fetch('https://api.vtibet.cn/xizangmobileinf/rest/xz/cardgroups', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'json=' + encodeURIComponent(JSON.stringify({
cardgroups: "LIVECAST",
paging: {
page_no: "1",
page_size: "100"
},
version: "1.0.0"
})),
mode: 'cors'
});
if (!response.ok) throw new Error('HTTP状态码: ' + response.status);
let data = await response.json();
data = data.cardgroups[1].cards[new URLSearchParams(window.location.search).get('id') || '0'].video
.url_hd;
// 返回数据
if (data) {
return window.location.href = data;
}
return alert('数据不存在');
} catch (error) {
return alert('捕获错误: ' + error.message);
}
})();
</script>
</body>
</html>使用方法:
访问示例:
频道ID:(频道ID => 频道名称)
0 => 西藏卫视(默认)
1 => 藏语卫视
2 => 影视文化