Compare commits

..

No commits in common. "8a91b15fea967238e58ac374b3283ce3bb6e3c87" and "c042d95636f34874ab6894f11948c6ab8150b0c6" have entirely different histories.

6 changed files with 22 additions and 37 deletions

View File

@ -35,12 +35,9 @@ class AESPKCS7:
self.iv = iv.encode('utf-8')
self.mode = AES.MODE_CBC
# 加密
def encrypt(self, content) -> bytes:
# if content is str, convert to bytes
if isinstance(content, str):
encodedData = content.encode('utf-8')
def encrypt(self, content: bytes) -> bytes:
cipher = AES.new(self.key, self.mode, self.iv)
content_padded = pad(encodedData, AES.block_size)
content_padded = pad(content, AES.block_size)
encrypted_bytes = cipher.encrypt(content_padded)
return encrypted_bytes
# 解密
@ -111,7 +108,7 @@ def apiSDGB(data:str, targetApi:str, userAgentExtraData:str, noLog:bool=False, t
logger.warning(f"无法解压,得到的原始响应: {responseRAWContent}")
raise SDGBResponseError("解压失败")
try:
resultResponse = aes.decrypt(responseDecompressed)
resultResponse = unpad(aes.decrypt(responseDecompressed), 16).decode()
logger.debug(f"成功解密响应!")
except:
logger.warning(f"解密失败,得到的原始响应: {responseDecompressed}")

View File

@ -140,7 +140,7 @@ def generateLoginBonusList(UserLoginBonusList, generateMode=1):
}
bonusList.append(data)
else:
raise SyntaxError("generateMode は 1 または 2 でなければなりません")
raise ValueError("generateMode は 1 または 2 でなければなりません")
logger.debug(f"ログインボーナスリスト: {bonusList}")
return bonusList

View File

@ -5,11 +5,7 @@ from datetime import datetime, timedelta
from Config import *
from API_TitleServer import apiSDGB
from HelperGetUserThing import implGetUser_
from loguru import logger
from HelperLogInOut import apiLogin, apiLogout, generateTimestamp
from HelperGetUserThing import apiGetUserData
def apiQueryTicket(userId:int) -> str:
'''查询已有票的 API 请求器,返回 Json String。'''
@ -54,7 +50,7 @@ def implBuyTicket(userId:int, ticketType:int):
返回服务器响应的 Json string
'''
# 先使用 GetUserData API 请求器,取得 rating 和 pc 数
currentUserData = implGetUser_("Data", userId)
currentUserData = json.loads(apiGetUserData(userId))
if currentUserData:
playerRating = currentUserData['userData']['playerRating']
playCount = currentUserData['userData'].get('playCount', 0)
@ -67,15 +63,7 @@ def implBuyTicket(userId:int, ticketType:int):
if __name__ == "__main__":
userId = testUid2
currentLoginTimestamp = generateTimestamp()
loginResult = apiLogin(currentLoginTimestamp, userId)
ticketType = 3
if loginResult['returnCode'] != 1:
logger.info("登录失败")
exit()
try:
logger.info(implBuyTicket(userId, 2))
logger.info(apiLogout(currentLoginTimestamp, userId))
finally:
logger.info(apiLogout(currentLoginTimestamp, userId))
#logger.warning("Error")
print(implBuyTicket(userId, ticketType))
print(apiQueryTicket(userId))

View File

@ -12,10 +12,9 @@ def implGetUser_(thing:str, userId:int, noLog=False) -> dict:
# 返回 Dict
return userthingDict
# 已弃用
#def apiGetUserData(userId:int) -> str:
# """Now aka of implGetUser_(Data)"""
# return implGetUser_("Data", userId)
def apiGetUserData(userId:int) -> str:
"""Now aka of implGetUser_(Data)"""
return implGetUser_("Data", userId)
def apiGetUserThing(userId:int, thing:str, noLog=False) -> str:
"""获取用户数据的 API 请求器,返回 Json String"""

View File

@ -8,13 +8,14 @@ import zlib
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad, pad
# 密钥和 IV
# CN 2024
AES_KEY_SDGB_1_40 = "n7bx6:@Fg_:2;5E89Phy7AyIcpxEQ:R@"
AES_IV_SDGB_1_40 = ";;KjR1C3hgB1ovXa"
aesKey2024 = "n7bx6:@Fg_:2;5E89Phy7AyIcpxEQ:R@"
aesIV2024 = ";;KjR1C3hgB1ovXa"
# 国际服 PRiSM
AES_KEY_SDGA_1_50 = "A;mv5YUpHBK3YxTy5KB^[;5]C2AL50Bq"
AES_IV_SDGA_1_50 = "9FM:sd9xA91X14v]"
aesKeyPrism = "A;mv5YUpHBK3YxTy5KB^[;5]C2AL50Bq"
aesIVPrism = "9FM:sd9xA91X14v]"
class AESPKCS7:
# 实现了 maimai 通讯所用的 AES 加密的类
@ -23,9 +24,9 @@ class AESPKCS7:
self.iv = iv.encode('utf-8')
self.mode = AES.MODE_CBC
# 加密
def encrypt(self, content: str) -> bytes:
def encrypt(self, content: bytes) -> bytes:
cipher = AES.new(self.key, self.mode, self.iv)
content_padded = pad(content.encode(), AES.block_size)
content_padded = pad(content, AES.block_size)
encrypted_bytes = cipher.encrypt(content_padded)
return encrypted_bytes
# 解密
@ -39,7 +40,7 @@ def main_sdga():
# 填入你的想解密的数据的 base64 编码
base64_encoded_data = "KSGm2qo7qVHz1wrK15PckYC5/kLjKcTtEXOgHeHt1Xn6DPdo3pltoPLADHpe8+Wq"
aes = AESPKCS7(AES_KEY_SDGA_1_50, AES_IV_SDGA_1_50)
aes = AESPKCS7(aesKeyPrism, aesIVPrism)
# 首先解码 base64
decodedData = base64.b64decode(base64_encoded_data)
@ -54,7 +55,7 @@ def main_sdgb():
# 填入你的想解密的数据的 base64 编码
base64_encoded_data = "eJyrTVvpuGwCR32OdodwtVXZ7/Ofmfhin7k/K61q3XNoad1rAPGwECU="
aes = AESPKCS7(AES_KEY_SDGB_1_40, AES_IV_SDGB_1_40)
aes = AESPKCS7(aesKey2024, aesIV2024)
# 首先解码 base64
decodedData = base64.b64decode(base64_encoded_data)