🎨 在错误时尝试刷新nd

This commit is contained in:
KimigaiiWuyi 2023-10-27 02:07:58 +08:00
parent f98a812499
commit 4a7667e0b0
2 changed files with 53 additions and 22 deletions

View File

@ -9,7 +9,17 @@ import uuid
import random import random
from abc import abstractmethod from abc import abstractmethod
from string import digits, ascii_letters from string import digits, ascii_letters
from typing import Any, Dict, List, Tuple, Union, Literal, Optional, cast from typing import (
Any,
Dict,
List,
Tuple,
Union,
Literal,
Optional,
cast,
overload,
)
from aiohttp import TCPConnector, ClientSession, ContentTypeError from aiohttp import TCPConnector, ClientSession, ContentTypeError
@ -123,7 +133,7 @@ class BaseMysApi:
... ...
def get_device_id(self) -> str: def get_device_id(self) -> str:
device_id = str(uuid.uuid4()) device_id = str(uuid.uuid4()).lower()
return device_id return device_id
def generate_fp(self, length: int = 13) -> str: def generate_fp(self, length: int = 13) -> str:
@ -161,7 +171,7 @@ class BaseMysApi:
'bbs_device_id': device_id, 'bbs_device_id': device_id,
'device_fp': self.generate_fp(), 'device_fp': self.generate_fp(),
} }
print(body)
HEADER = copy.deepcopy(self._HEADER) HEADER = copy.deepcopy(self._HEADER)
res = await self._mys_request( res = await self._mys_request(
url=self.MAPI['GET_FP_URL'], url=self.MAPI['GET_FP_URL'],
@ -290,6 +300,32 @@ class BaseMysApi:
) )
return data return data
@overload
async def ck_in_new_device(
self, uid: str, app_cookie: str
) -> Tuple[str, str, str, str]:
...
@overload
async def ck_in_new_device(
self, uid: str, app_cookie: Optional[str] = None
) -> Optional[Tuple[str, str, str, str]]:
...
async def ck_in_new_device(
self, uid: str, app_cookie: Optional[str] = None
):
device_id = self.get_device_id()
seed_id, seed_time = self.get_seed()
model_name = self.generate_model_name()
fp = await self.generate_fp_by_uid(uid, seed_id, seed_time, model_name)
if app_cookie is None:
app_cookie = await self.get_stoken(uid)
if app_cookie is None:
return logger.warning('设备登录流程错误...')
await self.device_login_and_save(device_id, fp, model_name, app_cookie)
return fp, device_id, seed_id, seed_time
async def _mys_request( async def _mys_request(
self, self,
url: str, url: str,
@ -311,7 +347,7 @@ class BaseMysApi:
if device_id is not None: if device_id is not None:
header['x-rpc-device_id'] = device_id header['x-rpc-device_id'] = device_id
print(header) logger.debug(header)
for _ in range(2): for _ in range(2):
async with client.request( async with client.request(
method, method,
@ -339,19 +375,16 @@ class BaseMysApi:
retcode = 0 retcode = 0
# 针对1034做特殊处理 # 针对1034做特殊处理
if retcode == 1034: if retcode == 1034 or retcode == 5003:
if uid: if uid:
''' nd = await self.ck_in_new_device(uid)
ck = header['Cookie'] ck = header['Cookie']
if 'DEVICEFP_SEED_ID' not in ck: if 'DEVICEFP_SEED_ID' not in ck and nd:
header['Cookie'] = ( header['Cookie'] = (
'mi18nLang=zh-cn;_MHYUUID=' f'DEVICEFP_SEED_ID={nd[2]};'
'b6261233-05a8-45fc-b7a1-55e152b52ae4' f'DEVICEFP_SEED_TIME={nd[3]};'
f'DEVICEFP_SEED_ID={seed_id};' f'{ck};DEVICE_FP={nd[0]}'
f'DEVICEFP_SEED_TIME={seed_time};'
f'{ck};DEVICE_FP={new_fp}'
) )
'''
header['x-rpc-challenge_game'] = ( header['x-rpc-challenge_game'] = (
'6' if self.is_sr else '2' '6' if self.is_sr else '2'

View File

@ -233,11 +233,7 @@ async def _deal_ck(bot_id: str, mes: str, user_id: str) -> str:
if uid is None: if uid is None:
uid = '0' uid = '0'
device_id = mys_api.get_device_id() nd = await mys_api.ck_in_new_device(uid, app_cookie)
seed_id, seed_time = mys_api.get_seed()
model_name = mys_api.generate_model_name()
fp = await mys_api.generate_fp_by_uid(uid, seed_id, seed_time, model_name)
await mys_api.device_login_and_save(device_id, fp, model_name, app_cookie)
# 往数据库添加内容 # 往数据库添加内容
if uid_bind and await GsUser.user_exists(uid_bind): if uid_bind and await GsUser.user_exists(uid_bind):
@ -248,7 +244,8 @@ async def _deal_ck(bot_id: str, mes: str, user_id: str) -> str:
status=None, status=None,
stoken=app_cookie, stoken=app_cookie,
sr_uid=sr_uid_bind, sr_uid=sr_uid_bind,
fp=fp, fp=nd[0],
device_id=nd[1],
) )
elif sr_uid_bind and await GsUser.user_exists(sr_uid_bind, 'sr'): elif sr_uid_bind and await GsUser.user_exists(sr_uid_bind, 'sr'):
await GsUser.update_data_by_uid( await GsUser.update_data_by_uid(
@ -258,7 +255,8 @@ async def _deal_ck(bot_id: str, mes: str, user_id: str) -> str:
cookie=account_cookie, cookie=account_cookie,
status=None, status=None,
stoken=app_cookie, stoken=app_cookie,
fp=fp, fp=nd[0],
device_id=nd[1],
) )
else: else:
await GsUser.insert_data( await GsUser.insert_data(
@ -277,8 +275,8 @@ async def _deal_ck(bot_id: str, mes: str, user_id: str) -> str:
sr_region=SR_SERVER.get(sr_uid_bind[0], None) sr_region=SR_SERVER.get(sr_uid_bind[0], None)
if sr_uid_bind if sr_uid_bind
else None, else None,
fp=fp, fp=nd[0],
device_id=device_id, device_id=nd[1],
sr_push_switch='off', sr_push_switch='off',
sr_sign_switch='off', sr_sign_switch='off',
) )