From 3a76298ba5ef2816cfb71d9ede98e182016d247b Mon Sep 17 00:00:00 2001 From: owwkmidream <159dreaml@gmail.com> Date: Sun, 8 Dec 2024 17:34:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(config):=20=E6=9B=B4=E6=96=B0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E5=88=B0v13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloudgames.py | 48 ++++++++++++++++++++++++++++++++++---- config.py | 46 +++++++++++++++++++++++++++++++----- config/config.yaml.example | 6 ++++- os_cloudgames.py | 2 +- setting.py | 4 ++++ 5 files changed, 94 insertions(+), 12 deletions(-) diff --git a/cloudgames.py b/cloudgames.py index 7222731..03ad651 100644 --- a/cloudgames.py +++ b/cloudgames.py @@ -35,20 +35,60 @@ def sign_account(self) -> str: elif data['retcode'] == -100: ret_msg = "云原神token失效/防沉迷" log.warning(ret_msg) - config.clear_cookie_cloudgame() + config.clear_cookie_cloudgame_genshin() else: ret_msg = f'脚本签到失败,json文本:{req.text}' log.warning(ret_msg) return ret_msg +class CloudZZZ: + def __init__(self, token) -> None: + self.headers = { + 'Host': 'cg-nap-api.mihoyo.com', + 'Accept': '*/*', + 'x-rpc-combo_token': token, + 'Accept-Encoding': 'gzip, deflate', + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Chrome/99.0.4844.84 Safari/537.36', + + } + + def sign_account(self) -> str: + ret_msg = "云绝区零:\r\n" + req = http.get(url=setting.cloud_zzz_sgin, headers=self.headers) + data = req.json() + if data['retcode'] == 0: + if int(data["data"]["free_time"]["send_freetime"]) > 0: + log.info(f'签到成功,已获得{data["data"]["free_time"]["send_freetime"]}分钟免费时长') + ret_msg += f'签到成功,已获得{data["data"]["free_time"]["send_freetime"]}分钟免费时长\n' + else: + log.info('签到失败,未获得免费时长,可能是已经签到过了或者超出免费时长上线') + ret_msg += '签到失败,未获得免费时长,可能是已经签到过了或者超出免费时长上线\n' + ret_msg += f'你当前拥有免费时长 {tools.time_conversion(int(data["data"]["free_time"]["free_time"]))} ,' \ + f'畅玩卡状态为 {data["data"]["play_card"]["short_msg"]},拥有邦邦点 {data["data"]["coin"]["coin_num"]} 个' + log.info(ret_msg) + elif data['retcode'] == -100: + ret_msg = "云绝区零token失效/防沉迷" + log.warning(ret_msg) + config.clear_cookie_cloudgame_zzz() + else: + ret_msg = f'脚本签到失败,json文本:{req.text}' + log.warning(ret_msg) + return ret_msg def run_task() -> str: ret_msg = "" cg_cn = config.config['cloud_games']['cn'] - if not cg_cn['genshin']['enable'] or cg_cn['genshin']['token'] == "": + if not cg_cn['enable']: return "" - cg_genshin = CloudGenshin(cg_cn['genshin']['token']) - ret_msg += cg_genshin.sign_account() + "\n\n" + # 云原神签到 + if cg_cn['genshin']['enable'] and cg_cn['genshin']['token'] != "": + cg_genshin = CloudGenshin(cg_cn['genshin']['token']) + ret_msg += cg_genshin.sign_account() + "\n\n" + # 云绝区零签到 + if cg_cn['zzz']['enable'] and cg_cn['zzz']['token'] != "": + cg_zzz = CloudZZZ(cg_cn['zzz']['token']) + ret_msg += cg_zzz.sign_account() + "\n\n" return ret_msg diff --git a/config.py b/config.py index 081b62b..cc76661 100644 --- a/config.py +++ b/config.py @@ -12,7 +12,7 @@ update_config_need = False config = { - 'enable': True, 'version': 12, "push": "", + 'enable': True, 'version': 13, "push": "", 'account': {'cookie': '', 'stuid': '', 'stoken': '', 'mid': ''}, 'device': {'name': 'Xiaomi MI 6', 'model': 'Mi 6', 'id': ''}, 'mihoyobbs': { @@ -44,7 +44,8 @@ 'cloud_games': { "cn": { "enable": False, - "genshin": {'enable': False, 'token': ""} + "genshin": {'enable': False, 'token': ""}, + "zzz": {'enable': False, 'token': ""} }, "os": { "enable": False, 'lang': 'zh-cn', @@ -154,6 +155,15 @@ def config_v11_update(data: dict): return new_config +def config_v12_update(data: dict): + global update_config_need + update_config_need = True + data['version'] = 13 + data['cloud_games']['cn']['zzz'] = {'enable': False, 'token': ""} + log.info("config已升级到: 13") + return data + + def load_config(p_path=None): global config if not p_path: @@ -169,6 +179,8 @@ def load_config(p_path=None): data = config_v10_update(data) if data['version'] == 11: data = config_v11_update(data) + if data['version'] == 12: + data = config_v12_update(data) save_config(p_config=data) # 去除cookie最末尾的空格 data["account"]["cookie"] = str(data["account"]["cookie"]).rstrip(' ') @@ -231,14 +243,36 @@ def disable_games(region: str = "cn"): save_config() -def clear_cookie_cloudgame(): +def clear_cookie_cloudgame_genshin(): + global config + if serverless: + log.info("云函数执行,无法保存") + return None + config['cloud_games']['cn']['genshin']["enable"] = False + config['cloud_games']['cn']['genshin']['token'] = "" + log.info("国服云原神Cookie删除完毕") + save_config() + + +def clear_cookie_cloudgame_genshin_os(): + global config + if serverless: + log.info("云函数执行,无法保存") + return None + config['cloud_games']['os']['genshin']["enable"] = False + config['cloud_games']['os']['genshin']['token'] = "" + log.info("国际服云原神Cookie删除完毕") + save_config() + + +def clear_cookie_cloudgame_zzz(): global config if serverless: log.info("云函数执行,无法保存") return None - config['cloud_games']['genshin']["enable"] = False - config['cloud_games']['genshin']['token'] = "" - log.info("云原神Cookie删除完毕") + config['cloud_games']['cn']['zzz']["enable"] = False + config['cloud_games']['cn']['zzz']['token'] = "" + log.info("国服云绝区零Cookie删除完毕") save_config() diff --git a/config/config.yaml.example b/config/config.yaml.example index cb32916..6eae57a 100644 --- a/config/config.yaml.example +++ b/config/config.yaml.example @@ -1,7 +1,7 @@ #这里控制整个config文件是否启用 enable: true #config的版本 -version: 12 +version: 13 # todo功能 push: "" account: @@ -101,6 +101,10 @@ cloud_games: enable: false #这里填入抓包获得的token,支持多个 token: "" + #云绝区零 + zzz: + enable: false + token: "" os: lang: "zh-cn" enable: false diff --git a/os_cloudgames.py b/os_cloudgames.py index c0b1ed2..31f889d 100644 --- a/os_cloudgames.py +++ b/os_cloudgames.py @@ -37,7 +37,7 @@ def sign_account(self) -> str: elif data['retcode'] == -100: ret_msg = "云原神token失效" log.warning(ret_msg) - config.clear_cookie_cloudgame() + config.clear_cookie_cloudgame_genshin_os() else: ret_msg = f'脚本签到失败,json文本:{req.text}' log.warning(ret_msg) diff --git a/setting.py b/setting.py index 1ee990b..2209f97 100644 --- a/setting.py +++ b/setting.py @@ -126,6 +126,10 @@ cloud_genshin_api = "https://api-cloudgame.mihoyo.com" cloud_genshin_sgin = f"{cloud_genshin_api}/hk4e_cg_cn/wallet/wallet/get" +# 云绝区零相关api +cloud_zzz_api = "https://cg-nap-api.mihoyo.com" +cloud_zzz_sgin = f"{cloud_zzz_api}/nap_cn/cg/wallet/wallet/get" + # 接下来是国际服的内容 os_referer_url = "https://act.hoyolab.com/" os_genshin_act_id = "e202102251931481" From 2b2e99890b6bd4e634a7e8f624fee703a0868b24 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Fri, 13 Dec 2024 15:02:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor(config):=20=20=E7=A7=BB=E9=99=A4co?= =?UTF-8?q?nfig=20v8=E7=9A=84=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/config.py b/config.py index cc76661..a69a20d 100644 --- a/config.py +++ b/config.py @@ -73,20 +73,7 @@ def copy_config(): return config_raw -def config_v9_update(data: dict): - global update_config_need - update_config_need = True - data['version'] = 9 - data['games']['os'] = { - 'enable': False, 'cookie': '', - 'genshin': {'auto_checkin': False, 'black_list': []}, - 'honkai_sr': {'auto_checkin': False, 'black_list': []} - } - log.info("config已升级到: 9") - return data - - -def config_v9_update_to_v12(data: dict): +def config_v9_update_to_v13(data: dict): global update_config_need update_config_need = True base_config = deepcopy(config_raw) @@ -119,7 +106,7 @@ def config_v9_update_to_v12(data: dict): base_config['cloud_games']['cn']['enable'] = data['cloud_games']['genshin']['enable'] base_config['cloud_games']['cn']['genshin']['enable'] = data['cloud_games']['genshin']['enable'] base_config['cloud_games']['cn']['genshin']['token'] = data['cloud_games']['genshin']['token'] - log.info("config已升级到: 12") + log.info("config已升级到: 13") return base_config @@ -139,7 +126,7 @@ def config_v10_update(data: dict): def config_v11_update(data: dict): global update_config_need update_config_need = True - data['version'] = 12 + data['version'] = 13 new_config = {} for key in data: if key == "account": @@ -151,7 +138,7 @@ def config_v11_update(data: dict): new_config['cloud_games']['cn']['enable'] = data['cloud_games']['genshin']['enable'] new_config['cloud_games']['cn']['genshin']['enable'] = data['cloud_games']['genshin']['enable'] new_config['cloud_games']['cn']['genshin']['token'] = data['cloud_games']['genshin']['token'] - log.info("config已升级到: 12") + log.info("config已升级到: 13") return new_config @@ -171,10 +158,8 @@ def load_config(p_path=None): with open(p_path, "r", encoding='utf-8') as f: data = yaml.load(f, Loader=yaml.FullLoader) if data['version'] != config_raw['version']: - if data['version'] == 8: - data = config_v9_update(data) if data['version'] == 9: - data = config_v9_update_to_v12(data) + data = config_v9_update_to_v13(data) if data['version'] == 10: data = config_v10_update(data) if data['version'] == 11: