Add Request Full Access Cookie Token

This commit is contained in:
洛水居室 2023-02-08 17:07:11 +08:00
parent 45626fb3c6
commit 138aa27dd6
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC
2 changed files with 37 additions and 9 deletions

View File

@ -26,11 +26,12 @@ class SignIn:
QRCODE_GET_API = "https://hk4e-sdk.mihoyo.com/hk4e_cn/combo/panda/qrcode/query" QRCODE_GET_API = "https://hk4e-sdk.mihoyo.com/hk4e_cn/combo/panda/qrcode/query"
GAME_TOKEN_API = "https://api-takumi.mihoyo.com/auth/api/getCookieAccountInfoByGameToken" GAME_TOKEN_API = "https://api-takumi.mihoyo.com/auth/api/getCookieAccountInfoByGameToken"
GAME_LTOKEN_API = "https://passport-api.mihoyo.com/account/ma-cn-session/app/getTokenByGameToken" GAME_LTOKEN_API = "https://passport-api.mihoyo.com/account/ma-cn-session/app/getTokenByGameToken"
COOKIES_GET_API = "https://passport-api.mihoyo.com/account/auth/api/getCookieAccountInfoBySToken"
def __init__(self, uid: int = 0, cookie: Dict = None): def __init__(self, uid: int = 0, cookie: Dict = None):
self.client = AsyncClient() self.client = AsyncClient()
self.uid = uid self.uid = uid
self.cookie = cookie if cookie is not None else {} self.cookie = cookie.copy() if cookie is not None else {}
self.parse_uid() self.parse_uid()
self.ticket = None self.ticket = None
self.device_id = None self.device_id = None
@ -137,6 +138,29 @@ class SignIn:
if res_data.get("stat", "") == "Confirmed": if res_data.get("stat", "") == "Confirmed":
return await self.set_cookie(res_json.get("data", {})) return await self.set_cookie(res_json.get("data", {}))
async def get_cookie_account_info_by_stoken(self, stoken, uid):
headers = {
"x-rpc-app_version": "2.11.1",
"User-Agent": (
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) "
"AppleWebKit/605.1.15 (KHTML, like Gecko) miHoYoBBS/2.11.1"
),
"x-rpc-client_type": "5",
"Referer": "https://webstatic.mihoyo.com/",
"Origin": "https://webstatic.mihoyo.com",
}
params = {
"stoken": stoken,
"uid": uid,
}
res = await self.client.get(
self.COOKIES_GET_API,
headers=headers,
params=params,
)
res_json = res.json()
return res_json.get("data", {}).get("cookie_token", "")
@staticmethod @staticmethod
def generate_qrcode(url: str) -> bytes: def generate_qrcode(url: str) -> bytes:
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4) qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4)

View File

@ -156,13 +156,11 @@ class SetUserCookies(Plugin.Conversation, BasePlugin.Conversation):
"<b>关于如何获取Cookies</b>\n" "<b>关于如何获取Cookies</b>\n"
"<b>现在因为网站HttpOnly策略无法通过脚本获取因此操作只能在PC上运行。</b>\n\n" "<b>现在因为网站HttpOnly策略无法通过脚本获取因此操作只能在PC上运行。</b>\n\n"
"PC\n" "PC\n"
"1、<a href='https://www.miyoushe.com/ys/'>打开米游社并登录</a>\n" "1、<a href='https://user.mihoyo.com/'>打开通行证并登录</a>\n"
"2、<a href='https://user.mihoyo.com/'>打开通行证并登录</a>\n" "2、进入通行证按F12打开开发者工具\n"
"3、登录完成后刷新米游社和通行证网页\n" "3、将开发者工具切换至网络(Network)并点击过滤栏中的文档(Document)并刷新页面\n"
"4、进入通行证按F12打开开发者工具\n" "4、在请求列表中选择第一个并点击\n"
"5、将开发者工具切换至网络(Network)并点击过滤栏中的文档(Document)并刷新页面\n" "5、找到并复制请求标头(Request Headers)中的<b>Cookie</b>\n"
"6、在请求列表中选择第一个并点击\n"
"7、找到并复制请求标头(Request Headers)中的<b>Cookie</b>\n"
"<u>如发现没有请求标头(Request Headers)大概因为缓存的存在需要你点击禁用缓存(Disable Cache)再次刷新页面</u>" "<u>如发现没有请求标头(Request Headers)大概因为缓存的存在需要你点击禁用缓存(Disable Cache)再次刷新页面</u>"
) )
else: else:
@ -277,7 +275,13 @@ class SetUserCookies(Plugin.Conversation, BasePlugin.Conversation):
sign_in_client = SignIn(cookie=add_user_command_data.cookies) sign_in_client = SignIn(cookie=add_user_command_data.cookies)
await sign_in_client.get_s_token() await sign_in_client.get_s_token()
add_user_command_data.cookies = sign_in_client.cookie add_user_command_data.cookies = sign_in_client.cookie
logger.info("用户 %s[%s] 绑定时获取 stoken 成功", user.full_name, user.id) logger.success("用户 %s[%s] 绑定时获取 stoken 成功", user.full_name, user.id)
stoken = add_user_command_data.cookies.get("stoken")
account_id = add_user_command_data.cookies.get("account_id")
if stoken and account_id:
cookie_token = await sign_in_client.get_cookie_account_info_by_stoken(stoken, account_id)
add_user_command_data.cookies["cookie_token"] = cookie_token
logger.success("用户 %s[%s] 绑定时获取 cookie_token 成功", user.full_name, user.id)
user_info: Optional[GenshinAccount] = None user_info: Optional[GenshinAccount] = None
level: int = 0 level: int = 0
# todo : 多账号绑定 # todo : 多账号绑定