This commit is contained in:
baiqwerdvd 2024-10-13 14:17:15 +08:00
parent 38ae22225d
commit 8061c44672
No known key found for this signature in database
GPG Key ID: 7717E46E1797411A
3 changed files with 21 additions and 45 deletions

View File

@ -27,11 +27,11 @@ async def get_resp_msg(bot: Bot, ev: Event):
if not phone_number.isdigit(): if not phone_number.isdigit():
return await bot.send("你输入了错误的格式!") return await bot.send("你输入了错误的格式!")
resp = await bot.receive_resp( resp = await bot.receive_resp(
f"请确认你的手机号码: {phone_number}." "如果正确请回复'确认', 其他任何回复将取消本次操作." f"请确认你的手机号码: {phone_number}. 如果正确请回复'确认', 其他任何回复将取消本次操作."
) )
if resp is not None and resp.text == "确认": if resp is not None and resp.text == "确认":
login = SklandLogin(phone_number) login = SklandLogin(phone_number)
login.send_phone_code() _ = login.send_phone_code()
code = await bot.receive_resp("请输入验证码:") code = await bot.receive_resp("请输入验证码:")
if code is None or not code.text.isdigit(): if code is None or not code.text.isdigit():
return await bot.send("你输入了错误的格式!") return await bot.send("你输入了错误的格式!")
@ -39,7 +39,7 @@ async def get_resp_msg(bot: Bot, ev: Event):
login.token_by_phone_code(code.text) login.token_by_phone_code(code.text)
login.post_account_info_hg() login.post_account_info_hg()
login.user_oauth2_v2_grant() login.user_oauth2_v2_grant()
(skland_cred, skland_token, skland_userId) = login.generate_cred_by_code() login.generate_cred_by_code()
uid = login.ark_uid uid = login.ark_uid
skd_uid = login.skland_userId skd_uid = login.skland_userId
@ -62,19 +62,19 @@ async def get_resp_msg(bot: Bot, ev: Event):
_ = await ArknightsUser.insert_data( _ = await ArknightsUser.insert_data(
ev.user_id, ev.user_id,
ev.bot_id, ev.bot_id,
cred=skland_cred, cred=login.skland_cred,
uid=uid, uid=uid,
skd_uid=skd_uid, skd_uid=skd_uid,
token=skland_token, token=login.skland_token,
) )
else: else:
_ = await ArknightsUser.update_data( _ = await ArknightsUser.update_data(
ev.user_id, ev.user_id,
ev.bot_id, ev.bot_id,
cred=skland_cred, cred=login.skland_cred,
uid=uid, uid=uid,
skd_uid=skd_uid, skd_uid=skd_uid,
token=skland_token, token=login.skland_token,
) )
if not push_data: if not push_data:
await ArknightsPush.insert_push_data(ev.bot_id, uid=uid, skd_uid=skd_uid) await ArknightsPush.insert_push_data(ev.bot_id, uid=uid, skd_uid=skd_uid)

View File

@ -5,5 +5,5 @@ ZONAI_SKLAND_URL = "https://zonai.skland.com/"
ARK_LOGIN_SEND_PHONE_CODE = ARK_ACCOUNT_SERVER + "general/v1/send_phone_code" ARK_LOGIN_SEND_PHONE_CODE = ARK_ACCOUNT_SERVER + "general/v1/send_phone_code"
ARK_TOKEN_BY_PHONE_CODE = ARK_ACCOUNT_SERVER + "user/auth/v2/token_by_phone_code" ARK_TOKEN_BY_PHONE_CODE = ARK_ACCOUNT_SERVER + "user/auth/v2/token_by_phone_code"
ARK_USER_OAUTH2_V2_GRANT = ARK_ACCOUNT_SERVER + "user/oauth2/v2/grant" ARK_USER_OAUTH2_V2_GRANT = ARK_ACCOUNT_SERVER + "user/oauth2/v2/grant"
ARK_ACCONUT_INFO_HG = SKLAND_WEB_API + "account/info/hg" ARK_ACCONUT_INFO_HG = "https://web-api.hypergryph.com/account/info/hg"
GENERATE_CRED_BY_CODE = ZONAI_SKLAND_URL + "web/v1/user/auth/generate_cred_by_code" GENERATE_CRED_BY_CODE = ZONAI_SKLAND_URL + "web/v1/user/auth/generate_cred_by_code"

View File

