🐛 修复米游币获取

This commit is contained in:
CMHopeSunshine 2022-08-19 01:15:45 +08:00
parent 7ca5bbec0c
commit 539aec48ca
2 changed files with 27 additions and 19 deletions

View File

@ -3,13 +3,13 @@ import random
from nonebot import logger from nonebot import logger
from littlepaimon_utils import aiorequests 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列表 # 米游社的API列表
bbs_Cookieurl = 'https://webapi.account.mihoyo.com/Api/cookie_accountinfo_by_loginticket?login_ticket={}' 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_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_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_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_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' 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): def __init__(self, cookies: str, user_id: str, uid: str):
self.headers: dict = { self.headers: dict = {
'DS': get_old_version_ds(mhy_bbs=True), 'DS': get_old_version_ds(),
'cookie': cookies, 'cookie': cookies,
'x-rpc-client_type': '2', '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-sys_version': '6.0.1',
'x-rpc-channel': 'mihoyo', 'x-rpc-channel': 'miyousheluodi',
'x-rpc-device_id': random_hex(32), 'x-rpc-device_id': random_hex(32),
'x-rpc-device_name': random_text(random.randint(1, 10)), 'x-rpc-device_name': random_text(random.randint(1, 10)),
'x-rpc-device_model': 'Mi 10', 'x-rpc-device_model': 'Mi 10',
@ -182,8 +182,10 @@ class MihoyoBBSCoin:
""" """
if self.Task_do['bbs_Sign']: if self.Task_do['bbs_Sign']:
return '讨论区签到任务已经完成过了~' return '讨论区签到任务已经完成过了~'
header = self.headers.copy()
for i in self.mihoyo_bbs_List: 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() data = req.json()
if 'err' in data['message']: if 'err' in data['message']:
self.state = False self.state = False

View File

@ -125,17 +125,23 @@ def random_text(length: int) -> str:
return ''.join(random.sample(string.ascii_lowercase + string.digits, length)) return ''.join(random.sample(string.ascii_lowercase + string.digits, length))
# 米游社headers的ds_token对应版本2.11.1 def get_ds(q: str = '', b: dict = None, mhy_bbs_sign: bool = False) -> str:
def get_ds(q="", b=None) -> str: """
if b: 生成米游社headers的ds_token
br = json.dumps(b) :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: else:
br = "" s = 'xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs'
s = "xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs"
t = str(int(time())) t = str(int(time()))
r = str(random.randint(100000, 200000)) r = str(random.randint(100000, 200000))
c = md5("salt=" + s + "&t=" + t + "&r=" + r + "&b=" + br + "&q=" + q) c = md5(f'salt={s}&t={t}&r={r}&b={br}&q={q}')
return f"{t},{r},{c}" return f'{t},{r},{c}'
# 米游社爬虫headers # 米游社爬虫headers
@ -158,9 +164,9 @@ def get_old_version_ds(mhy_bbs: bool = False) -> str:
生成米游社旧版本headers的ds_token 生成米游社旧版本headers的ds_token
""" """
if mhy_bbs: if mhy_bbs:
s = 'dWCcD2FsOUXEstC5f9xubswZxEeoBOTc' s = '9nQiU3AV0rJSIBWgdynfoGMGKaklfbM7'
else: else:
s = 'h8w582wxwgqvahcdkpvdhbh2w9casgfl' s = 'z8DRIUjNDT7IT5IZXvrUAxyupA1peND9'
t = str(int(time())) t = str(int(time()))
r = ''.join(random.sample(string.ascii_lowercase + string.digits, 6)) r = ''.join(random.sample(string.ascii_lowercase + string.digits, 6))
c = md5(f"salt={s}&t={t}&r={r}") c = md5(f"salt={s}&t={t}&r={r}")
@ -171,15 +177,15 @@ def get_sign_headers(cookie):
headers = { headers = {
'User_Agent': 'Mozilla/5.0 (Linux; Android 10; MIX 2 Build/QKQ1.190825.002; wv) AppleWebKit/537.36 (' '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 ' '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, 'Cookie': cookie,
'x-rpc-device_id': random_hex(32), 'x-rpc-device_id': random_hex(32),
'Origin': 'https://webstatic.mihoyo.com', 'Origin': 'https://webstatic.mihoyo.com',
'X_Requested_With': 'com.mihoyo.hyperion', 'X_Requested_With': 'com.mihoyo.hyperion',
'DS': get_old_version_ds(mhy_bbs=True), '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', '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 return headers