|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
版本2,上一个主题的ID是一样的。- <?php
- $CACHE_DIR = __DIR__ . '/cache';
- if (!is_dir($CACHE_DIR)) {
- mkdir($CACHE_DIR, 0777, true);
- }
- function md5_str($str) {
- return md5($str);
- }
- function randomInt($min, $max) {
- return random_int($min, $max);
- }
- function getCachePath($key) {
- global $CACHE_DIR;
- $filename = 'migu_cache_' . md5_str($key) . '.json';
- return $CACHE_DIR . DIRECTORY_SEPARATOR . $filename;
- }
- function getMiguCache($key) {
- $p = getCachePath($key);
- if (!file_exists($p)) {
- return ['url' => null, 'hit' => false];
- }
- try {
- $content = file_get_contents($p);
- $d = json_decode($content, true);
- if (!$d) {
- return ['url' => null, 'hit' => false];
- }
- $nowSeconds = time();
- if ($nowSeconds - intval($d['time']) > intval($d['ttl'])) {
- @unlink($p);
- return ['url' => null, 'hit' => false];
- }
- return ['url' => $d['url'], 'hit' => true];
- } catch (Throwable $e) {
- return ['url' => null, 'hit' => false];
- }
- }
- function setMiguCache($key, $url, $ttlSeconds) {
- $p = getCachePath($key);
- $data = [
- 'url' => $url,
- 'time' => time(),
- 'ttl' => $ttlSeconds
- ];
- try {
- file_put_contents($p, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
- } catch (Throwable $e) {
- error_log("Cache write error: " . $e->getMessage());
- }
- }
- function getSignConfig($contId) {
- $appVersion = '2600033500';
- $saltValue = '16d4328df21a4138859388418bd252c2';
- $timestampMs = (string) round(microtime(true) * 1000);
- $ver8 = substr($appVersion, 0, 8);
- $md5string = md5_str($timestampMs . $contId . $ver8);
- $prefix = randomInt(0, 999999);
- $salt = str_pad((string)$prefix, 6, '0', STR_PAD_LEFT) . '80';
- $text = $md5string . $saltValue . 'migu' . substr($salt, 0, 4);
- $sign = md5_str($text);
- return ['timestampMs' => $timestampMs, 'salt' => $salt, 'sign' => $sign];
- }
- function miguEncryptedUrl($rawUrl) {
- $factorOfEncryption = [8, 3, 7, 6, 6];
- $parsed = parse_url($rawUrl);
- if ($parsed === false || !isset($parsed['query'])) {
- return $rawUrl;
- }
- parse_str($parsed['query'], $params);
- $puData = isset($params['puData']) ? (string)$params['puData'] : '';
- if ($puData === '') {
- return $rawUrl;
- }
- $ddCalcuExists = array_key_exists('ddCalcu', $params) && $params['ddCalcu'] !== '';
- if (!$ddCalcuExists) {
- $userid = isset($params['userid']) ? (string)$params['userid'] : 'eeeeeeeee';
- $timestamp = isset($params['timestamp']) ? (string)$params['timestamp'] : 'tttttttttttttt';
- $programId = isset($params['ProgramID']) ? (string)$params['ProgramID'] : 'ccccccccc';
- $channelId = isset($params['Channel_ID']) ? (string)$params['Channel_ID'] : 'nnnnnnnnnnnnnnnn';
- $useridChars = preg_split('//u', $userid, -1, PREG_SPLIT_NO_EMPTY);
- $timestampChars = preg_split('//u', $timestamp, -1, PREG_SPLIT_NO_EMPTY);
- $programIdChars = preg_split('//u', $programId, -1, PREG_SPLIT_NO_EMPTY);
- $channelIdChars = preg_split('//u', $channelId, -1, PREG_SPLIT_NO_EMPTY);
- $ddCalcu = '';
- $puLen = strlen($puData);
- $halfLen = intdiv($puLen, 2);
- for ($i = 0; $i < $halfLen; $i++) {
- $ddCalcu .= $puData[$puLen - 1 - $i];
- $ddCalcu .= $puData[$i];
- $charToEncrypt = '';
- if ($i === 1) {
- $idx = $factorOfEncryption[0] - 1;
- $charToEncrypt = isset($useridChars[$idx]) ? $useridChars[$idx] : 'e';
- } elseif ($i === 2) {
- $idx = $factorOfEncryption[1] - 1;
- $charToEncrypt = isset($timestampChars[$idx]) ? $timestampChars[$idx] : 't';
- } elseif ($i === 3) {
- $idx = $factorOfEncryption[2] - 1;
- $charToEncrypt = isset($programIdChars[$idx]) ? $programIdChars[$idx] : 'c';
- } elseif ($i === 4) {
- $idx = $factorOfEncryption[3] - 1;
- $charToEncrypt = isset($channelIdChars[$idx]) ? $channelIdChars[$idx] : 'n';
- }
- if ($charToEncrypt !== '') {
- $codePoint = function_exists('mb_ord') ? mb_ord($charToEncrypt, 'UTF-8') : ord($charToEncrypt);
- $encryptedVal = $codePoint ^ $factorOfEncryption[4];
- $encryptedVal %= 26;
- $encryptedVal += 97;
- $ddCalcu .= chr($encryptedVal);
- }
- }
- if ($puLen % 2 === 1) {
- $ddCalcu .= $puData[$halfLen];
- }
- $params['ddCalcu'] = $ddCalcu;
- }
- if (!isset($params['sv'])) {
- $params['sv'] = '10004';
- }
- if (!isset($params['ct'])) {
- $params['ct'] = 'android';
- }
- $parsed['query'] = http_build_query($params, '', '&', PHP_QUERY_RFC3986);
- $url = '';
- if (isset($parsed['scheme'])) $url .= $parsed['scheme'] . '://';
- if (isset($parsed['user'])) {
- $url .= $parsed['user'];
- if (isset($parsed['pass'])) $url .= ':' . $parsed['pass'];
- $url .= '@';
- }
- if (isset($parsed['host'])) $url .= $parsed['host'];
- if (isset($parsed['port'])) $url .= ':' . $parsed['port'];
- if (isset($parsed['path'])) $url .= $parsed['path'];
- if (isset($parsed['query']) && $parsed['query'] !== '') $url .= '?' . $parsed['query'];
- if (isset($parsed['fragment'])) $url .= '#' . $parsed['fragment'];
- return $url;
- }
- function handleMiguMainRequest($id) {
- $cached = getMiguCache($id);
- if ($cached['hit']) {
- return $cached['url'];
- }
- $signConfig = getSignConfig($id);
- $timestampMs = $signConfig['timestampMs'];
- $salt = $signConfig['salt'];
- $sign = $signConfig['sign'];
- $apiUrl = 'https://play.miguvideo.com/playurl/v1/play/playurl?contId=' . rawurlencode($id)
- . '&dolby=true&isMultiView=true&xh265=true&os=13&ott=false&rateType=3&salt=' . rawurlencode($salt)
- . '&sign=' . rawurlencode($sign)
- . '×tamp=' . rawurlencode($timestampMs)
- . '&ua=oneplus-12&vr=true';
- $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',
- 'appVersionName: 6.3.35',
- 'appVersion: 2600033500',
- 'Phone-Info: oneplus-13|13',
- 'X-UP-CLIENT-CHANNEL-ID: 2600033500-99000-201600010010028',
- 'APP-VERSION-CODE: 260335005',
- 'Accept: */*',
- 'Connection: keep-alive',
- ];
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $apiUrl);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- $response = curl_exec($ch);
- if ($response === false) {
- error_log('API Request Error: ' . curl_error($ch));
- curl_close($ch);
- return null;
- }
- curl_close($ch);
- $json = json_decode($response, true);
- $rawUrl = '';
- if (isset($json['body']['urlInfo']['url'])) {
- $rawUrl = $json['body']['urlInfo']['url'];
- }
- if (!$rawUrl) {
- return null;
- }
- $ottUrl = miguEncryptedUrl($rawUrl);
- if (!$ottUrl || trim($ottUrl) === '') {
- return null;
- }
- setMiguCache($id, $ottUrl, 1800);
- return $ottUrl;
- }
- $id = isset($_GET['id']) ? $_GET['id'] : '608807420';
- $finalUrl = handleMiguMainRequest($id);
- if ($finalUrl) {
- header('Location: ' . $finalUrl, true, 302);
- exit;
- }
- http_response_code(500);
- echo 'Failed to retrieve or encrypt URL.';
复制代码
|
|