|
|
如题目所示!!!!!!
我用了之前的咪咕ID版本的php代码,先是配置成功后,播放了一天时间。
第二天,回家就不能用了。不知道什么原因。
麻烦各位大佬,改一下代码。
谢谢!!谢谢!!谢谢!!谢谢!!谢谢!!谢谢!!谢谢!!谢谢!!
请看附件内容。
代码如下《《《《《《《《《《《《《
<?php
//注意: $userId = "我按F12,粘贴代码获取到的userID";
// $userToken = "我按F12,粘贴代码获取到的token";
function salt_table() {
return [
"7c8ddcab45b340ecbb02bc979c7f58c8", "7a5d79ed05ed48c4908b0179d5a5eb2c", "2195d5312d114db397bcfb5ade3784cf",
"5454203c18274e8a961efe328a59d1f9", "aa4688fcf6844e809cb428dc4bd5f265", "96f3d14a9fe144589f10c775e0c9b4b0",
"fbc05527db71425f8094e659d62eb878", "c8e65a8b8b3d46f89397573bfa06f68a", "a1ef732fa53846c3ba96ada1dcf2513d",
(因为帖子字数限制,我删除了一部分)
"58cf465392214c91bc18bd8c46d3b109"
];
}
function migu_cache_dir(): string
{
$dir = __DIR__ . '/migucache';
if (!is_dir($dir)) {
@mkdir($dir, 0775, true);
}
return $dir;
}
function cache_path($key) {
return migu_cache_dir()."/migu_cache_".md5($key).".json";
}
function get_migu_cache($key) {
$p = cache_path($key);
if (!is_file($p)) return [null,false];
$d = json_decode(@file_get_contents($p), true);
if (!$d) return [null,false];
if (time() - intval($d['time']) > intval($d['ttl'])) { @unlink($p); return [null,false]; }
return [$d['url'], true];
}
function set_migu_cache($key, $url, $ttl_seconds) {
$p = cache_path($key);
@file_put_contents($p, json_encode(['url'=>$url,'time'=>time(),'ttl'=>$ttl_seconds], JSON_UNESCAPED_SLASHES));
}
function url_sign($md5string) {
$salt = strval(random_int(10000000, 99999999));
$saltInt = intval(substr($salt, 6));
$idx = $saltInt % 100;
$table = salt_table();
$text = $md5string . $table[$idx] . "migu" . substr($salt, 0, 4);
$sign = md5($text);
return [$salt, $sign];
}
function get_sign_config($contId) {
$appVersion = "2600037000";
$tm = (string)intval(microtime(true) * 1000);
$md5string = md5($tm . $contId . substr($appVersion, 0, 8));
return [$tm, url_sign($md5string)];
}
function send_get_request($url, $headers) {
$ch = curl_init($url);
$h = [];
foreach ($headers as $k=>$v) $h[] = $k.": ".$v;
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => $h,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_TIMEOUT => 10,
]);
$body = curl_exec($ch);
$err = curl_errno($ch);
curl_close($ch);
if ($err) return null;
return $body;
}
function migu_encrypted_url($str) {
if (trim($str) === "") {
return "";
}
$parts = parse_url($str);
if ($parts === false || !isset($parts['query'])) {
return "";
}
parse_str($parts['query'], $q);
$S = isset($q['puData']) ? $q['puData'] : "";
$U = isset($q['userid']) ? $q['userid'] : "";
$T = isset($q['timestamp']) ? $q['timestamp'] : "";
$P = isset($q['ProgramID']) ? $q['ProgramID'] : "";
$C = isset($q['Channel_ID']) ? $q['Channel_ID'] : "";
$V = isset($q['playurlVersion']) ? $q['playurlVersion'] : "";
$sRunes = preg_split('//u', $S, -1, PREG_SPLIT_NO_EMPTY);
$N = count($sRunes);
$half = (int)(($N + 1) / 2);
$sb = "";
for ($i = 0; $i < $half; $i++) {
if ($N % 2 == 1 && $i == $half - 1) {
$sb .= $sRunes[$i];
break;
}
$sb .= $sRunes[$N - 1 - $i];
$sb .= $sRunes[$i];
switch ($i) {
case 1:
$uRunes = preg_split('//u', $U, -1, PREG_SPLIT_NO_EMPTY);
if (count($uRunes) > 2) {
$sb .= $uRunes[2];
} else {
$vRunes = preg_split('//u', $V, -1, PREG_SPLIT_NO_EMPTY);
if (count($vRunes) > 0) {
$sb .= mb_strtolower($vRunes[count($vRunes) - 1], 'UTF-8');
}
}
break;
case 2:
$tRunes = preg_split('//u', $T, -1, PREG_SPLIT_NO_EMPTY);
if (count($tRunes) > 6) {
$sb .= $tRunes[6];
} else {
$sb .= $sRunes[$i];
}
break;
case 3:
$pRunes = preg_split('//u', $P, -1, PREG_SPLIT_NO_EMPTY);
if (count($pRunes) > 2) {
$sb .= $pRunes[2];
} else {
$sb .= $sRunes[$i];
}
break;
case 4:
$cRunes = preg_split('//u', $C, -1, PREG_SPLIT_NO_EMPTY);
if (count($cRunes) >= 4) {
$sb .= $cRunes[count($cRunes) - 4];
} else {
$sb .= $sRunes[$i];
}
break;
}
}
$base = $str;
if (($idx = strpos($str, "?")) !== false) {
$base = substr($str, 0, $idx);
}
$dd = $sb;
$result = sprintf("%s?%s&ddCalcu=%s", $base, $parts['query'], $dd);
return $result;
}
function handle_migu_main_request($id) {
[$cached, $hit] = get_migu_cache($id);
if ($hit) return $cached;
$userId = "我按F12,粘贴代码获取到的userID";
$userToken = "我按F12,粘贴代码获取到的token";
[$tm, $saltSign] = get_sign_config($id);
$salt = $saltSign[0];
$sign = $saltSign[1];
$url = sprintf(
"https://play.miguvideo.com/playurl/v1/play/playurl?audio=false&contId=%s&dolby=true&multiViewN=2&h265=true&&os=13&ott=true&rateType=8&salt=%s&sign=%s×tamp=%s&ua=oneplus-13&vr=true",
$id, $salt, $sign, $tm
);
$headers = [
"Host" => "play.miguvideo.com",
"appId" => "miguvideo",
"terminalId" => "android",
"User-Agent" => "Dalvik/2.1.0+(Linux;+U;+Android+13;+oneplus-13+Build/TP1A.220624.014)",
"MG-BH" => "true",
"userToken" => $userToken,
"appVersion" => "2600037000",
"Phone-Info" => "oneplus-13|13",
"X-UP-CLIENT-CHANNEL-ID" => "2600037000-99000-200300220100002",
"userId" => $userId,
"APP-VERSION-CODE" => "260370016",
"Accept" => "*/*",
"Connection" => "keep-alive",
];
$body = send_get_request($url, $headers);
if ($body === null) return null;
$json = json_decode($body, true);
if (!is_array($json)) return null;
$rawUrl = "";
if (isset($json["body"]["urlInfo"]["url"])) $rawUrl = (string)$json["body"]["urlInfo"]["url"];
$ottUrl = migu_encrypted_url($rawUrl);
if (trim($ottUrl) === "") return null;
set_migu_cache($id, $ottUrl, 1800);
return $ottUrl;
}
$channel_list = [
'cctv1' => '608807420', //CCTV1综合
'cctv2' => '631780532', //CCTV2财*
'cctv3' => '624878271', //CCTV3综艺
'cctv4' => '631780421', //CCTV4中文国际
'cctv4a' => '608807416', //CCTV4美洲
'cctv4o' => '608807419', //CCTV4欧洲
'cctv5' => '641886683', //CCTV5体育
'cctv5p' => '641886773', //CCTV5+体育赛事
'cctv6' => '624878396', //CCTV6电影
'cctv7' => '673168121', //CCTV7国防军事
'cctv8' => '624878356', //CCTV8电视剧
'cctv9' => '673168140', //CCTV9纪录
(因为帖子字数限制,我删除了一些)
'xm6' => '608935797', //熊猫6
'xm7' => '609169286', //熊猫7
'xm8' => '609169287', //熊猫8
'xm9' => '609169226', //熊猫9
'xm10' => '609169285', //熊猫10
];
$default_channel = 'cctv1';
// 列表查询功能
if (isset($_GET['list'])) {
header('Content-Type: text/html; charset=utf-8');
echo "<!DOCTYPE html><html><head><meta charset='utf-8'><title>频道列表</title></head><body>";
echo "<h3>可用频道列表</h3>";
echo "<p>使用方法: migu.php?id=频道名称</p>";
echo "<table border='1' cellpadding='8'>";
echo "<tr><th>频道名称</th><th>节目ID</th><th>访问链接</th></tr>";
foreach ($channel_list as $key => $value) {
echo "<tr>";
echo "<td>$key</td>";
echo "<td>$value</td>";
echo "<td><a href='?id=$key'>migu.php?id=$key</a></td>";
echo "</tr>";
}
echo "</table>";
echo "</body></html>";
exit;
}
// 主功能:获取播放地址
if (isset($_GET['id']) && !empty($_GET['id'])) {
$input_id = (string)$_GET['id'];
if (isset($channel_list[$input_id])) {
$id = $channel_list[$input_id];
} else {
$id = $input_id;
}
} else {
$id = $channel_list[$default_channel];
}
$res = handle_migu_main_request($id);
if ($res) {
header('location:' . $res);
} else {
header('Content-Type: text/plain; charset=utf-8');
echo "无法获取播放地址,请检查ID是否正确";
}
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》以上代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|