From fc262e2a916de8e448ddeec9c16505fc2c44db22 Mon Sep 17 00:00:00 2001 From: clover420 <748883120@qq.com> Date: Sat, 27 Aug 2022 21:51:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E4=BA=91=E5=8E=9F=E7=A5=9E=E7=AD=BE=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloud_genshin.py | 44 ++++++++++++++++++++++++++++++++++++++ config.py | 7 ++++++ config/config.yaml.example | 3 +++ main.py | 11 +++++++++- setting.py | 8 +++++++ tools.py | 3 +++ 6 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 cloud_genshin.py diff --git a/cloud_genshin.py b/cloud_genshin.py new file mode 100644 index 0000000..78f89af --- /dev/null +++ b/cloud_genshin.py @@ -0,0 +1,44 @@ +import setting +from request import http +import tools +import config +from loghelper import log + + + +class cloud_ys(): + def __init__(self,token) -> None: + self.headers = { + 'x-rpc-combo_token': token, + 'x-rpc-client_type': setting.mihoyobbs_Client_type, + 'x-rpc-app_version': setting.cloudgenshin_Version, + 'x-rpc-sys_version': '12', # Previous version need to convert the type of this var + 'x-rpc-channel': 'mihoyo', + 'x-rpc-device_id': tools.get_cloud_device_id(), + 'x-rpc-device_name': 'Xiaomi M2012K11AC', + 'x-rpc-device_model': 'M2012K11AC', + 'x-rpc-app_id': '1953439974', + 'Referer': 'https://app.mihoyo.com', + 'Host': 'api-cloudgame.mihoyo.com', + 'Connection': 'Keep-Alive', + 'Accept-Encoding': 'gzip', + 'User-Agent': 'okhttp/4.9.0' + } + + def Sgin(self): + req = http.get(url=setting.Cloud_Ys_Sgin,headers=self.headers).json() + try: + jg = req['data']['list'][0]['msg'] + if "每日登录奖励" in jg: + log.info("云原神签到成功") + data = "云原神签到成功" + except IndexError: + log.warning("云原神签到失败或重复签到") + data = "云原神签到失败或重复签到" + except Exception as er: + log.warning(f"云原神签到失败,出现了错误:{er}") + data = f"云原神签到失败,出现了错误:{er}" + reqs = http.get(url=setting.Cloud_ys_Inquire,headers=self.headers).json() + nr = (f"\n你当前拥有免费时长 {reqs['data']['free_time']['free_time']} 分钟,畅玩卡状态为 {reqs['data']['play_card']['short_msg']},拥有米云币 {reqs['data']['coin']['coin_num']} 枚") + data = data + nr + return data \ No newline at end of file diff --git a/config.py b/config.py index 12fc525..b0f04cf 100644 --- a/config.py +++ b/config.py @@ -34,6 +34,10 @@ config = { 'enable': False, 'cookie': '', 'genshin': {'auto_checkin': False, 'black_list': []} } + }, + 'cloud_genshin': { + 'token': '', + 'enable': False } } @@ -78,6 +82,9 @@ def update_config(): continue config['games']['cn'][i] = config_json['games']['cn'][i] config['games']['os'] = config_json['games']['os'] + config['cloud_genshin']['token'] = config_json['cloud_genshin']['token'] + config['cloud_genshin']['enable'] = config_json['cloud_genshin']['enable'] + print(config) save_config() log.info('config更新完毕') if not serverless: diff --git a/config/config.yaml.example b/config/config.yaml.example index 2ce131c..abc3efe 100644 --- a/config/config.yaml.example +++ b/config/config.yaml.example @@ -39,3 +39,6 @@ games: genshin: auto_checkin: false black_list: [] +cloud_genshin: + token: '' + enable: true \ No newline at end of file diff --git a/main.py b/main.py index f5a8c6d..3dda549 100644 --- a/main.py +++ b/main.py @@ -10,6 +10,7 @@ import setting import mihoyobbs import honkai3rd import tearsofthemis +import cloud_genshin from error import * from loghelper import log @@ -95,6 +96,14 @@ def main(): ret_code = 3 return_data += "\n\n" + genshin_message time.sleep(random.randint(2, 8)) + if config.config['cloud_genshin']['enable']: + log.info("正在进行云原神签到") + if config.config['cloud_genshin']['token'] == "": + log.info("token为空,跳过任务") + else: + cloud_ys = cloud_genshin.cloud_ys(config.config['cloud_genshin']['token']) + data = cloud_ys.Sgin() + return_data += "\n\n云原神:\n"+data return ret_code, return_data elif config.config["account"]["cookie"] == "CookieError": raise CookieError('Cookie expires') @@ -113,4 +122,4 @@ if __name__ == "__main__": message = "账号Cookie出错!" log.error("账号Cookie有问题!") push.push(status_code, message) -pass +pass \ No newline at end of file diff --git a/setting.py b/setting.py index e9026bd..b8ddc70 100644 --- a/setting.py +++ b/setting.py @@ -7,6 +7,9 @@ mihoyobbs_Version = "2.35.2" # Slat和Version相互对应 # 米游社的客户端类型 mihoyobbs_Client_type = "2" # 1为ios 2为安卓 mihoyobbs_Client_type_web = "5" # 4为pc web 5为mobile web +#云原神版本 +cloudgenshin_Version = "3.0.0" + # 米游社的分区列表 mihoyobbs_List = [{ "id": "1", @@ -75,6 +78,7 @@ headers = { # 通用设置 bbs_Api = "https://bbs-api.mihoyo.com" web_Api = "https://api-takumi.mihoyo.com" +Cloud_Ys_Api = "https://api-cloudgame.mihoyo.com" account_Info_url = web_Api + "/binding/api/getUserGameRolesByCookie?game_biz=" # 米游社的API列表 @@ -110,3 +114,7 @@ genshin_Act_id = "e202009291139501" genshin_checkin_rewards = f'{web_Api}/event/bbs_sign_reward/home?act_id={genshin_Act_id}' genshin_Is_signurl = web_Api + "/event/bbs_sign_reward/info?act_id={}®ion={}&uid={}" genshin_Signurl = web_Api + "/event/bbs_sign_reward/sign" + +# 云原神相关api +Cloud_Ys_Sgin = Cloud_Ys_Api + "/hk4e_cg_cn/gamer/api/listNotifications?status=NotificationStatusUnread&type=NotificationTypePopup&is_sort=true" +Cloud_ys_Inquire = Cloud_Ys_Api + "/hk4e_cg_cn/wallet/wallet/get" \ No newline at end of file diff --git a/tools.py b/tools.py index 25dfb9e..22b76bc 100644 --- a/tools.py +++ b/tools.py @@ -50,6 +50,9 @@ def get_ds2(q: str, b: str) -> str: def get_device_id() -> str: return str(uuid.uuid3(uuid.NAMESPACE_URL, config.config["account"]["cookie"])) +# 生成一个device id +def get_cloud_device_id() -> str: + return str(uuid.uuid3(uuid.NAMESPACE_URL, "ai=4;ci=1;oi=74192553;ct=78851ef4251e14fb45659a5276370b819ab9f47b;si=f8bc714db618c290b05c1949c654e6e4fb38edb49831e3a2b75455dfa8812320;bi=hk4e_cn")) # 获取签到的奖励名称 def get_item(raw_data: dict) -> str: From 87b3ae0ccb2cc2fbd5f843f1907495f0d2af3fb1 Mon Sep 17 00:00:00 2001 From: clover420 <748883120@qq.com> Date: Sat, 27 Aug 2022 21:57:24 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools.py b/tools.py index 22b76bc..3527e60 100644 --- a/tools.py +++ b/tools.py @@ -50,10 +50,6 @@ def get_ds2(q: str, b: str) -> str: def get_device_id() -> str: return str(uuid.uuid3(uuid.NAMESPACE_URL, config.config["account"]["cookie"])) -# 生成一个device id -def get_cloud_device_id() -> str: - return str(uuid.uuid3(uuid.NAMESPACE_URL, "ai=4;ci=1;oi=74192553;ct=78851ef4251e14fb45659a5276370b819ab9f47b;si=f8bc714db618c290b05c1949c654e6e4fb38edb49831e3a2b75455dfa8812320;bi=hk4e_cn")) - # 获取签到的奖励名称 def get_item(raw_data: dict) -> str: temp_name = raw_data["name"] From a1f76e15e081354a0c115ec720241b918d340975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=AF=E7=81=AB=E9=98=91=E7=8F=8A?= <47273274+clover1420@users.noreply.github.com> Date: Sat, 27 Aug 2022 22:13:05 +0800 Subject: [PATCH 3/3] Update cloud_genshin.py --- cloud_genshin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cloud_genshin.py b/cloud_genshin.py index 78f89af..e74afba 100644 --- a/cloud_genshin.py +++ b/cloud_genshin.py @@ -14,7 +14,7 @@ class cloud_ys(): 'x-rpc-app_version': setting.cloudgenshin_Version, 'x-rpc-sys_version': '12', # Previous version need to convert the type of this var 'x-rpc-channel': 'mihoyo', - 'x-rpc-device_id': tools.get_cloud_device_id(), + 'x-rpc-device_id': tools.get_device_id(), 'x-rpc-device_name': 'Xiaomi M2012K11AC', 'x-rpc-device_model': 'M2012K11AC', 'x-rpc-app_id': '1953439974', @@ -41,4 +41,4 @@ class cloud_ys(): reqs = http.get(url=setting.Cloud_ys_Inquire,headers=self.headers).json() nr = (f"\n你当前拥有免费时长 {reqs['data']['free_time']['free_time']} 分钟,畅玩卡状态为 {reqs['data']['play_card']['short_msg']},拥有米云币 {reqs['data']['coin']['coin_num']} 枚") data = data + nr - return data \ No newline at end of file + return data