mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-25 09:37:30 +00:00
🐛 Fix setcookie do not save ltuid
Co-authored-by: 洛水居室 <luoshuijs@outlook.com>
This commit is contained in:
parent
c1012d206b
commit
4f686f5284
@ -34,9 +34,6 @@ class AuthClient:
|
|||||||
QRCODE_GET_API = f"https://{HK4E_SDK_HOST}/hk4e_cn/combo/panda/qrcode/query"
|
QRCODE_GET_API = f"https://{HK4E_SDK_HOST}/hk4e_cn/combo/panda/qrcode/query"
|
||||||
GET_COOKIE_ACCOUNT_BY_GAME_TOKEN_API = f"https://{TAKUMI_HOST}/auth/api/getCookieAccountInfoByGameToken"
|
GET_COOKIE_ACCOUNT_BY_GAME_TOKEN_API = f"https://{TAKUMI_HOST}/auth/api/getCookieAccountInfoByGameToken"
|
||||||
GET_TOKEN_BY_GAME_LTOKEN_API = f"https://{PASSPORT_HOST}/account/ma-cn-session/app/getTokenByGameToken"
|
GET_TOKEN_BY_GAME_LTOKEN_API = f"https://{PASSPORT_HOST}/account/ma-cn-session/app/getTokenByGameToken"
|
||||||
GET_COOKIES_TOKEN_BY_STOKEN_API = f"https://{PASSPORT_HOST}/account/auth/api/getCookieAccountInfoBySToken"
|
|
||||||
GET_LTOKEN_BY_STOKEN_API = f"https://{PASSPORT_HOST}/account/auth/api/getLTokenBySToken"
|
|
||||||
get_STOKEN_URL = f"https://{TAKUMI_HOST}/auth/api/getMultiTokenByLoginTicket"
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -60,24 +57,6 @@ class AuthClient:
|
|||||||
else:
|
else:
|
||||||
self.user_id = self.cookies.user_id
|
self.user_id = self.cookies.user_id
|
||||||
|
|
||||||
async def get_stoken_by_login_ticket(self) -> bool:
|
|
||||||
if self.cookies.login_ticket is None and self.user_id is None:
|
|
||||||
return False
|
|
||||||
params = {"login_ticket": self.cookies.login_ticket, "uid": self.user_id, "token_types": 3}
|
|
||||||
data = await self.client.get(self.get_STOKEN_URL, params=params, headers={"User-Agent": self.USER_AGENT})
|
|
||||||
res_json = data.json()
|
|
||||||
res_data = res_json.get("data", {}).get("list", [])
|
|
||||||
for i in res_data:
|
|
||||||
name = i.get("name")
|
|
||||||
token = i.get("token")
|
|
||||||
if name and token and hasattr(self.cookies, name):
|
|
||||||
setattr(self.cookies, name, token)
|
|
||||||
if self.cookies.stoken:
|
|
||||||
if self.cookies.stuid:
|
|
||||||
self.cookies.stuid = self.user_id
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
async def get_ltoken_by_game_token(self, game_token: str) -> bool:
|
async def get_ltoken_by_game_token(self, game_token: str) -> bool:
|
||||||
if self.user_id is None:
|
if self.user_id is None:
|
||||||
return False
|
return False
|
||||||
@ -154,68 +133,6 @@ class AuthClient:
|
|||||||
if res_data.get("stat", "") == "Confirmed":
|
if res_data.get("stat", "") == "Confirmed":
|
||||||
return await self._set_cookie_by_game_token(res_json.get("data", {}))
|
return await self._set_cookie_by_game_token(res_json.get("data", {}))
|
||||||
|
|
||||||
async def get_cookie_token_by_stoken(self) -> bool:
|
|
||||||
if self.cookies.stoken is None:
|
|
||||||
return False
|
|
||||||
user_id = self.cookies.user_id
|
|
||||||
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": self.cookies.stoken,
|
|
||||||
"uid": user_id,
|
|
||||||
}
|
|
||||||
res = await self.client.get(
|
|
||||||
self.GET_COOKIES_TOKEN_BY_STOKEN_API,
|
|
||||||
headers=headers,
|
|
||||||
params=params,
|
|
||||||
)
|
|
||||||
res_json = res.json()
|
|
||||||
cookie_token = res_json.get("data", {}).get("cookie_token", "")
|
|
||||||
if cookie_token:
|
|
||||||
self.cookies.cookie_token = cookie_token
|
|
||||||
self.cookies.account_id = user_id
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
async def get_ltoken_by_stoken(self) -> bool:
|
|
||||||
if self.cookies.stoken is None:
|
|
||||||
return False
|
|
||||||
user_id = self.cookies.user_id
|
|
||||||
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": self.cookies.stoken,
|
|
||||||
"uid": user_id,
|
|
||||||
}
|
|
||||||
res = await self.client.get(
|
|
||||||
self.GET_LTOKEN_BY_STOKEN_API,
|
|
||||||
headers=headers,
|
|
||||||
params=params,
|
|
||||||
)
|
|
||||||
res_json = res.json()
|
|
||||||
ltoken = res_json.get("data", {}).get("ltoken", "")
|
|
||||||
if ltoken:
|
|
||||||
self.cookies.ltoken = ltoken
|
|
||||||
self.cookies.ltuid = user_id
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
@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)
|
||||||
|
@ -226,8 +226,8 @@ class AccountCookiesPlugin(Plugin.Conversation):
|
|||||||
if cookies.login_ticket is not None:
|
if cookies.login_ticket is not None:
|
||||||
try:
|
try:
|
||||||
cookies.cookie_token = await client.get_cookie_token_by_login_ticket()
|
cookies.cookie_token = await client.get_cookie_token_by_login_ticket()
|
||||||
cookies.account_id = cookies.account_id
|
cookies.account_id = client.account_id
|
||||||
cookies.ltuid = cookies.account_id
|
cookies.ltuid = client.account_id
|
||||||
logger.success("用户 %s[%s] 绑定时获取 cookie_token 成功", user.full_name, user.id)
|
logger.success("用户 %s[%s] 绑定时获取 cookie_token 成功", user.full_name, user.id)
|
||||||
cookies.stoken = await client.get_stoken_by_login_ticket()
|
cookies.stoken = await client.get_stoken_by_login_ticket()
|
||||||
logger.success("用户 %s[%s] 绑定时获取 stoken 成功", user.full_name, user.id)
|
logger.success("用户 %s[%s] 绑定时获取 stoken 成功", user.full_name, user.id)
|
||||||
@ -246,14 +246,11 @@ class AccountCookiesPlugin(Plugin.Conversation):
|
|||||||
try:
|
try:
|
||||||
if client.account_id is None and cookies.is_v2:
|
if client.account_id is None and cookies.is_v2:
|
||||||
logger.info("检测到用户 %s[%s] 使用 V2 Cookie 正在尝试获取 account_id", user.full_name, user.id)
|
logger.info("检测到用户 %s[%s] 使用 V2 Cookie 正在尝试获取 account_id", user.full_name, user.id)
|
||||||
if client.region == Region.CHINESE:
|
account_info = await client.get_user_info()
|
||||||
account_info = await client.get_user_info()
|
account_id = account_info.accident_id
|
||||||
account_id = account_info.accident_id
|
account_cookies_plugin_data.account_id = account_id
|
||||||
account_cookies_plugin_data.account_id = account_id
|
cookies.set_v2_uid(account_id)
|
||||||
cookies.set_v2_uid(account_id)
|
logger.success("获取用户 %s[%s] account_id[%s] 成功", user.full_name, user.id, account_id)
|
||||||
logger.success("获取用户 %s[%s] account_id[%s] 成功", user.full_name, user.id, account_id)
|
|
||||||
else:
|
|
||||||
logger.warning("用户 %s[%s] region[%s] 也许是不正确的", user.full_name, user.id, client.region.name)
|
|
||||||
else:
|
else:
|
||||||
account_cookies_plugin_data.account_id = client.account_id
|
account_cookies_plugin_data.account_id = client.account_id
|
||||||
genshin_accounts = await client.get_genshin_accounts()
|
genshin_accounts = await client.get_genshin_accounts()
|
||||||
|
@ -2,6 +2,7 @@ import html
|
|||||||
from http.cookies import SimpleCookie
|
from http.cookies import SimpleCookie
|
||||||
from typing import Tuple, TYPE_CHECKING
|
from typing import Tuple, TYPE_CHECKING
|
||||||
|
|
||||||
|
from simnet import Region, GenshinClient
|
||||||
from telegram import InlineKeyboardMarkup, InlineKeyboardButton
|
from telegram import InlineKeyboardMarkup, InlineKeyboardButton
|
||||||
from telegram.ext import filters
|
from telegram.ext import filters
|
||||||
|
|
||||||
@ -10,7 +11,6 @@ from core.plugin import Plugin, handler
|
|||||||
from core.services.cookies import CookiesService
|
from core.services.cookies import CookiesService
|
||||||
from core.services.players import PlayersService
|
from core.services.players import PlayersService
|
||||||
from core.services.players.services import PlayerInfoService
|
from core.services.players.services import PlayerInfoService
|
||||||
from modules.apihelper.client.components.authclient import AuthClient
|
|
||||||
from modules.apihelper.models.genshin.cookies import CookiesModel
|
from modules.apihelper.models.genshin.cookies import CookiesModel
|
||||||
from utils.log import logger
|
from utils.log import logger
|
||||||
|
|
||||||
@ -211,12 +211,13 @@ class PlayersManagesPlugin(Plugin):
|
|||||||
|
|
||||||
if cookies.stoken is not None:
|
if cookies.stoken is not None:
|
||||||
try:
|
try:
|
||||||
auth_client = AuthClient(cookies=cookies)
|
region = Region.CHINESE if player.region.value == 1 else Region.OVERSEAS
|
||||||
if await auth_client.get_cookie_token_by_stoken():
|
async with GenshinClient(cookies=cookies.to_dict(), region=region) as client:
|
||||||
|
cookies.cookie_token = await client.get_cookie_token_by_stoken()
|
||||||
logger.success("用户 %s[%s] 刷新 cookie_token 成功", user.full_name, user.id)
|
logger.success("用户 %s[%s] 刷新 cookie_token 成功", user.full_name, user.id)
|
||||||
if await auth_client.get_ltoken_by_stoken():
|
cookies.ltoken = await client.get_ltoken_by_stoken()
|
||||||
logger.success("用户 %s[%s] 刷新 ltoken 成功", user.full_name, user.id)
|
logger.success("用户 %s[%s] 刷新 ltoken 成功", user.full_name, user.id)
|
||||||
auth_client.cookies.remove_v2()
|
cookies.remove_v2()
|
||||||
except Exception as exc: # pylint: disable=W0703
|
except Exception as exc: # pylint: disable=W0703
|
||||||
logger.error("刷新 cookie_token 失败 [%s]", (str(exc)))
|
logger.error("刷新 cookie_token 失败 [%s]", (str(exc)))
|
||||||
await callback_query.edit_message_text(
|
await callback_query.edit_message_text(
|
||||||
|
@ -311,7 +311,7 @@ class GenshinHelper(Plugin):
|
|||||||
device_fp = devices.device_fp
|
device_fp = devices.device_fp
|
||||||
|
|
||||||
async with GenshinClient(
|
async with GenshinClient(
|
||||||
cookies,
|
cookies.data,
|
||||||
region=game_region,
|
region=game_region,
|
||||||
account_id=player.account_id,
|
account_id=player.account_id,
|
||||||
player_id=uid,
|
player_id=uid,
|
||||||
|
Loading…
Reference in New Issue
Block a user