A-A+

最新QQ 音乐 (y.qq.com) 请求签名算法 python脚本

2024年10月10日 14:43 汪洋大海 暂无评论 共978字 (阅读51 views次)
#!/usr/bin/env python3

import sys
import re

from hashlib import sha1
from base64 import b64encode

PART_1_INDEXES = [23, 14, 6, 36, 16, 40, 7, 19]
PART_2_INDEXES = [16, 1, 32, 12, 19, 27, 8, 5]
SCRAMBLE_VALUES = [89, 39, 179, 150, 218, 82, 58, 252, 177,
                   52, 186, 123, 120, 64, 242, 133, 143, 161, 121, 179]

# JavaScript quirks emulation
PART_1_INDEXES = filter(lambda x: x < 40, PART_1_INDEXES)


def zzc_sign(payload: str) -> str:
    hash = sha1(payload.encode('utf-8')).hexdigest().upper()

    part1 = ''.join(map(lambda i: hash[i], PART_1_INDEXES))
    part2 = ''.join(map(lambda i: hash[i], PART_2_INDEXES))

    part3 = bytearray(20)
    for (i, v) in enumerate(SCRAMBLE_VALUES):
        value = v ^ int(hash[i*2:i*2+2], 16)
        part3[i] = value
    b64_part = re.sub(rb'[\\/+=]', b'', b64encode(part3)).decode('utf-8')
    return f'zzc{part1}{b64_part}{part2}'.lower()


def main(payload: str) -> str:
    sign = zzc_sign(payload)
    print(f"sign={sign} (len={len(sign)})")


if __name__ == "__main__":
    main(sys.argv[1])

使用方法

$ ./zzc_sign.py 123
sign=zzcec1b555gzqzg7laztguyjl2bu20r6x1w50c55f60 (len=43)

文章来源:https://github.com/jixunmoe/qmweb-sign/tree/v1.0.4

布施恩德可便相知重

微信扫一扫打赏

支付宝扫一扫打赏

×

给我留言