|
|
<?php
error_reporting(0);
$id = $_GET['id']??'dfws';
$n = [
'dfws' => 1, //东方卫视4k
'shxwzh' => 2, //上海新闻综合
'shds' => 4, //上海都市
'dycj' => 5, //第1财 经
'hhxd' => 9, //哈哈炫动
'wxty' => 10, //五星体育
'mdy' => 11, //上海魔都眼
'jsrw' => 12, //上海新纪实(原纪实人文)
];
$t = time();
$nonce = getnonce(8);
$sign = md5(md5("Api-Version=v1&channel_id={$n[$id]}&nonce={$nonce}&platform=pc×tamp={$t}&version=7.1.14&28c8edde3d61a0411511d3b1866f0636"));
$h = [
"api-version: v1",
"nonce:".$nonce,
"m-uuid: D-8XPI8xaE6RMX4NZsu3e",
"platform:pc",
"version:7.1.14",
"timestamp:".$t,
"sign:".$sign,
];
$url = "https://kapi.kankanews.com/content/pc/tv/channel/detail?channel_id=".$n[$id];
$encrypted = json_decode(get($url,$h),1)['result']['live_address'];
$live = decrypted($encrypted);
if($id=='shds'||$id=='hhxd') {
$playurl = trim(strstr(m3u8($live),'https'));
header('location:'.$playurl);
//echo $playurl;
} else {
$burl = dirname($live).'/';
$playurl = preg_replace("/(.*?.ts)/i",$burl."$1",m3u8($live));
header('Content-Type: application/vnd.apple.mpegurl');
// header('location:'.$playurl);
print_r($playurl);
}
function get($url,$header){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_REFERER, 'https://live.kankanews.com/');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$d = curl_exec($ch);
curl_close($ch);
return $d;
}
function m3u8($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_REFERER, 'https://live.kankanews.com/');
$d = curl_exec($ch);
curl_close($ch);
return $d;
}
function getnonce($length) {
$base36 = base_convert(mt_rand()/mt_getrandmax(), 10, 36);
return substr($base36, -$length);
}
function decrypted($str){
//RSA公钥
$public_key = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDP5hzPUW5RFeE2xBT1ERB3hHZI\nVotn/qatWhgc1eZof09qKjElFN6Nma461ZAwGpX4aezKP8Adh4WJj4u2O54xCXDt\nwzKRqZO2oNZkuNmF2Va8kLgiEQAAcxYc8JgTN+uQQNpsep4n/o1sArTJooZIF17E\ntSqSgXDcJ7yDj5rc7wIDAQAB\n-----END PUBLIC KEY-----";
$pu_key = openssl_pkey_get_public($public_key);
$key_len = openssl_pkey_get_details($pu_key)['bits'];
$decrypted= "";
$part_len = $key_len / 8;
$parts = str_split(base64_decode($str), $part_len);
foreach ($parts as $part) {
$decrypted_temp = '';
openssl_public_decrypt($part, $decrypted_temp, $pu_key);
$decrypted .= $decrypted_temp;
}
return $decrypted;
}
?> |
|