diff --git a/cloud_genshin.py b/cloud_genshin.py new file mode 100644 index 0000000..e74afba --- /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_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 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..3527e60 100644 --- a/tools.py +++ b/tools.py @@ -50,7 +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"])) - # 获取签到的奖励名称 def get_item(raw_data: dict) -> str: temp_name = raw_data["name"]