Skip to content

Commit

Permalink
Merge pull request #214 from owwkmidream/feat-CloudZZZ
Browse files Browse the repository at this point in the history
增加云绝区零签到,升级配置文件v13
  • Loading branch information
Womsxd authored Dec 13, 2024
2 parents a34ecbf + 2b2e998 commit 3f2e12f
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 32 deletions.
48 changes: 44 additions & 4 deletions cloudgames.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
71 changes: 45 additions & 26 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -72,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)
Expand Down Expand Up @@ -118,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


Expand All @@ -138,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":
Expand All @@ -150,25 +138,34 @@ 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


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:
p_path = config_Path
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:
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(' ')
Expand Down Expand Up @@ -231,14 +228,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()


Expand Down
6 changes: 5 additions & 1 deletion config/config.yaml.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#这里控制整个config文件是否启用
enable: true
#config的版本
version: 12
version: 13
# todo功能
push: ""
account:
Expand Down Expand Up @@ -101,6 +101,10 @@ cloud_games:
enable: false
#这里填入抓包获得的token,支持多个
token: ""
#云绝区零
zzz:
enable: false
token: ""
os:
lang: "zh-cn"
enable: false
Expand Down
2 changes: 1 addition & 1 deletion os_cloudgames.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3f2e12f

Please sign in to comment.