mirror of
https://github.com/MeoProject/lx-music-api-server.git
synced 2025-05-23 19:17:41 +08:00
feat: zzc sign
This commit is contained in:
parent
0677c0b5ad
commit
3fb2718cdf
@ -1,104 +1,55 @@
|
|||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# - mode: python -
|
# - mode: python -
|
||||||
# - author: helloplhm-qwq -
|
# - author: jixunmoe -
|
||||||
# - name: QMWSign.py -
|
# - name: zzc_sign.py -
|
||||||
# - project: lx-music-api-server -
|
# - project: qmweb-sign -
|
||||||
# - license: MIT -
|
# - license: MIT -
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# This file is part of the "lx-music-api-server" project.
|
# This file is part of the "qmweb-sign" project.
|
||||||
|
|
||||||
from common.utils import createMD5
|
import sys
|
||||||
import re as _re
|
import re
|
||||||
|
|
||||||
def v(b):
|
from hashlib import sha1
|
||||||
res = []
|
from base64 import b64encode
|
||||||
p = [21, 4, 9, 26, 16, 20, 27, 30]
|
|
||||||
for x in p:
|
|
||||||
res.append(b[x])
|
|
||||||
return ''.join(res)
|
|
||||||
|
|
||||||
def c(b):
|
PART_1_INDEXES = [23, 14, 6, 36, 16, 40, 7, 19]
|
||||||
res = []
|
PART_2_INDEXES = [16, 1, 32, 12, 19, 27, 8, 5]
|
||||||
p = [18, 11, 3, 2, 1, 7, 6, 25]
|
SCRAMBLE_VALUES = [
|
||||||
for x in p:
|
89,
|
||||||
res.append(b[x])
|
39,
|
||||||
return ''.join(res)
|
179,
|
||||||
|
150,
|
||||||
|
218,
|
||||||
|
82,
|
||||||
|
58,
|
||||||
|
252,
|
||||||
|
177,
|
||||||
|
52,
|
||||||
|
186,
|
||||||
|
123,
|
||||||
|
120,
|
||||||
|
64,
|
||||||
|
242,
|
||||||
|
133,
|
||||||
|
143,
|
||||||
|
161,
|
||||||
|
121,
|
||||||
|
179,
|
||||||
|
]
|
||||||
|
|
||||||
def y(a, b, c):
|
PART_1_INDEXES = filter(lambda x: x < 40, PART_1_INDEXES)
|
||||||
e = []
|
|
||||||
r25 = a >> 2
|
|
||||||
if b is not None and c is not None:
|
|
||||||
r26 = a & 3
|
|
||||||
r26_2 = r26 << 4
|
|
||||||
r26_3 = b >> 4
|
|
||||||
r26_4 = r26_2 | r26_3
|
|
||||||
r27 = b & 15
|
|
||||||
r27_2 = r27 << 2
|
|
||||||
r27_3 = r27_2 | (c >> 6)
|
|
||||||
r28 = c & 63
|
|
||||||
e.append(r25)
|
|
||||||
e.append(r26_4)
|
|
||||||
e.append(r27_3)
|
|
||||||
e.append(r28)
|
|
||||||
else:
|
|
||||||
r10 = a >> 2
|
|
||||||
r11 = a & 3
|
|
||||||
r11_2 = r11 << 4
|
|
||||||
e.append(r10)
|
|
||||||
e.append(r11_2)
|
|
||||||
return e
|
|
||||||
|
|
||||||
def n(ls):
|
|
||||||
e = []
|
|
||||||
for i in range(0, len(ls), 3):
|
|
||||||
if i < len(ls) - 2:
|
|
||||||
e += y(ls[i], ls[i + 1], ls[i + 2])
|
|
||||||
else:
|
|
||||||
e += y(ls[i], None, None)
|
|
||||||
res = []
|
|
||||||
b64all = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
|
||||||
for i in e:
|
|
||||||
res.append(b64all[i])
|
|
||||||
return ''.join(res)
|
|
||||||
|
|
||||||
def t(b):
|
def sign(payload: str) -> str:
|
||||||
zd = {
|
hash = sha1(payload.encode("utf-8")).hexdigest().upper()
|
||||||
"0": 0,
|
|
||||||
"1": 1,
|
|
||||||
"2": 2,
|
|
||||||
"3": 3,
|
|
||||||
"4": 4,
|
|
||||||
"5": 5,
|
|
||||||
"6": 6,
|
|
||||||
"7": 7,
|
|
||||||
"8": 8,
|
|
||||||
"9": 9,
|
|
||||||
"A": 10,
|
|
||||||
"B": 11,
|
|
||||||
"C": 12,
|
|
||||||
"D": 13,
|
|
||||||
"E": 14,
|
|
||||||
"F": 15
|
|
||||||
}
|
|
||||||
ol = [212, 45, 80, 68, 195, 163, 163, 203, 157, 220, 254, 91, 204, 79, 104, 6]
|
|
||||||
res = []
|
|
||||||
j = 0
|
|
||||||
for i in range(0, len(b), 2):
|
|
||||||
one = zd[b[i]]
|
|
||||||
two = zd[b[i + 1]]
|
|
||||||
r = one * 16 ^ two
|
|
||||||
res.append(r ^ ol[j])
|
|
||||||
j += 1
|
|
||||||
return res
|
|
||||||
|
|
||||||
def sign(params):
|
part1 = "".join(map(lambda i: hash[i], PART_1_INDEXES))
|
||||||
md5Str = createMD5(params).upper()
|
part2 = "".join(map(lambda i: hash[i], PART_2_INDEXES))
|
||||||
h = v(md5Str)
|
|
||||||
e = c(md5Str)
|
part3 = bytearray(20)
|
||||||
ls = t(md5Str)
|
for i, v in enumerate(SCRAMBLE_VALUES):
|
||||||
m = n(ls)
|
value = v ^ int(hash[i * 2 : i * 2 + 2], 16)
|
||||||
res = 'zzb' + h + m + e
|
part3[i] = value
|
||||||
res = res.lower()
|
b64_part = re.sub(rb"[\\/+=]", b"", b64encode(part3)).decode("utf-8")
|
||||||
r = _re.compile(r'[\\/+]')
|
return f"zzc{part1}{b64_part}{part2}".lower()
|
||||||
res = _re.sub(r, '', res)
|
|
||||||
return res
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
# This file is part of the "lx-music-api-server" project.
|
# This file is part of the "lx-music-api-server" project.
|
||||||
|
|
||||||
from common.exceptions import FailedException
|
from common.exceptions import FailedException
|
||||||
from common import config, utils, variable, Httpx
|
from common import config, utils, variable
|
||||||
from .musicInfo import getMusicInfo
|
from .musicInfo import getMusicInfo
|
||||||
from .utils import tools
|
from .utils import tools
|
||||||
from .utils import signRequest
|
from .utils import signRequest
|
||||||
|
Loading…
x
Reference in New Issue
Block a user