|
试试这个:
- <?php
- // 获取频道ID,只允许1-4台
- $id = isset($_GET['id']) ? $_GET['id'] : 'nbtv1';
- $allowed_ids = ['nbtv1', 'nbtv2', 'nbtv3', 'nbtv4'];
- // 验证频道ID是否有效,无效则使用默认nbtv1
- if (!in_array($id, $allowed_ids)) {
- $id = 'nbtv1';
- }
- // 构建POST数据
- $post_data = [
- 'url' => 'http://liveplay.nbtv.cn/live/'.$id.'_md.m3u8',
- 'playType' => 'live',
- 'type' => 'cdn',
- 'cdnEncrypt' => 'd058c6c09b8cec3e4c8391557ac977714a35da41c4cfd40c75d6b4fdb37750b40af99e78071b72269b1614077c887c9431ce02c56739ed3a878ac3445c6352497f6ab0dec816df39192412e95509d2df4808e102380dd64ae67105a7266ec8ed580998e4e34dd62002039f872e1bda820ec4d9eaf8a11d658155d26c74125323c71e9743653e192327f3b6944ef0d219250f53718c6c38512eb9f142afe25f0838dff439d47fa695cb0eaf6473e4b4b6be62bfcbd240bc8d77d250809c1796c3cc54bdc2b70740c58cb3e39cf0ca4472d7c04c433a1daa8c6853e887aa36046c5bb959a58c0df05b81b399fad91372fea0aae029b73101c15d4bf220bbf975f7cb0a0c7ba42817d4aeebc8b8b6a3f2e83760724205a1f0eeab3dc2501d520baeab6463a0189135c00c96896e000fc28c',
- 'cdnIndex' => 0,
- ];
- $post_json = json_encode($post_data);
- // 初始化cURL
- $ch = curl_init('http://em.chinamcloud.com/player/encryptUrl');
- curl_setopt_array($ch, [
- CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_POST => 1,
- CURLOPT_POSTFIELDS => $post_json,
- CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
- CURLOPT_TIMEOUT => 10,
- CURLOPT_SSL_VERIFYPEER => false,
- CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
- ]);
- // 执行cURL请求
- $result = curl_exec($ch);
- // 检查cURL错误
- if (curl_errno($ch)) {
- header("HTTP/1.1 500 Internal Server Error");
- echo "服务器请求失败";
- curl_close($ch);
- exit;
- }
- curl_close($ch);
- // 解析JSON响应
- $response = json_decode($result);
- if (json_last_error() !== JSON_ERROR_NONE || !isset($response->url)) {
- header("HTTP/1.1 500 Internal Server Error");
- echo "数据解析失败";
- exit;
- }
- $playurl = $response->url;
- // 重定向到播放URL
- header('Location: ' . $playurl);
- ?>
复制代码
|
|