2021-05-25 09:45:35 +00:00
|
|
|
import time
|
2021-05-23 13:24:20 +00:00
|
|
|
import tools
|
|
|
|
import config
|
2021-05-25 09:45:35 +00:00
|
|
|
import random
|
2021-05-23 13:24:20 +00:00
|
|
|
import setting
|
2021-06-13 02:33:38 +00:00
|
|
|
from request import http
|
2022-01-06 05:49:25 +00:00
|
|
|
from loghelper import log
|
2022-01-29 06:21:24 +00:00
|
|
|
from error import CookieError
|
2021-05-23 13:24:20 +00:00
|
|
|
|
2021-10-25 14:53:34 +00:00
|
|
|
|
2022-01-06 05:49:25 +00:00
|
|
|
class Genshin:
|
2021-05-23 13:24:20 +00:00
|
|
|
def __init__(self) -> None:
|
|
|
|
self.headers = {
|
2021-10-25 14:53:34 +00:00
|
|
|
'Accept': 'application/json, text/plain, */*',
|
2022-01-06 05:49:25 +00:00
|
|
|
'DS': tools.get_ds(web=True, web_old=True),
|
2021-10-25 14:53:34 +00:00
|
|
|
'Origin': 'https://webstatic.mihoyo.com',
|
|
|
|
'x-rpc-app_version': setting.mihoyobbs_Version_old,
|
|
|
|
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0',
|
|
|
|
'x-rpc-client_type': setting.mihoyobbs_Client_type_web,
|
|
|
|
'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',
|
|
|
|
'Accept-Encoding': 'gzip, deflate',
|
|
|
|
'Accept-Language': 'zh-CN,en-US;q=0.8',
|
|
|
|
'X-Requested-With': 'com.mihoyo.hyperion',
|
|
|
|
"Cookie": config.mihoyobbs_Cookies,
|
2022-01-06 05:49:25 +00:00
|
|
|
'x-rpc-device_id': tools.get_device_id()
|
2021-10-25 14:53:34 +00:00
|
|
|
}
|
2022-01-06 05:49:25 +00:00
|
|
|
self.acc_List = self.get_account_list()
|
2021-06-06 13:19:28 +00:00
|
|
|
if len(self.acc_List) != 0:
|
2022-01-06 05:49:25 +00:00
|
|
|
self.sign_Give = self.get_signgive()
|
2021-05-25 09:45:35 +00:00
|
|
|
|
2021-10-25 14:53:34 +00:00
|
|
|
# 获取绑定的账号列表
|
2022-01-06 05:49:25 +00:00
|
|
|
def get_account_list(self) -> list:
|
|
|
|
log.info("正在获取米哈游账号绑定原神账号列表...")
|
|
|
|
temp_list = []
|
2021-06-13 02:33:38 +00:00
|
|
|
req = http.get(setting.genshin_Account_info_url, headers=self.headers)
|
2021-05-23 13:24:20 +00:00
|
|
|
data = req.json()
|
2021-06-06 13:19:28 +00:00
|
|
|
if data["retcode"] != 0:
|
2022-01-06 05:49:25 +00:00
|
|
|
log.warning("获取账号列表失败!")
|
2022-01-29 06:21:24 +00:00
|
|
|
config.genshin_Auto_sign = False
|
|
|
|
config.save_config()
|
|
|
|
raise CookieError("BBS Cookie Errror")
|
2021-05-23 13:24:20 +00:00
|
|
|
for i in data["data"]["list"]:
|
2022-01-06 05:49:25 +00:00
|
|
|
temp_list.append([i["nickname"], i["game_uid"], i["region"]])
|
|
|
|
log.info(f"已获取到{len(temp_list)}个原神账号信息")
|
|
|
|
return temp_list
|
2021-05-25 09:45:35 +00:00
|
|
|
|
2021-10-25 14:53:34 +00:00
|
|
|
# 获取已经签到奖励列表
|
2022-01-06 05:49:25 +00:00
|
|
|
def get_signgive(self) -> list:
|
|
|
|
log.info("正在获取签到奖励列表...")
|
2021-10-25 14:53:34 +00:00
|
|
|
req = http.get(setting.genshin_Signlisturl.format(setting.genshin_Act_id), headers=self.headers)
|
2021-05-24 08:16:52 +00:00
|
|
|
data = req.json()
|
2021-06-06 13:19:28 +00:00
|
|
|
if data["retcode"] != 0:
|
2022-01-06 05:49:25 +00:00
|
|
|
log.warning("获取签到奖励列表失败")
|
2021-10-25 14:53:34 +00:00
|
|
|
print(req.text)
|
2021-06-06 13:19:28 +00:00
|
|
|
return data["data"]["awards"]
|
2021-05-25 09:45:35 +00:00
|
|
|
|
2021-10-25 14:53:34 +00:00
|
|
|
# 判断签到
|
2022-01-06 05:49:25 +00:00
|
|
|
def is_sign(self, region: str, uid: str):
|
2021-08-03 02:35:55 +00:00
|
|
|
req = http.get(setting.genshin_Is_signurl.format(setting.genshin_Act_id, region, uid), headers=self.headers)
|
2021-05-24 08:16:52 +00:00
|
|
|
data = req.json()
|
2021-06-06 13:19:28 +00:00
|
|
|
if data["retcode"] != 0:
|
2022-01-06 05:49:25 +00:00
|
|
|
log.warning("获取账号签到信息失败!")
|
2021-10-25 14:53:34 +00:00
|
|
|
print(req.text)
|
2022-01-29 06:21:24 +00:00
|
|
|
config.genshin_Auto_sign = False
|
|
|
|
config.save_config()
|
|
|
|
raise CookieError("BBS Cookie Errror")
|
2021-06-06 13:19:28 +00:00
|
|
|
return data["data"]
|
2021-05-25 09:45:35 +00:00
|
|
|
|
2021-10-25 14:53:34 +00:00
|
|
|
# 签到
|
2022-01-06 05:49:25 +00:00
|
|
|
def sign_account(self):
|
2022-01-30 03:58:31 +00:00
|
|
|
return_data = "原神:"
|
2021-06-06 13:19:28 +00:00
|
|
|
if len(self.acc_List) != 0:
|
2021-06-06 04:16:28 +00:00
|
|
|
for i in self.acc_List:
|
2022-01-06 05:49:25 +00:00
|
|
|
log.info(f"正在为旅行者{i[0]}进行签到...")
|
2021-08-06 00:53:51 +00:00
|
|
|
time.sleep(random.randint(2, 8))
|
2022-01-06 05:49:25 +00:00
|
|
|
is_data = self.is_sign(region=i[2], uid=i[1])
|
2021-09-30 13:00:12 +00:00
|
|
|
if is_data["first_bind"]:
|
2022-01-06 05:49:25 +00:00
|
|
|
log.warning(f"旅行者{i[0]}是第一次绑定米游社,请先手动签到一次")
|
2021-05-24 08:16:52 +00:00
|
|
|
else:
|
2022-01-06 05:49:25 +00:00
|
|
|
sign_days = is_data["total_sign_day"] - 1
|
2021-09-30 13:00:12 +00:00
|
|
|
if is_data["is_sign"]:
|
2022-01-06 05:49:25 +00:00
|
|
|
log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}")
|
2021-05-24 11:48:03 +00:00
|
|
|
else:
|
2021-08-06 00:53:51 +00:00
|
|
|
time.sleep(random.randint(2, 8))
|
2021-08-03 02:35:55 +00:00
|
|
|
req = http.post(url=setting.genshin_Signurl, headers=self.headers,
|
2021-10-25 14:53:34 +00:00
|
|
|
json={'act_id': setting.genshin_Act_id, 'region': i[2], 'uid': i[1]})
|
2021-06-06 04:16:28 +00:00
|
|
|
data = req.json()
|
2021-06-06 13:19:28 +00:00
|
|
|
if data["retcode"] == 0:
|
2022-01-06 05:49:25 +00:00
|
|
|
if sign_days == 0:
|
|
|
|
log.info(f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}")
|
2021-06-06 04:16:28 +00:00
|
|
|
else:
|
2022-01-06 05:49:25 +00:00
|
|
|
log.info(
|
|
|
|
f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days + 1])}")
|
2021-06-06 13:19:28 +00:00
|
|
|
elif data["retcode"] == -5003:
|
2022-01-06 05:49:25 +00:00
|
|
|
log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}")
|
2021-06-06 04:16:28 +00:00
|
|
|
else:
|
2022-01-06 05:49:25 +00:00
|
|
|
log.warning("账号签到失败!")
|
2021-10-25 14:53:34 +00:00
|
|
|
print(req.text)
|
2022-01-30 03:58:31 +00:00
|
|
|
if is_data["is_sign"] or data["retcode"] == 0 or data["retcode"] == -5003:
|
|
|
|
return_data += f"\n旅行者:{i[0]}已连续签到{sign_days}天,今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}"
|
|
|
|
else:
|
|
|
|
return_data += f"\n旅行者:{i[0]},本次签到失败"
|
2021-06-06 04:16:28 +00:00
|
|
|
else:
|
2022-01-06 05:49:25 +00:00
|
|
|
log.warning("账号没有绑定任何原神账号!")
|
2022-01-30 03:58:31 +00:00
|
|
|
return_data += "\n并没有绑定任何原神账号"
|
|
|
|
return return_data
|