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/6] =?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/6] =?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/6] 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 From f4b2433fd9e1074a45dd42633f96fa61c052a9e8 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 28 Aug 2022 17:30:28 +0800 Subject: [PATCH 4/6] =?UTF-8?q?config=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 39 +++++++++++++++++++++++++++++++++----- config/config.yaml.example | 9 +++++---- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/config.py b/config.py index b0f04cf..aa23d14 100644 --- a/config.py +++ b/config.py @@ -9,7 +9,7 @@ serverless = False update_config_need = False config = { - 'enable': True, 'version': 6, + 'enable': True, 'version': 7, 'account': { 'cookie': '', 'login_ticket': '', @@ -35,9 +35,11 @@ config = { 'genshin': {'auto_checkin': False, 'black_list': []} } }, - 'cloud_genshin': { - 'token': '', - 'enable': False + 'cloud_games': { + "genshin": { + 'enable': False, + 'token': '' + } } } @@ -93,10 +95,24 @@ def update_config(): log.error("请本地更新一下config") +def config_v7_update(data: dict): + global update_config_need + update_config_need = True + data['version'] = 7 + data['cloud_games'] = {"genshin": {'enable': False, 'token': ''}} + log.info("config已升级到: 7") + return data + + def load_config(): global config with open(config_Path, "r", encoding='utf-8') as f: - config = yaml.load(f, Loader=yaml.FullLoader) + data = yaml.load(f, Loader=yaml.FullLoader) + if data['version'] == 7: + config = data + else: + config = config_v7_update(data) + save_config() log.info("Config加载完毕") @@ -143,6 +159,18 @@ def clear_cookies(): log.info("Cookie删除完毕") +def clear_cookie_cloudgame(): + global config + global serverless + if serverless: + log.info("云函数执行,无法保存") + return None + config['cloud_games']['genshin']["enable"] = False + config['cloud_games']['genshin']['token'] = "" + log.info("云原神Cookie删除完毕") + save_config() + + if __name__ == "__main__": # 初始化配置文件 # try: @@ -153,4 +181,5 @@ if __name__ == "__main__": # pass # save_config() # update_config() + load_config() pass diff --git a/config/config.yaml.example b/config/config.yaml.example index abc3efe..a29e814 100644 --- a/config/config.yaml.example +++ b/config/config.yaml.example @@ -1,5 +1,5 @@ enable: true #这里控制整个config文件是否启用 -version: 6 #config的版本 +version: 7 #config的版本 account: cookie: "" #登入账号只需要修改这里就行了,下面会自动获取 login_ticket: "" @@ -39,6 +39,7 @@ games: genshin: auto_checkin: false black_list: [] -cloud_genshin: - token: '' - enable: true \ No newline at end of file +cloud_games: #云游戏专区 + genshin: #云原神 + enable: true #开启签到 + token: "" #这里填入抓包获得的token From 858d425d15a0b3742c0d52a975c7942e53e1329a Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 28 Aug 2022 17:31:01 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BA=91=E5=8E=9F=E7=A5=9E=E7=AD=BE?= =?UTF-8?q?=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloud_genshin.py | 54 +++++++++++++++++++++++++++--------------------- main.py | 12 +++++------ setting.py | 7 +++---- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/cloud_genshin.py b/cloud_genshin.py index e74afba..2643122 100644 --- a/cloud_genshin.py +++ b/cloud_genshin.py @@ -1,18 +1,17 @@ -import setting -from request import http import tools import config +import setting +from request import http from loghelper import log - -class cloud_ys(): - def __init__(self,token) -> None: +class CloudGenshin: + def __init__(self) -> None: self.headers = { - 'x-rpc-combo_token': token, + 'x-rpc-combo_token': config.config['cloud_games']['genshin']['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-sys_version': '12', 'x-rpc-channel': 'mihoyo', 'x-rpc-device_id': tools.get_device_id(), 'x-rpc-device_name': 'Xiaomi M2012K11AC', @@ -25,20 +24,27 @@ class cloud_ys(): '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 + def sign_account(self): + ret_msg = "云原神:\r\n" + req = http.get(url=setting.cloud_genshin_Inquire, headers=self.headers) + data = req.json() + if data['retcode'] == 0: + if req["data"]["free_time"]['free_time'] == '0': + log.info('签到失败,未获得免费时长,可能是已经签到过了或者超出免费时长上线') + else: + log.info(f'签到成功,已获得{data["data"]["free_time"]["free_time"]}分钟免费时长') + ret_msg = f'你当前拥有免费时长 {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() + else: + ret_msg = f'脚本签到失败,json文本:{req.text}' + log.warning(ret_msg) + return ret_msg + + +if __name__ == '__main__': + pass diff --git a/main.py b/main.py index 3dda549..eba661b 100644 --- a/main.py +++ b/main.py @@ -96,14 +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']: + if config.config['cloud_games']['genshin']["enable"]: log.info("正在进行云原神签到") - if config.config['cloud_genshin']['token'] == "": + if config.config['cloud_games']['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 + cloud_ys = cloud_genshin.CloudGenshin() + data = cloud_ys.sign_account() + return_data += "\n\n" + data return ret_code, return_data elif config.config["account"]["cookie"] == "CookieError": raise CookieError('Cookie expires') @@ -122,4 +122,4 @@ if __name__ == "__main__": message = "账号Cookie出错!" log.error("账号Cookie有问题!") push.push(status_code, message) -pass \ No newline at end of file +pass diff --git a/setting.py b/setting.py index b8ddc70..cdbebcc 100644 --- a/setting.py +++ b/setting.py @@ -7,7 +7,7 @@ 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" # 米游社的分区列表 @@ -78,7 +78,6 @@ 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列表 @@ -116,5 +115,5 @@ genshin_Is_signurl = web_Api + "/event/bbs_sign_reward/info?act_id={}®ion={}& 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 +cloud_genshin_Api = "https://api-cloudgame.mihoyo.com" +cloud_genshin_Inquire = cloud_genshin_Api + "/hk4e_cg_cn/wallet/wallet/get" From d74eeae1a0b18c309e4d2f0ceb1fcdb6427661f4 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 28 Aug 2022 17:36:43 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BA=91=E5=87=BD=E6=95=B0=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=A4=84=E7=90=86&=E9=98=B2=E6=AD=A2httpx=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- requirements_qcloud.txt | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 requirements_qcloud.txt diff --git a/README.md b/README.md index 33d09e6..fc80cef 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ docker-compose pull && docker-compose up -d 1. 下载本项目 -2. 在脚本目录执行`pip3 install -r requirements.txt -t .` +2. 在脚本目录执行`pip3 install -r requirements_qcloud.txt -t .` 3. 在本地完整运行一次。 @@ -152,7 +152,7 @@ docker-compose pull && docker-compose up -d * 阿里云 1. 下载本项目 - 2. 在脚本目录执行`pip3 install -r requirements.txt -t .` + 2. 在脚本目录执行`pip3 install -r requirements.txt -t .`,如果无法选择`Python3.9`环境请执行`pip3 install -r requirements_qcloud.txt -t .` 3. 在本地完整运行一次。 4. 打开并登录[函数计算 FC](https://fcnext.console.aliyun.com/cn-hangzhou/services)。注意左上方显示的地区,可点击切换其他地区。 5. 创建服务 (日志功能可能产生费用,建议关闭) diff --git a/requirements_qcloud.txt b/requirements_qcloud.txt new file mode 100644 index 0000000..37ca3e1 --- /dev/null +++ b/requirements_qcloud.txt @@ -0,0 +1,2 @@ +requests>=2.26.0 +PyYAML~=6.0 \ No newline at end of file