@ -52,8 +52,8 @@ class SklandLogin:
_HEADER: ClassVar[Dict[str, str]] = { _HEADER: ClassVar[Dict[str, str]] = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36", # noqa: E501 "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36", # noqa: E501
"content-type": "application/json;charset=UTF-8", "content-type": "application/json;charset=UTF-8",
"origin": "https://www.skland.com", "origin": "https://ak.hypergryph.com",
"referer": "https://www.skland.com", "referer": "https://ak.hypergryph.com",
} }
def __init__(self, phone: str, geetest_token: Union[str, None] = None): def __init__(self, phone: str, geetest_token: Union[str, None] = None):
@ -63,6 +63,9 @@ class SklandLogin:
verify=False, verify=False,
) )
self.geetest_token = geetest_token self.geetest_token = geetest_token
self.token = None
self.hg_token = None
self.ark_uid = None
def send_phone_code( def send_phone_code(
self, self,
@ -105,7 +108,7 @@ class SklandLogin:
"_pass_API", "_pass_API",
geetest_pass_data.info, geetest_pass_data.info,
) )
self.send_phone_code( _ = self.send_phone_code(
override_geetest=GeneralGeetestData( override_geetest=GeneralGeetestData(
geetest_challenge=geetest_pass_data.data.challenge, geetest_challenge=geetest_pass_data.data.challenge,
geetest_validate=geetest_pass_data.data.validate, geetest_validate=geetest_pass_data.data.validate,
@ -137,42 +140,14 @@ class SklandLogin:
def post_account_info_hg(self): def post_account_info_hg(self):
if self.token is None: if self.token is None:
raise SklandLoginError(ARK_ACCONUT_INFO_HG, "token not set!") raise SklandLoginError(ARK_ACCONUT_INFO_HG, "token not set!")
data = AccountInfoHGRequest(
content=self.token,
)
response = self.client.post( response = self.client.post(
ARK_ACCONUT_INFO_HG, ARK_ACCONUT_INFO_HG,
json=mscjson.decode(mscjson.encode(data)), json={"content": self.token},
) )
set_cookie = response.headers.get("set-cookie") set_cookie: str = response.headers.get("set-cookie")
matches = re.findall(r"ACCOUNT=([^;]+)", set_cookie) matches = re.findall(r"ACCOUNT=([^;]+)", set_cookie)
account_cookie = matches[0] account_cookie: str = matches[0]
self.client = httpx.Client( self.hg_token = account_cookie
headers=self._HEADER,
verify=False,
cookies={"ACCOUNT": account_cookie},
)
response.raise_for_status()
result = convert(response.json(), AccountInfoHGResponse)
if result.code != 0:
raise SklandLoginError(ARK_ACCONUT_INFO_HG, result.msg)
self.get_account_info_hg()
def get_account_info_hg(self):
if self.token is None:
raise SklandLoginError(ARK_ACCONUT_INFO_HG, "token not set!")
data = AccountInfoHGRequest(
content=self.token,
)
response = self.client.post(
ARK_ACCONUT_INFO_HG,
json=mscjson.decode(mscjson.encode(data)),
)
response.raise_for_status()
result = convert(response.json(), AccountInfoHGResponse)
if result.code != 0:
raise SklandLoginError(ARK_ACCONUT_INFO_HG, result.msg)
self.hg_token = result.data["content"]
self.get_ark_uid() self.get_ark_uid()
def user_oauth2_v2_grant(self): def user_oauth2_v2_grant(self):
@ -215,11 +190,13 @@ class SklandLogin:
) )
response.raise_for_status() response.raise_for_status()
result_data = response.json() result_data = response.json()
self.ark_uid = result_data["data"]["uid"] self.ark_uid: str = result_data["data"]["uid"]
def generate_cred_by_code(self): def generate_cred_by_code(self):
self.client.headers["platform"] = "3" self.client.headers["platform"] = "3"
self.client.headers["vName"] = "1.0.0" self.client.headers["vName"] = "1.0.0"
self.client.headers["origin"] = "https://zonai.skland.com/"
self.client.headers["referer"] = "https://zonai.skland.com/"
self.client.headers["timestamp"] = str(int(datetime.now().timestamp())) self.client.headers["timestamp"] = str(int(datetime.now().timestamp()))
self.client.headers["dId"] = get_d_id() self.client.headers["dId"] = get_d_id()
response = self.client.post( response = self.client.post(
@ -237,4 +214,3 @@ class SklandLogin:
self.skland_cred = result.data.cred self.skland_cred = result.data.cred
self.skland_token = result.data.token self.skland_token = result.data.token
self.skland_userId = result.data.userId self.skland_userId = result.data.userId
return (self.skland_cred, self.skland_token, self.skland_userId)