| 
 网站升级https后 发现使用http的hls直播源均无法正常播放了 网站引用了多个http hls直播源 如何才能让恢复使用呢 ?这里采用的是服务端转发 代码如下 <?php
error_reporting(0);
header("ACCESS-CONTROL-ALLOW-ORIGIN:*");
function get_url_contents($url)
{
    if (function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_URL, $url);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    } else {
        if (ini_get("allow_url_fopen") == "1") {
            return file_get_contents($url);
        }
    }
}
function resolve_hls($url)
{
    $url = trim(urldecode($url));
    $old = pathinfo($url);
    $m3u8 = get_url_contents($url);
    if (!empty($old['dirname'])) {
        if (strpos($m3u8,'EXT-X-STREAM-INF')!== false) {
            try {
                preg_match_all('/([\S]+)(\.m3u8)+(.*)?/i', $m3u8, $match);
                $new = $match[0][0];
                if (stripos($new, 'http:') !== false || stripos($new, 'https:') !== false || substr($new, 0, 2) == '//') {
                    $newUrl = $new;
                } else {
                    $newUrl = $old['dirname'] . '/' . $new;
                }
                resolve_hls($newUrl);
            }catch (\Exception $exception) {
                echo $exception->getMessage();
            }
        } else {
            try {
                preg_match_all('/([\S]+)(\.ts)+(.*)?/i', $m3u8, $match_ts);
                if(empty($match_ts[0][0])){
                    preg_match_all('/([\S]+)(\.aac)+(.*)?/i', $m3u8, $match_ts);
                }
                $new = $match_ts[0][0];
                if (stripos($new, 'http:') !== false || stripos($new, 'https:') !== false || substr($new, 0, 2) == '//') {
                echo $m3u8;
                } else {
                    $newUrl = $old['dirname'] . '/';
                echo preg_replace_callback('/([\S]+)(\.ts)+(.*)?/i', function ($mtches) use ($newUrl){
                    return 'https://qianxun.damicms.com/transhls.php?action=' . urlencode($newUrl . $mtches[0]);
                    }, $m3u8);
                }
            } catch (\Exception $exception) {
                echo $exception->getMessage();
            }
        }
    }
}
if (!empty($_GET['url'])) {
    $url = urldecode($_GET['url']);
    resolve_hls($url);
} else if(!empty($_GET['action'])){
    $url2 = trim(urldecode($_GET['action']));
    if(stripos($url2, 'https:') !== false){
    header("Location:{$url2}");
    }else{
    $m3u8 = get_url_contents($url2);
    echo $m3u8;
    }
}
?>
 |