福建厦门几个频道的代理源码
源码相关说明:
1,源码有时效性,无时间保障,可能当天就失效,这些都是正常现象,不提供后期维护。
2,部分源码需要国内主机支持,故而境外主机无法使用。
3,部分源码需要服务器支持,包括但不限于PHP版本、某些参数等等。
4,所有源码都会有演示,演示没问题的话,请自行解决服务器相关问题,不做任何解答。给钱的大爷除外。
5,最重要的一点:部分源码其实是网络公开的,可能会收费,是因为我花时间了,你大可以自己去找,就看你的时间值不值这几毛钱了。如果有时间建议自己去找。
频道列表
厦门卫视,http://115.190.252.60:26759/fj/fjxm.php?id=xmws厦门1套,http://115.190.252.60:26759/fj/fjxm.php?id=xmtv1厦门2套,http://115.190.252.60:26759/fj/fjxm.php?id=xmtv2厦门移动电视,http://115.190.252.60:26759/fj/fjxm.php?id=xmtv4
代理源码内容如下,此代理可能需要国内主机:
<?phpif(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);}echo_content($ct, $c);functionneed_m3u8(&$id, &$ts_url){$q = $_SERVER['QUERY_STRING'];$r = stripos($q, 'id=') === 0;if($r) {$id = $_GET['id'];// 将频道名称转换为数字ID$id = convert_channel_name_to_id($id);} else {$ts_url = $q;}return $r;}// 频道名称到ID的映射函数functionconvert_channel_name_to_id($channel_name) {// 频道映射表$channel_map = ['xmws' => '84', // 厦门卫视'xmtv1' => '16', // 厦视一套'xmtv2' => '17', // 厦视二套'xmtv4' => '52' // 厦门电视台移动电视];// 如果是频道名称,转换为ID;如果是数字ID,直接返回if(isset($channel_map[$channel_name])) {return $channel_map[$channel_name];} else {// 如果不在映射表中,检查是否为数字IDif(is_numeric($channel_name)) {return $channel_name;} else {// 未知频道名称,返回默认值或抛出错误return '84'; // 默认返回厦门卫视}}}functionget_m3u8_url($id){$r = load_from_cache($id);if($r)return $r;$r = get_m3u8_url_from_web($id);save_to_cache($id, $r);return $r;}functionget_m3u8_url_from_web($id) {$u = "https://mapi1.kxm.xmtv.cn/api/v1/channel.php?channel_id=".$id;$c = send_request($u);$j = json_decode($c);return $j[0] -> channel_stream[0] -> m3u8;}functionsave_to_cache($id, $url){$a[$id]['expire_time'] = time() + 60 * 60;$a[$id]['url'] = $url;array_to_file($a, 'xmtv_cache.txt');}functionload_from_cache($id){file_to_array('xmtv_cache.txt', $a);if(isset($a) && isset($a[$id]) && $a[$id]['expire_time'] > time())return $a[$id]['url'];elsereturn '';}functionfile_to_array($filename, &$array) {$array = [];if(file_exists($filename)) {$handle = fopen($filename, 'r');if(flock($handle, LOCK_SH)) { // 共享锁,允许其他进程读但禁止写$data = file_get_contents($filename);$array = unserialize($data);flock($handle, LOCK_UN);}fclose($handle);}return true;}functionarray_to_file($array, $filename) {$data = serialize($array);file_put_contents($filename, $data, LOCK_EX);return true;}functionsend_request($url, &$content_type = null){$ch = curl_init($url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_REFERER, 'https://seexm2024.kxm.xmtv.cn/');$res = curl_exec($ch);if(func_num_args() > 1)$content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);curl_close($ch);return $res;}functionreplace_ts_urls($m3u8_url, $m3u8_content){$dest_ts_path = dirname($m3u8_url)."/";$dest_ts_domain_path = implode("/", array_slice(explode("/", $m3u8_url), 0, 3));$protocol = !empty($_SERVER['HTTPS']) ? 'https' : 'http';$self_part = "$protocol://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];return preg_replace_callback("/^((?!#).+)$/im",function ($matches) use ($self_part, $dest_ts_path, $dest_ts_domain_path) {if (!is_absolute_url($matches[1]))if ($matches[1][0] == '/')$ts = $dest_ts_domain_path.$matches[1];else$ts = $dest_ts_path.$matches[1];else$ts = $matches[1];return "$self_part?$ts";},$m3u8_content);}functionis_absolute_url($url) {return stripos($url, 'http:') === 0 || stripos($url, 'https:') === 0;}functionecho_content($content_type, $content){header("Access-Control-Allow-Origin: *");header("Content-Type: $content_type");echo $content;}
夜雨聆风