找回密码
 立即注册
搜索
查看: 321|回复: 15

求助一下PHP源失效不知是哪里问题

  [复制链接]

14

主题

97

回帖

127

积分

注册会员

积分
127
发表于 2025-11-12 08:17:42 | 显示全部楼层 |阅读模式
本帖最后由 gz53713565 于 2025-11-12 10:46 编辑

求助一下PHP源失效不知是哪里问题,别人能播我的显示失效,求大佬帮忙分析一下。谢谢

  1. <?php
  2. /*
  3. 四川卫视,sc.php?id=1
  4. 四川新闻,sc.php?id=2
  5. 四川经济,sc.php?id=3
  6. 四川文化旅游,sc.php?id=4
  7. 四川影视文艺,sc.php?id=5
  8. 四川妇女儿童,sc.php?id=6
  9. 四川星空购物,sc.php?id=7
  10. 四川乡村,sc.php?id=8
  11. 康巴卫视,sc.php?id=9
  12. 四川卫视4K,sc.php?id=10
  13. */

  14. //https://www.sctv.com/watchTV
  15. //https://iptv.cc/forum.php?mod=viewthread&tid=5856&highlight=%E5%9B%9B%E5%B7%9D
  16. //https://www.utao.tv/
  17. //https://bgithub.xyz/VonChange/utao/releases

  18. if (need_m3u8($id, $ts_url)) {
  19.     $u = get_m3u8_url($id);
  20.     $c = send_request($u, $ct);
  21.     $c = replace_ts_urls($u, $c);
  22. } else {
  23.     $c = send_request($ts_url, $ct);
  24.     if ($ct == 'application/vnd.apple.mpegurl')
  25.         $c = replace_ts_urls($ts_url, $c);
  26. }
  27. echo_content($ct, $c);



  28. function need_m3u8(&$id, &$ts_url)
  29. {
  30.     $q = $_SERVER['QUERY_STRING'];
  31.     $r = stripos($q, 'id=') === 0;
  32.     if ($r)
  33.         $id = $_GET['id'];
  34.     else
  35.         $ts_url = $q;
  36.     return $r;
  37. }

  38. function get_m3u8_url($id)
  39. {
  40.     $u = 'http://api.vonchange.com/utao/sctv?tag='.$id;
  41.     $r = file_get_contents($u);
  42.     return $r;
  43. }

  44. function send_request($url, &$content_type)
  45. {
  46.     $ch = curl_init($url);
  47.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  48.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  49.     curl_setopt($ch, CURLOPT_REFERER, 'https://www.sctv.com/');
  50.     $ua = 'Mozilla/5.0 (Linux; U; Android 8.1.0; zh-cn; BLA-AL00 Build/HUAWEIBLA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/8.9 Mobile Safari/537.36';
  51.     curl_setopt($ch, CURLOPT_USERAGENT, $ua);
  52.     $res = curl_exec($ch);
  53.     $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
  54.     curl_close($ch);
  55.     return $res;
  56. }

  57. function replace_ts_urls($m3u8_url, $m3u8_content)
  58. {
  59.     //$m3u8_content = ltrim($m3u8_content, "\xEF\xBB\xBF");
  60.     $dest_ts_path = dirname($m3u8_url)."/";
  61.     $protocol = !empty($_SERVER['HTTPS']) ? 'https' : 'http';
  62.     $self_part = "$protocol://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

  63.     $s = 'URI="';
  64.     if (strpos($m3u8_content, $s) !== false)
  65.         $m3u8_content = str_replace($s, $s.$self_part.'?'.$dest_ts_path, $m3u8_content);

  66.     return preg_replace_callback("/^((?!#).+)$/im",
  67.         function ($matches) use ($self_part, $dest_ts_path) {
  68.             if (!is_absolute_url($matches[1]))
  69.                 $ts = $dest_ts_path.$matches[1];
  70.             else
  71.                 $ts = $matches[1];
  72.             return "$self_part?$ts";
  73.         },
  74.         $m3u8_content
  75.     );
  76. }

  77. function is_absolute_url($url) {
  78.     return stripos($url, 'http:') === 0 || stripos($url, 'https:') === 0;
  79. }

  80. function echo_content($content_type, $content)
  81. {
  82.     header("Access-Control-Allow-Origin: *");
  83.     header("Content-Type: $content_type");
  84.     echo $content;
  85. }
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

点评

国内IP测试可以,clawcloud上不行,应该服务器限制了  发表于 2025-11-12 11:21

1

主题

21

回帖

97

积分

注册会员

积分
97
发表于 2025-11-12 08:30:47 来自手机 | 显示全部楼层
你把sc.PHP改成sc.php试试?

14

主题

97

回帖

127

积分

注册会员

积分
127
 楼主| 发表于 2025-11-12 10:42:10 | 显示全部楼层
见好就收 发表于 2025-11-12 08:30
你把sc.PHP改成sc.php试试?

