mirror of
https://github.com/MeoProject/lx-music-api-server.git
synced 2025-07-06 22:42:14 +08:00
feat: 增加kg token报活
This commit is contained in:
@ -6,10 +6,12 @@
|
||||
# - license: MIT -
|
||||
# ----------------------------------------
|
||||
# This file is part of the "lx-music-api-server" project.
|
||||
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto.Util.Padding import pad
|
||||
from common import utils
|
||||
from common import config
|
||||
from common import Httpx
|
||||
import json
|
||||
|
||||
createObject = utils.CreateObject
|
||||
|
||||
@ -23,6 +25,7 @@ tools = createObject({
|
||||
"version": config.read_config("module.kg.tracker.version"),
|
||||
"extra_params": config.read_config("module.kg.tracker.extra_params"),
|
||||
"appid": config.read_config("module.kg.client.appid"),
|
||||
'mid': config.read_config('module.kg.user.mid'),
|
||||
"pid": config.read_config("module.kg.client.pid"),
|
||||
'qualityHashMap': {
|
||||
'128k': 'hash_128',
|
||||
@ -49,14 +52,21 @@ def buildRequestParams(dictionary: dict):
|
||||
return joined_str
|
||||
|
||||
def sign(params, body = "", signkey = tools["signkey"]):
|
||||
if (isinstance(body, dict)):
|
||||
body = json.dumps(body)
|
||||
params = utils.sortDict(params)
|
||||
params = buildSignatureParams(params, body)
|
||||
return utils.createMD5(signkey + params + signkey)
|
||||
|
||||
async def signRequest(url, params, options, signkey = tools["signkey"]):
|
||||
params['signature'] = sign(params, options.get("body") if options.get("body") else (options.get("data") if options.get("data") else ""), signkey)
|
||||
params['signature'] = sign(params, options.get("body") if options.get("body") else (options.get("data") if options.get("data") else (options.get("json") if options.get("json") else "")), signkey)
|
||||
url = url + "?" + buildRequestParams(params)
|
||||
return await Httpx.AsyncRequest(url, options)
|
||||
|
||||
def getKey(hash_, user_info):
|
||||
return utils.createMD5(hash_.lower() + tools.pidversec + tools.appid + user_info['mid'] + user_info['userid'])
|
||||
|
||||
def aes_sign(plain_text, key=b'90b8382a1bb4ccdcf063102053fd75b8', iv=b'f063102053fd75b8'):
|
||||
cipher = AES.new(key, AES.MODE_CBC, iv)
|
||||
crypto = cipher.encrypt(pad(plain_text.encode(), AES.block_size))
|
||||
return crypto.hex()
|
||||
|
Reference in New Issue
Block a user