内蒙古电视台代理,js代码
内蒙古电视台代理,js代码书写的。加密形式是:XXTEA加密算法。大神帮我看下它的加密形式如何用php代码来书写,谢谢了。<script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="xxtea.js"></script>
<script>
var idParam = location.href.split('?id=');
if (idParam.length > 1) {var id = idParam.split('&');} else {var id = 'nmgws';}
var channel = [];
channel['nmgws'] = 125; //古内蒙古卫视
channel['nmgmyws'] = 126; //内蒙古蒙古语卫视
channel['nmgxwzh'] = 127; //内蒙古新闻综合
channel['nmgjjsh'] = 128; //内蒙古经济生活
channel['nmgse'] = 129; //内蒙古少儿频道
channel['nmgwtyl'] = 130; //内蒙古文体娱乐
channel['nmgnm'] = 131; //内蒙古农牧频道
channel['nmgmgwh'] = 132; //内蒙古蒙古语文化
var parms = {
"size": 100,
"type": 1
};
var encrydata = XXTEA.encryptToString(JSON.stringify(parms), "5b28bae827e651b3");
var url = 'https://api-bt.nmtv.cn/broadcast/list';
$.ajax({
contentType: "application/json",
type: 'POST',
url: url,
data: encrydata,
success: function(res) {
var shuju = XXTEA.decryptToString(res, "5b28bae827e651b3");
var obj = JSON.parse(shuju);
var json = (obj.data);
var cid = channel;
for (var Index in json) {
var pid = json.data.id;
if (pid == cid) {
var m3u8 = json.data.streamUrl;
//console.log(m3u8);
location.href = m3u8;
}
}
}
});
</script>
本帖最后由 guoma 于 2024-7-2 21:51 编辑
<?php
error_reporting(0);
$id = isset($_GET['id'])?$_GET['id']:'nmws';
$n = [
'nmws' => 125, //古内蒙古卫视
'nmmyws' => 126, //内蒙古蒙古语卫视
'nmxwzh' => 127, //内蒙古新闻综合
'nmjjsh' => 128, //内蒙古经济生活
'nmse' => 129, //内蒙古少儿频道
'nmwtyl' => 130, //内蒙古文体娱乐
'nmnm' => 131, //内蒙古农牧频道
'nmwh' => 132, //内蒙古蒙古语文化
];
$ch = curl_init('https://api-bt.nmtv.cn/broadcast/list?size=100&type=1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$res = curl_exec($ch);
curl_close($ch);
$res = str_replace('"','',$res);
$str = xxtea_decrypt(base64_decode($res), "5b28bae827e651b3");
$json = json_decode($str, 1);
foreach ($json['data'] as $v) {
if ($v['data']['id'] == $n[$id]) {
$m3u8 = $v['data']['streamUrl'];
header("Location: $m3u8");
//echo $m3u8;
exit;
}
}
function xxtea_encrypt($str, $key) {
if ($str == "") return "";
$v = str2long($str, true);
$k = str2long($key, false);
if (count($k) < 4) {
for ($i = count($k); $i < 4; $i++) {
$k[$i] = 0;
}
}
$n = count($v) - 1;
$z = $v[$n];
$y = $v;
$delta = 0x9E3779B9;
$q = floor(6 + 52 / ($n + 1));
$sum = 0;
while (0 < $q--) {
$sum = int32($sum + $delta);
$e = $sum >> 2 & 3;
for ($p = 0; $p < $n; $p++) {
$y = $v[$p + 1];
$mx = int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
$z = $v[$p] = int32($v[$p] + $mx);
}
$y = $v;
$mx = int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
$z = $v[$n] = int32($v[$n] + $mx);
}
return long2str($v, false);
}
function xxtea_decrypt($str, $key) {
if ($str == "") {
return "";
}
$v = str2long($str, false);
$k = str2long($key, false);
if (count($k) < 4) {
for ($i = count($k); $i < 4; $i++) {
$k[$i] = 0;
}
}
$n = count($v) - 1;
$z = $v[$n];
$y = $v;
$delta = 0x9E3779B9;
$q = floor(6 + 52 / ($n + 1));
$sum = int32($q * $delta);
while ($sum != 0) {
$e = $sum >> 2 & 3;
for ($p = $n; $p > 0; $p--) {
$z = $v[$p - 1];
$mx = int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
$y = $v[$p] = int32($v[$p] - $mx);
}
$z = $v[$n];
$mx = int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
$y = $v = int32($v - $mx);
$sum = int32($sum - $delta);
}
return long2str($v, true);
}
function int32($n) {
while ($n >= 2147483648) $n -= 4294967296;
while ($n <= -2147483649) $n += 4294967296;
return (int)$n;
}
function str2long($s, $w) {
$v = unpack("V*", $s. str_repeat("\0", (4 - strlen($s) % 4) & 3));
$v = array_values($v);
if ($w) {
$v = strlen($s);
}
return $v;
}
function long2str($v, $w) {
$len = count($v);
$n = ($len - 1) << 2;
if ($w) {
$m = $v[$len - 1];
if (($m < $n - 3) || ($m > $n))
return false;
$n = $m;
}
$s = array();
for ($i = 0; $i < $len; $i++) {
$s[$i] = pack("V", $v[$i]);
}
if ($w) {
return substr(join('', $s), 0, $n);
} else {
return join('', $s);
}
}
?>
这是加密所有函数:
(function (global) {
'use strict';
var arrayLikeObjectArgumentsEnabled = true;
try {
String.fromCharCode.apply(String, new Uint8Array());
}
catch (e) {
arrayLikeObjectArgumentsEnabled = false;
Object.defineProperty(Array.prototype, 'subarray', { value: Array.prototype.slice });
}
var DELTA = 0x9E3779B9;
function toUint8Array(v, includeLength) {
var length = v.length;
var n = length << 2;
if (includeLength) {
var m = v;
n -= 4;
if ((m < n - 3) || (m > n)) {
return null;
}
n = m;
}
var bytes = new Uint8Array(n);
for (var i = 0; i < n; ++i) {
bytes = v >> ((i & 3) << 3);
}
return bytes;
}
function toUint32Array(bytes, includeLength) {
var length = bytes.length;
var n = length >> 2;
if ((length & 3) !== 0) {
++n;
}
var v;
if (includeLength) {
v = new Uint32Array(n + 1);
v = length;
}
else {
v = new Uint32Array(n);
}
for (var i = 0; i < length; ++i) {
v |= bytes << ((i & 3) << 3);
}
return v;
}
function int32(i) {
return i & 0xFFFFFFFF;
}
function mx(sum, y, z, p, e, k) {
return ((z >>> 5 ^ y << 2) + (y >>> 3 ^ z << 4)) ^ ((sum ^ y) + (k ^ z));
}
function fixk(k) {
if (k.length < 16) {
var key = new Uint8Array(16);
key.set(k);
k = key;
}
return k;
}
function encryptUint32Array(v, k) {
var length = v.length;
var n = length - 1;
var y, z, sum, e, p, q;
z = v;
sum = 0;
for (q = Math.floor(6 + 52 / length) | 0; q > 0; --q) {
sum = int32(sum + DELTA);
e = sum >>> 2 & 3;
for (p = 0; p < n; ++p) {
y = v;
z = v = int32(v + mx(sum, y, z, p, e, k));
}
y = v;
z = v = int32(v + mx(sum, y, z, n, e, k));
}
return v;
}
function decryptUint32Array(v, k) {
var length = v.length;
var n = length - 1;
var y, z, sum, e, p, q;
y = v;
q = Math.floor(6 + 52 / length);
for (sum = int32(q * DELTA); sum !== 0; sum = int32(sum - DELTA)) {
e = sum >>> 2 & 3;
for (p = n; p > 0; --p) {
z = v;
y = v = int32(v - mx(sum, y, z, p, e, k));
}
z = v;
y = v = int32(v - mx(sum, y, z, 0, e, k));
}
return v;
}
function toBytes(str) {
var n = str.length;
// A single code unit uses at most 3 bytes.
// Two code units at most 4.
var bytes = new Uint8Array(n * 3);
var length = 0;
for (var i = 0; i < n; i++) {
var codeUnit = str.charCodeAt(i);
if (codeUnit < 0x80) {
bytes = codeUnit;
}
else if (codeUnit < 0x800) {
bytes = 0xC0 | (codeUnit >> 6);
bytes = 0x80 | (codeUnit & 0x3F);
}
else if (codeUnit < 0xD800 || codeUnit > 0xDFFF) {
bytes = 0xE0 | (codeUnit >> 12);
bytes = 0x80 | ((codeUnit >> 6) & 0x3F);
bytes = 0x80 | (codeUnit & 0x3F);
}
else {
if (i + 1 < n) {
var nextCodeUnit = str.charCodeAt(i + 1);
if (codeUnit < 0xDC00 && 0xDC00 <= nextCodeUnit && nextCodeUnit <= 0xDFFF) {
var rune = (((codeUnit & 0x03FF) << 10) | (nextCodeUnit & 0x03FF)) + 0x010000;
bytes = 0xF0 | (rune >> 18);
bytes = 0x80 | ((rune >> 12) & 0x3F);
bytes = 0x80 | ((rune >> 6) & 0x3F);
bytes = 0x80 | (rune & 0x3F);
i++;
continue;
}
}
throw new Error('Malformed string');
}
}
return bytes.subarray(0, length);
}
function toShortString(bytes, n) {
var charCodes = new Array(n);
var i = 0, off = 0;
for (var len = bytes.length; i < n && off < len; i++) {
var unit = bytes;
switch (unit >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
charCodes = unit;
break;
case 12:
case 13:
if (off < len) {
charCodes = ((unit & 0x1F) << 6) |
(bytes & 0x3F);
}
else {
throw new Error('Unfinished UTF-8 octet sequence');
}
break;
case 14:
if (off + 1 < len) {
charCodes = ((unit & 0x0F) << 12) |
((bytes & 0x3F) << 6) |
(bytes & 0x3F);
}
else {
throw new Error('Unfinished UTF-8 octet sequence');
}
break;
case 15:
if (off + 2 < len) {
var rune = (((unit & 0x07) << 18) |
((bytes & 0x3F) << 12) |
((bytes & 0x3F) << 6) |
(bytes & 0x3F)) - 0x10000;
if (0 <= rune && rune <= 0xFFFFF) {
charCodes = (((rune >> 10) & 0x03FF) | 0xD800);
charCodes = ((rune & 0x03FF) | 0xDC00);
}
else {
throw new Error('Character outside valid Unicode range: 0x' + rune.toString(16));
}
}
else {
throw new Error('Unfinished UTF-8 octet sequence');
}
break;
default:
throw new Error('Bad UTF-8 encoding 0x' + unit.toString(16));
}
}
if (i < n) {
charCodes.length = i;
}
return String.fromCharCode.apply(String, charCodes);
}
function toLongString(bytes, n) {
var buf = [];
var charCodes = new Array(0x8000);
var i = 0, off = 0;
for (var len = bytes.length; i < n && off < len; i++) {
var unit = bytes;
switch (unit >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
charCodes = unit;
break;
case 12:
case 13:
if (off < len) {
charCodes = ((unit & 0x1F) << 6) |
(bytes & 0x3F);
}
else {
throw new Error('Unfinished UTF-8 octet sequence');
}
break;
case 14:
if (off + 1 < len) {
charCodes = ((unit & 0x0F) << 12) |
((bytes & 0x3F) << 6) |
(bytes & 0x3F);
}
else {
throw new Error('Unfinished UTF-8 octet sequence');
}
break;
case 15:
if (off + 2 < len) {
var rune = (((unit & 0x07) << 18) |
((bytes & 0x3F) << 12) |
((bytes & 0x3F) << 6) |
(bytes & 0x3F)) - 0x10000;
if (0 <= rune && rune <= 0xFFFFF) {
charCodes = (((rune >> 10) & 0x03FF) | 0xD800);
charCodes = ((rune & 0x03FF) | 0xDC00);
}
else {
throw new Error('Character outside valid Unicode range: 0x' + rune.toString(16));
}
}
else {
throw new Error('Unfinished UTF-8 octet sequence');
}
break;
default:
throw new Error('Bad UTF-8 encoding 0x' + unit.toString(16));
}
if (i >= 0x7FFF - 1) {
var size = i + 1;
charCodes.length = size;
buf.push(String.fromCharCode.apply(String, charCodes));
n -= size;
i = -1;
}
}
if (i > 0) {
charCodes.length = i;
buf.push(String.fromCharCode.apply(String, charCodes));
}
return buf.join('');
}
function toString(bytes) {
if (!bytes) return '密钥错误';
var n = bytes.length;
if (n === 0) return '';
return ((n < 0x7FFF) ?
toShortString(bytes, n) :
toLongString(bytes, n));
}
function toArray(bytes) {
var n = bytes.length;
var a = new Array(bytes.length);
for (var i = 0; i < n; ++i) {
a = bytes;
}
return a;
}
function toAsciiString(bytes) {
var n = bytes.length;
if (n === 0) return '';
var charCodes = (arrayLikeObjectArgumentsEnabled ? bytes : toArray(bytes));
if (n < 0xFFFF) {
return String.fromCharCode.apply(String, charCodes);
}
var remain = n & 0x7FFF;
var count = n >> 15;
var a = new Array(remain ? count + 1 : count);
for (var i = 0; i < count; ++i) {
a = String.fromCharCode.apply(String, charCodes.subarray(i << 15, (i + 1) << 15));
}
if (remain) {
a = String.fromCharCode.apply(String, charCodes.subarray(count << 15, n));
}
return a.join('');
}
function base64ToBytes(base64) {
var s = window.atob(base64);
var n = s.length;
var bytes = new Uint8Array(n);
for (var i = 0; i < n; i++) {
bytes = s.charCodeAt(i);
}
return bytes;
}
function encrypt(data, key) {
if (typeof data === 'string') data = toBytes(data);
if (typeof key === 'string') key = toBytes(key);
if (data === undefined || data === null || data.length === 0) {
return data;
}
return toUint8Array(encryptUint32Array(toUint32Array(data, true), toUint32Array(fixk(key), false)), false);
}
function encryptToString(data, key) {
return window.btoa(toAsciiString(encrypt(data, key)));
}
function decrypt(data, key) {
if (typeof data === 'string') data = base64ToBytes(data);
if (typeof key === 'string') key = toBytes(key);
if (data === undefined || data === null || data.length === 0) {
return data;
}
return toUint8Array(decryptUint32Array(toUint32Array(data, false), toUint32Array(fixk(key), false)), true);
}
function decryptToString(data, key) {
return toString(decrypt(data, key));
}
global.XXTEA = Object.create(null, {
toBytes: { value: toBytes },
toString: { value: toString },
encrypt: { value: encrypt },
encryptToString: { value: encryptToString },
decrypt: { value: decrypt },
decryptToString: { value: decryptToString }
});
})(this || ('this'));
眼睛都看花了。。。 关键是静态,没什么意义,反而吉林省台有点意思
qqincai 发表于 2024-6-24 22:34
关键是静态,没什么意义,反而吉林省台有点意思
吉林省台js代码我发隔壁了,你帮我看下。如何改成php代码形式 jiaerfeng 发表于 2024-6-25 00:06
吉林省台js代码我发隔壁了,你帮我看下。如何改成php代码形式
吉林台照此套。
页:
[1]