还是不行,帮忙看看这个PHP<?php
/*
四川卫视,sc.php?id=1
四川新闻,sc.php?id=2
四川经济,sc.php?id=3
四川文化旅游,sc.php?id=4
四川影视文艺,sc.php?id=5
四川妇女儿童,sc.php?id=6
四川星空购物,sc.php?id=7
四川乡村,sc.php?id=8
康巴卫视,sc.php?id=9
四川卫视4K,sc.php?id=10
*/

//https://www.sctv.com/watchTV
//https://iptv.cc/forum.php?mod=viewthread&tid=5856&highlight=%E5%9B%9B%E5%B7%9D
//https://www.utao.tv/
//https://bgithub.xyz/VonChange/utao/releases

if (need_m3u8($id, $ts_url)) {
    $u = get_m3u8_url($id);
    $c = send_request($u, $ct);
    $c = replace_ts_urls($u, $c);
} else {
    $c = send_request($ts_url, $ct);
    if ($ct == 'application/vnd.apple.mpegurl')
        $c = replace_ts_urls($ts_url, $c);
}
echo_content($ct, $c);



function need_m3u8(&$id, &$ts_url)
{
    $q = $_SERVER['QUERY_STRING'];
    $r = stripos($q, 'id=') === 0;
    if ($r)
        $id = $_GET['id'];
    else
        $ts_url = $q;
    return $r;
}

function get_m3u8_url($id)
{
    $u = 'http://api.vonchange.com/utao/sctv?tag='.$id;
    $r = file_get_contents($u);
    return $r;
}

function send_request($url, &$content_type)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_REFERER, 'https://www.sctv.com/');
    $ua = 'Mozilla/5.0 (Linux; U; Android 8.1.0; zh-cn; BLA-AL00 Build/HUAWEIBLA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/8.9 Mobile Safari/537.36';
    curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    $res = curl_exec($ch);
    $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
    curl_close($ch);
    return $res;
}

function replace_ts_urls($m3u8_url, $m3u8_content)
{
    //$m3u8_content = ltrim($m3u8_content, "\xEF\xBB\xBF");
    $dest_ts_path = dirname($m3u8_url)."/";
    $protocol = !empty($_SERVER['HTTPS']) ? 'https' : 'http';
    $self_part = "$protocol://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

    $s = 'URI="';
    if (strpos($m3u8_content, $s) !== false)
        $m3u8_content = str_replace($s, $s.$self_part.'?'.$dest_ts_path, $m3u8_content);

    return preg_replace_callback("/^((?!#).+)$/im",
        function ($matches) use ($self_part, $dest_ts_path) {
            if (!is_absolute_url($matches[1]))
                $ts = $dest_ts_path.$matches[1];
            else
                $ts = $matches[1];
            return "$self_part?$ts";
        },
        $m3u8_content
    );
}

function is_absolute_url($url) {
    return stripos($url, 'http:') === 0 || stripos($url, 'https:') === 0;
}

function echo_content($content_type, $content)
{
    header("Access-Control-Allow-Origin: *");
    header("Content-Type: $content_type");
    echo $content;
}
?>

1

主题

63

回帖

130

积分

注册会员

积分
130
发表于 2025-11-12 10:52:39 | 显示全部楼层
本帖最后由 zxh000297 于 2025-11-12 10:55 编辑

你第四张图显示你的sc.php文件存放路径在192.168.1.205:5090,你的调用地址是192.168.1.205:5080,且提示的File not found是文件未找到,你确认一下端口吧

你提供的sc.php代码我测试正常的

0

主题

29

回帖

98

积分

注册会员

积分
98
发表于 2025-11-12 11:21:02 | 显示全部楼层
国内IP测试可以,clawcloud上不行,应该服务器限制了

5

主题

43

回帖

105

积分

注册会员

积分
105
发表于 2025-11-12 11:37:57 | 显示全部楼层
测试正常的

14

主题

97

回帖

127

积分

注册会员

积分
127
 楼主| 发表于 2025-11-12 12:32:28 | 显示全部楼层

看看你测试的播放地址?

5

主题

43

回帖

105

积分

注册会员

积分
105
发表于 2025-11-12 14:09:35 | 显示全部楼层
gz53713565 发表于 2025-11-12 12:32
看看你测试的播放地址?

四川卫视4K,http://xxx.xxx.xxx/sc.php?id=10

就是这样式的格式

14

主题

97

回帖

127

积分

注册会员

积分
127
 楼主| 发表于 2025-11-12 14:16:10 | 显示全部楼层
zzj152 发表于 2025-11-12 14:09
四川卫视4K,http://xxx.xxx.xxx/sc.php?id=10

就是这样式的格式

对的,没错

14

主题

97

回帖

127

积分

注册会员

积分
127
 楼主| 发表于 2025-11-12 14:19:11 | 显示全部楼层
zzj152 发表于 2025-11-12 14:09
四川卫视4K,http://xxx.xxx.xxx/sc.php?id=10

就是这样式的格式

谢谢你,找到问题了 把PHP文件改成小写字母就OK了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|直播源论坛