From 539aec48caa3545f893ed4430709ff682aed45ea Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Fri, 19 Aug 2022 01:15:45 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E7=B1=B3=E6=B8=B8?= =?UTF-8?q?=E5=B8=81=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Paimon_Info/get_coin.py | 14 ++++++++------ utils/auth_util.py | 32 +++++++++++++++++++------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Paimon_Info/get_coin.py b/Paimon_Info/get_coin.py index b70255d..59a94bf 100644 --- a/Paimon_Info/get_coin.py +++ b/Paimon_Info/get_coin.py @@ -3,13 +3,13 @@ import random from nonebot import logger from littlepaimon_utils import aiorequests -from ..utils.auth_util import random_text, random_hex, get_old_version_ds +from ..utils.auth_util import random_text, random_hex, get_old_version_ds, get_ds # 米游社的API列表 bbs_Cookieurl = 'https://webapi.account.mihoyo.com/Api/cookie_accountinfo_by_loginticket?login_ticket={}' bbs_Cookieurl2 = 'https://api-takumi.mihoyo.com/auth/api/getMultiTokenByLoginTicket?login_ticket={}&token_types=3&uid={}' bbs_Taskslist = 'https://bbs-api.mihoyo.com/apihub/sapi/getUserMissionsState' # 获取任务列表 -bbs_Signurl = 'https://bbs-api.mihoyo.com/apihub/sapi/signIn?gids={}' # post +bbs_Signurl = 'https://bbs-api.mihoyo.com/apihub/app/api/signIn' # post bbs_Listurl = 'https://bbs-api.mihoyo.com/post/api/getForumPostList?forum_id={}&is_good=false&is_hot=false&page_size=20&sort_type=1' bbs_Detailurl = 'https://bbs-api.mihoyo.com/post/api/getPostFull?post_id={}' bbs_Shareurl = 'https://bbs-api.mihoyo.com/apihub/api/getShareConf?entity_id={}&entity_type=1' @@ -62,12 +62,12 @@ class MihoyoBBSCoin: def __init__(self, cookies: str, user_id: str, uid: str): self.headers: dict = { - 'DS': get_old_version_ds(mhy_bbs=True), + 'DS': get_old_version_ds(), 'cookie': cookies, 'x-rpc-client_type': '2', - 'x-rpc-app_version': '2.28.1', + 'x-rpc-app_version': '2.34.1', 'x-rpc-sys_version': '6.0.1', - 'x-rpc-channel': 'mihoyo', + 'x-rpc-channel': 'miyousheluodi', 'x-rpc-device_id': random_hex(32), 'x-rpc-device_name': random_text(random.randint(1, 10)), 'x-rpc-device_model': 'Mi 10', @@ -182,8 +182,10 @@ class MihoyoBBSCoin: """ if self.Task_do['bbs_Sign']: return '讨论区签到任务已经完成过了~' + header = self.headers.copy() for i in self.mihoyo_bbs_List: - req = await aiorequests.post(url=bbs_Signurl.format(i['id']), data={}, headers=self.headers) + header['DS'] = get_ds('', {'gids': i['id']}, True) + req = await aiorequests.post(url=bbs_Signurl, json={'gids': i['id']}, headers=header) data = req.json() if 'err' in data['message']: self.state = False diff --git a/utils/auth_util.py b/utils/auth_util.py index 0c2ba3a..aa1fa9e 100644 --- a/utils/auth_util.py +++ b/utils/auth_util.py @@ -125,17 +125,23 @@ def random_text(length: int) -> str: return ''.join(random.sample(string.ascii_lowercase + string.digits, length)) -# 米游社headers的ds_token,对应版本2.11.1 -def get_ds(q="", b=None) -> str: - if b: - br = json.dumps(b) +def get_ds(q: str = '', b: dict = None, mhy_bbs_sign: bool = False) -> str: + """ + 生成米游社headers的ds_token + :param q: 查询 + :param b: 请求体 + :param mhy_bbs_sign: 是否为米游社讨论区签到 + :return: ds_token + """ + br = json.dumps(b) if b else '' + if mhy_bbs_sign: + s = 't0qEgfub6cvueAPgR5m9aQWWVciEer7v' else: - br = "" - s = "xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs" + s = 'xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs' t = str(int(time())) r = str(random.randint(100000, 200000)) - c = md5("salt=" + s + "&t=" + t + "&r=" + r + "&b=" + br + "&q=" + q) - return f"{t},{r},{c}" + c = md5(f'salt={s}&t={t}&r={r}&b={br}&q={q}') + return f'{t},{r},{c}' # 米游社爬虫headers @@ -158,9 +164,9 @@ def get_old_version_ds(mhy_bbs: bool = False) -> str: 生成米游社旧版本headers的ds_token """ if mhy_bbs: - s = 'dWCcD2FsOUXEstC5f9xubswZxEeoBOTc' + s = '9nQiU3AV0rJSIBWgdynfoGMGKaklfbM7' else: - s = 'h8w582wxwgqvahcdkpvdhbh2w9casgfl' + s = 'z8DRIUjNDT7IT5IZXvrUAxyupA1peND9' t = str(int(time())) r = ''.join(random.sample(string.ascii_lowercase + string.digits, 6)) c = md5(f"salt={s}&t={t}&r={r}") @@ -171,15 +177,15 @@ def get_sign_headers(cookie): headers = { 'User_Agent': 'Mozilla/5.0 (Linux; Android 10; MIX 2 Build/QKQ1.190825.002; wv) AppleWebKit/537.36 (' 'KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.101 Mobile Safari/537.36 ' - 'miHoYoBBS/2.3.0', + 'miHoYoBBS/2.34.1', 'Cookie': cookie, 'x-rpc-device_id': random_hex(32), 'Origin': 'https://webstatic.mihoyo.com', 'X_Requested_With': 'com.mihoyo.hyperion', 'DS': get_old_version_ds(mhy_bbs=True), - 'x-rpc-client_type': '2', + 'x-rpc-client_type': '5', 'Referer': 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required=true&act_id=e202009291139501&utm_source=bbs&utm_medium=mys&utm_campaign=icon', - 'x-rpc-app_version': '2.28.1' + 'x-rpc-app_version': '2.34.1' } return headers