|
|
请登陆查看全文
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- <?php
- // 获取房间号参数
- $roomId = $_GET['id'];
- if (empty($roomId)) {
- die('请提供房间号,格式:cc163.php?id=房间号');
- }
- // 网易CC直播页面URL
- $url = "https://cc.163.com/{$roomId}/";
- // 设置请求头
- $headers = array(
- 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36',
- 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
- 'Accept-Language: zh-CN,zh;q=0.9',
- 'Referer: https://cc.163.com/',
- 'Upgrade-Insecure-Requests: 1'
- );
- // 初始化cURL会话
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- // 执行请求并获取响应
- $response = curl_exec($ch);
- // 检查是否有错误
- if(curl_errno($ch)) {
- die('错误: ' . curl_error($ch));
- }
- curl_close($ch);
- // 查找sharefile字段
- $pattern = '/"sharefile":"([^"]+?)"/';
- preg_match($pattern, $response, $matches);
- if (empty($matches[1])) {
- die('未找到sharefile字段');
- }
- // 解码URL
- $sharefile = json_decode('"' . $matches[1] . '"');
- if (empty($sharefile)) {
- die('sharefile字段解析失败');
- }
- // 检查是否为m3u8地址
- if (strpos($sharefile, '.m3u8') === false) {
- die('sharefile字段不是m3u8地址');
- }
- // 设置CORS头
- header('Access-Control-Allow-Origin: *');
- // 跳转到m3u8地址
- header('Location: ' . $sharefile);
- ?>
复制代码
|
|