2021-05-25 17:45:35 +08:00
|
|
|
import time
|
2021-05-23 21:24:20 +08:00
|
|
|
import tools
|
|
|
|
|
import config
|
2021-05-25 17:45:35 +08:00
|
|
|
import random
|
2021-05-23 21:24:20 +08:00
|
|
|
import setting
|
2022-08-18 16:36:48 +08:00
|
|
|
from error import *
|
2021-06-13 10:33:38 +08:00
|
|
|
from request import http
|
2022-01-06 13:49:25 +08:00
|
|
|
from loghelper import log
|
2022-04-23 08:47:10 +08:00
|
|
|
from account import get_account_list
|
2021-05-23 21:24:20 +08:00
|
|
|
|
2021-10-25 22:53:34 +08:00
|
|
|
|
2022-01-06 13:49:25 +08:00
|
|
|
class Genshin:
|
2021-05-23 21:24:20 +08:00
|
|
|
def __init__(self) -> None:
|
2022-08-18 16:36:48 +08:00
|
|
|
self.headers = {}
|
|
|
|
|
self.headers.update(setting.headers)
|
2022-08-05 12:25:10 +08:00
|
|
|
self.headers['DS'] = tools.get_ds(web=True)
|
2022-08-18 16:36:48 +08:00
|
|
|
self.headers['Referer'] = 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required=true' \
|
2022-04-28 14:29:18 +08:00
|
|
|
f'&act_id={setting.genshin_Act_id}&utm_source=bbs&utm_medium=mys&utm_campaign=icon'
|
|
|
|
|
self.headers['Cookie'] = config.config["account"]["cookie"]
|
|
|
|
|
self.headers['x-rpc-device_id'] = tools.get_device_id()
|
2022-05-01 10:33:20 +08:00
|
|
|
self.account_list = get_account_list("hk4e_cn", self.headers)
|
|
|
|
|
if len(self.account_list) != 0:
|
|
|
|
|
self.checkin_rewards = self.get_checkin_rewards()
|
2021-05-25 17:45:35 +08:00
|
|
|
|
2021-10-25 22:53:34 +08:00
|
|
|
# 获取已经签到奖励列表
|
2022-05-01 10:33:20 +08:00
|
|
|
def get_checkin_rewards(self) -> list:
|
2022-01-06 13:49:25 +08:00
|
|
|
log.info("正在获取签到奖励列表...")
|
2022-05-01 10:33:20 +08:00
|
|
|
req = http.get(setting.genshin_checkin_rewards, headers=self.headers)
|
2021-05-24 16:16:52 +08:00
|
|
|
data = req.json()
|
2021-06-06 21:19:28 +08:00
|
|
|
if data["retcode"] != 0:
|
2022-01-06 13:49:25 +08:00
|
|
|
log.warning("获取签到奖励列表失败")
|
2021-10-25 22:53:34 +08:00
|
|
|
print(req.text)
|
2021-06-06 21:19:28 +08:00
|
|
|
return data["data"]["awards"]
|
2021-05-25 17:45:35 +08:00
|
|
|
|
2021-10-25 22:53:34 +08:00
|
|
|
# 判断签到
|
2022-04-30 09:00:07 +08:00
|
|
|
def is_sign(self, region: str, uid: str) -> dict:
|
2021-08-03 10:35:55 +08:00
|
|
|
req = http.get(setting.genshin_Is_signurl.format(setting.genshin_Act_id, region, uid), headers=self.headers)
|
2021-05-24 16:16:52 +08:00
|
|
|
data = req.json()
|
2021-06-06 21:19:28 +08:00
|
|
|
if data["retcode"] != 0:
|
2022-01-06 13:49:25 +08:00
|
|
|
log.warning("获取账号签到信息失败!")
|
2021-10-25 22:53:34 +08:00
|
|
|
print(req.text)
|
2022-04-28 15:08:27 +08:00
|
|
|
config.config["games"]["cn"]["genshin"]["auto_checkin"] = False
|
2022-01-29 14:21:24 +08:00
|
|
|
config.save_config()
|
|
|
|
|
raise CookieError("BBS Cookie Errror")
|
2021-06-06 21:19:28 +08:00
|
|
|
return data["data"]
|
2021-05-25 17:45:35 +08:00
|
|
|
|
2022-08-18 16:36:48 +08:00
|
|
|
def check_in(self, account):
|
|
|
|
|
for i in range(3):
|
|
|
|
|
req = http.post(url=setting.genshin_Signurl, headers=self.headers,
|
|
|
|
|
json={'act_id': setting.genshin_Act_id, 'region': account[2], 'uid': account[1]})
|
|
|
|
|
data = req.json()
|
|
|
|
|
if data["retcode"] == 0 and data["data"]["success"] == 1:
|
|
|
|
|
time.sleep(random.randint(4, 10))
|
|
|
|
|
else:
|
|
|
|
|
break
|
|
|
|
|
return req
|
|
|
|
|
|
2021-10-25 22:53:34 +08:00
|
|
|
# 签到
|
2022-04-30 09:00:07 +08:00
|
|
|
def sign_account(self) -> str:
|
2022-04-23 08:47:10 +08:00
|
|
|
return_data = "原神: "
|
2022-05-01 10:33:20 +08:00
|
|
|
if len(self.account_list) != 0:
|
|
|
|
|
for i in self.account_list:
|
2022-04-28 15:08:27 +08:00
|
|
|
if i[1] in config.config["games"]["cn"]["genshin"]["black_list"]:
|
|
|
|
|
continue
|
2022-01-06 13:49:25 +08:00
|
|
|
log.info(f"正在为旅行者{i[0]}进行签到...")
|
2021-08-06 08:53:51 +08:00
|
|
|
time.sleep(random.randint(2, 8))
|
2022-01-06 13:49:25 +08:00
|
|
|
is_data = self.is_sign(region=i[2], uid=i[1])
|
2021-09-30 21:00:12 +08:00
|
|
|
if is_data["first_bind"]:
|
2022-01-06 13:49:25 +08:00
|
|
|
log.warning(f"旅行者{i[0]}是第一次绑定米游社,请先手动签到一次")
|
2021-05-24 16:16:52 +08:00
|
|
|
else:
|
2022-01-06 13:49:25 +08:00
|
|
|
sign_days = is_data["total_sign_day"] - 1
|
2022-08-18 16:36:48 +08:00
|
|
|
ok = True
|
2022-08-18 16:40:31 +08:00
|
|
|
if is_data["is_sign"]:
|
2022-05-01 10:33:20 +08:00
|
|
|
log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days])}")
|
2022-04-28 14:42:20 +08:00
|
|
|
sign_days += 1
|
2021-05-24 19:48:03 +08:00
|
|
|
else:
|
2021-08-06 08:53:51 +08:00
|
|
|
time.sleep(random.randint(2, 8))
|
2022-08-18 16:36:48 +08:00
|
|
|
req = self.check_in(i)
|
2021-06-06 12:16:28 +08:00
|
|
|
data = req.json()
|
2022-08-11 21:27:15 +08:00
|
|
|
if data["retcode"] == 0 and data["data"]["success"] == 0:
|
2022-04-24 13:09:47 +08:00
|
|
|
log.info(f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是"
|
2022-05-01 10:33:20 +08:00
|
|
|
f"{tools.get_item(self.checkin_rewards[0 if sign_days == 0 else sign_days + 1])}")
|
2022-04-28 14:42:20 +08:00
|
|
|
sign_days += 2
|
2021-06-06 21:19:28 +08:00
|
|
|
elif data["retcode"] == -5003:
|
2022-05-01 10:33:20 +08:00
|
|
|
log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days])}")
|
2021-06-06 12:16:28 +08:00
|
|
|
else:
|
2022-08-11 21:27:15 +08:00
|
|
|
s = "账号签到失败!"
|
2022-08-18 16:36:48 +08:00
|
|
|
if data["data"] != "" and data.get("data").get("success", -1):
|
2022-08-11 21:27:15 +08:00
|
|
|
s += "原因: 验证码\njson信息:" + req.text
|
|
|
|
|
log.warning(s)
|
2022-02-08 13:14:30 +08:00
|
|
|
ok = False
|
|
|
|
|
if ok:
|
2022-08-18 16:36:48 +08:00
|
|
|
return_data += f"\n{i[0]}已连续签到{sign_days}天\n" \
|
|
|
|
|
f"今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days - 1])}"
|
2022-01-30 11:58:31 +08:00
|
|
|
else:
|
2022-01-30 16:17:47 +08:00
|
|
|
return_data += f"\n{i[0]},本次签到失败"
|
2022-08-11 21:27:15 +08:00
|
|
|
if data["data"] != "" and data["data"]["success"] == 1:
|
|
|
|
|
return_data += ",失败原因: 触发验证码"
|
2021-06-06 12:16:28 +08:00
|
|
|
else:
|
2022-01-06 13:49:25 +08:00
|
|
|
log.warning("账号没有绑定任何原神账号!")
|
2022-01-30 11:58:31 +08:00
|
|
|
return_data += "\n并没有绑定任何原神账号"
|
|
|
|
|
return return_data
|