|
|
发表于 2025-11-6 15:34:08
|
显示全部楼层
- <?php
- $channelId = $_GET['id'] ?? 'szdsj';
- $channelMap = [
- 'szws4k' => 'R77mK1v', // Shenzhen Satellite TV 4K
- 'szws' => 'AxeFRth', // Shenzhen Satellite TV
- 'szds' => 'ZwxzUXr', // Urban Channel
- 'szdsj' => '4azbkoY', // TV Drama Channel
- 'szgg' => '2q76Sw2', // Public Channel
- 'szcj' => '3vlcoxP', // Finance Channel
- 'szyl' => '1q4iPng', // Entertainment Channel
- 'szse' => '1SIQj6s', // Children's Channel
- 'szyd' => 'wDF6KJ3', // Mobile TV
- 'szyh' => 'BJ5u5k2', // E-Shopping Channel
- 'szgj' => 'sztvgjpd', // International Channel
- ];
- $baseUrl = "https://sztv-hls.sztv.com.cn";
- $secretKey = "bf9b2cab35a9c38857b82aabf99874aa96b9ffbb";
- $expiryTime = dechex(time() + 7200);
- $bitrate = "500";
- if (!isset($channelMap[$channelId])) {
- $channelId = 'szdsj';
- }
- $streamPath = '/' . $channelMap[$channelId] . '/' . $bitrate . '/' .
- generateStreamToken($channelMap[$channelId]) . '.m3u8';
- $authSignature = md5($secretKey . $streamPath . $expiryTime);
- $streamUrl = $baseUrl . $streamPath . "?sign={$authSignature}&t={$expiryTime}";
- header("Location: $streamUrl");
- function generateStreamToken($channelCode) {
- $baseTimestamp = strtotime('today') * 1000;
- $sum1 = 0;
- $sum2 = 0;
- $prevChar = -1;
-
- foreach (str_split($channelCode) as $currentChar) {
- $charValue = ord($currentChar);
- $sum1 += $charValue;
-
- if ($prevChar != -1) {
- $sum2 += ($prevChar - $charValue);
- }
-
- $prevChar = $charValue;
- }
-
- $combinedSum = $sum1 + $sum2;
- $sumBase36 = base_convert($combinedSum, 10, 36);
- $timeBase36 = base_convert($baseTimestamp, 10, 36);
-
- $timeSum = array_sum(array_map('ord', str_split($timeBase36)));
- $timeReordered = substr($timeBase36, 5) . substr($timeBase36, 0, 5);
-
- $difference = abs($timeSum - $combinedSum);
- $mixedString = strrev($sumBase36) . $timeReordered;
-
- $prefix = substr($mixedString, 0, 4);
- $suffix = substr($mixedString, 4);
-
- $dayParity = date('w') % 2;
- $tokenParts = [];
-
- foreach (str_split($channelCode) as $index => $char) {
- if ($index % 2 == $dayParity) {
- $tokenParts[] = $mixedString[$index % strlen($mixedString)];
- } else {
- $prevIndex = $index - 1;
- if ($prevIndex >= 0) {
- $prevChannelChar = $channelCode[$prevIndex];
- $posInPrefix = strpos($prefix, $prevChannelChar);
- $tokenParts[] = ($posInPrefix === false) ? $prevChannelChar : $suffix[$posInPrefix];
- } else {
- $tokenParts[] = $prefix[$index % strlen($prefix)];
- }
- }
- }
-
- $differenceBase36 = strrev(base_convert($difference, 10, 36));
- $finalToken = $differenceBase36 . implode('', $tokenParts);
-
- return substr($finalToken, 0, strlen($channelCode));
- }
- ?>
复制代码 |
|