|
|
这个试试
- <?php
- error_reporting(0);
- header("Access-Control-Allow-Origin: *");
- header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
- $id = isset($_GET['id']) ? $_GET['id'] : 'jncqxw';
- $n = [
- //济南
- "jncqxw" => [171,1], //长清新闻 - 第1个节目
- "jncqsh" => [171,2], //长清生活 - 第2个节目
- "jnjrtv" => [303,1], //济铁电视台
- "jnjyzh" => [85,1], //济阳综合
- "jnjyys" => [85,2], //济阳影视
- "jnlcxw" => [261,1], //历城新闻综合
- "jnpyzh" => [257,1], //平阴综合
- "jnpyxc" => [257,3], //平阴乡村振兴
- "jnshzh" => [97,1], //商河综合
- "jnshys" => [97,2], //商河影视
- "jnzqzh" => [195,1], //章丘综合
- "jnzqgg" => [195,2], //章丘公共
- ];
- function fetch_url($url) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- $headers = [
- 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/517.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/517.36',
- 'sec-ch-ua-platform: "Windows"'
- ];
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- $result = curl_exec($ch);
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
-
- if ($http_code != 200) {
- return false;
- }
- return $result;
- }
- try {
- if (!isset($n[$id])) {
- throw new Exception("频道不存在");
- }
- $orgid = $n[$id][0];
- $channel_index = $n[$id][1];
- $api_url = "https://app.litenews.cn/v1/app/play/tv/live?orgid=" . $orgid;
- $response = fetch_url($api_url);
- if ($response === false) {
- throw new Exception("无法获取频道数据");
- }
- $data = json_decode($response, true);
- if ($data['code'] != 1 || !isset($data['data']) || !is_array($data['data'])) {
- throw new Exception("频道数据解析失败");
- }
- if ($channel_index < 1 || $channel_index > count($data['data'])) {
- throw new Exception("频道序号超出范围");
- }
- $channel = $data['data'][$channel_index - 1];
- if (!isset($channel['stream'])) {
- throw new Exception("未找到可用的直播流");
- }
- $stream_url = $channel['stream'];
- header("Content-Type: text/plain");
- echo $stream_url;
- } catch (Exception $e) {
- header("Content-Type: text/plain");
- echo "错误: " . $e->getMessage();
- }
- ?>
复制代码
|
|