OS server support #25
Some checks are pending
SyncMirror / sync (push) Waiting to run

This commit is contained in:
GamerNoTitle 2024-09-20 07:40:47 +08:00
parent 62e19837aa
commit f90b99a6d4
2 changed files with 139 additions and 87 deletions

View File

@ -21,8 +21,10 @@ accounts:
# devicemodel: 手机抓的填抓出来的手机型号,大概为手机厂商+上面的deviceid如红米K40为Xiaomi M2012K11AC # devicemodel: 手机抓的填抓出来的手机型号,大概为手机厂商+上面的deviceid如红米K40为Xiaomi M2012K11AC
# 如果是网页版抓的填Unknown # 如果是网页版抓的填Unknown
devicemodel: devicemodel:
# appid: 手机抓的固定填1953439974网页版抓的留空 # appid: 国服手机抓的固定填1953439974网页版抓的留空国际服手机抓的填9000254
appid: appid:
# region(可选): 账号所处的地区国服填cn国际服填os不填或非法值按国服处理
region: cn
# 第二个账号,不需要的话把下面删掉,如果需要更多就在下面再加 # 第二个账号,不需要的话把下面删掉,如果需要更多就在下面再加
- token: - token:
# 关于type如果你在安卓版的云·原神里面抓的话type应该是2 # 关于type如果你在安卓版的云·原神里面抓的话type应该是2
@ -41,5 +43,7 @@ accounts:
# devicemodel: 手机抓的填抓出来的手机型号,大概为手机厂商+上面的deviceid如红米K40为Xiaomi M2012K11AC # devicemodel: 手机抓的填抓出来的手机型号,大概为手机厂商+上面的deviceid如红米K40为Xiaomi M2012K11AC
# 如果是网页版抓的填Unknown # 如果是网页版抓的填Unknown
devicemodel: devicemodel:
# appid: 手机抓的固定填1953439974网页版抓的留空 # appid: 国服手机抓的固定填1953439974网页版抓的留空国际服手机抓的填9000254
appid: appid:
# region(可选): 账号所处的地区国服填cn国际服填os不填或非法值按国服处理
region: os

216
main.py
View File

@ -1,4 +1,5 @@
import requests as r import requests as r
import httpx
import json import json
import os import os
import re import re
@ -7,6 +8,7 @@ import random
import time import time
import yaml import yaml
def ReadConf(variable_name, default_value=None): def ReadConf(variable_name, default_value=None):
# Try to get the variable from the environment # Try to get the variable from the environment
env_value = os.environ.get(variable_name) env_value = os.environ.get(variable_name)
@ -17,110 +19,157 @@ def ReadConf(variable_name, default_value=None):
# If not found in environment, try to read from config.yml # If not found in environment, try to read from config.yml
try: try:
with open("config.yml", "r", encoding='utf-8') as config_file: with open("config.yml", "r", encoding="utf-8") as config_file:
config_data = yaml.load(config_file, Loader=yaml.FullLoader) config_data = yaml.load(config_file, Loader=yaml.FullLoader)
return config_data return config_data
except FileNotFoundError: except FileNotFoundError:
return default_value return default_value
sentry_sdk.init( sentry_sdk.init(
"https://425d7b4536f94c9fa540fe34dd6609a2@o361988.ingest.sentry.io/6352584", "https://425d7b4536f94c9fa540fe34dd6609a2@o361988.ingest.sentry.io/6352584",
# Set traces_sample_rate to 1.0 to capture 100% # Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring. # of transactions for performance monitoring.
# We recommend adjusting this value in production. # We recommend adjusting this value in production.
traces_sample_rate=1.0 traces_sample_rate=1.0,
) )
conf = ReadConf('MHYY_CONFIG')['accounts'] conf = ReadConf("MHYY_CONFIG")["accounts"]
if not conf: if not conf:
print('请正确配置环境变量或者config.yml后再运行本脚本') print("请正确配置环境变量或者config.yml后再运行本脚本")
os._exit(0) os._exit(0)
print(f'检测到 {len(conf)} 个账号,正在进行任务……') print(f"检测到 {len(conf)} 个账号,正在进行任务……")
# Options # Options
sct_status = os.environ.get('sct') # https://sct.ftqq.com/ sct_status = os.environ.get("sct") # https://sct.ftqq.com/
sct_key = os.environ.get('sct_key') sct_key = os.environ.get("sct_key")
sct_url = f'https://sctapi.ftqq.com/{sct_key}.send?title=MHYY-AutoCheckin 自动推送' sct_url = f"https://sctapi.ftqq.com/{sct_key}.send?title=MHYY-AutoCheckin 自动推送"
sct_msg = '' sct_msg = ""
class RunError(Exception): class RunError(Exception):
pass pass
try: if __name__ == "__main__":
ver_info = r.get('https://sdk-static.mihoyo.com/hk4e_cn/mdk/launcher/api/resource?key=eYd89JmJ&launcher_id=18', timeout=60).text # if not os.environ.get("MHYY_DEBUG", False):
version = json.loads(ver_info)['data']['game']['latest']['version'] # wait_time = random.randint(1, 3600) # Random Sleep to Avoid Ban
print(f'从官方API获取到云·原神最新版本号{version}') # print(f'为了避免同一时间签到人数太多导致被官方怀疑,开始休眠 {wait_time} 秒')
except: # time.sleep(wait_time)
version = '4.3.0'
NotificationURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/listNotifications?status=NotificationStatusUnread&type=NotificationTypePopup&is_sort=true' try:
WalletURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/wallet/wallet/get' ver_info = httpx.get(
AnnouncementURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/getAnnouncementInfo' "https://hyp-api.mihoyo.com/hyp/hyp-connect/api/getGamePackages?game_ids[]=1Z8W5NHUQb&launcher_id=jGHBHlcOq1",
timeout=60,
verify=False,
).text
version = json.loads(ver_info)["data"]["game_packages"][0]["main"]["major"][
"version"
]
print(f"从官方API获取到云·原神最新版本号{version}")
except:
version = "5.0.0"
if __name__ == '__main__':
for config in conf: for config in conf:
if config == '': # 各种API的URL
NotificationURL = "https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/listNotifications?status=NotificationStatusUnread&type=NotificationTypePopup&is_sort=true"
WalletURL = "https://api-cloudgame.mihoyo.com/hk4e_cg_cn/wallet/wallet/get"
AnnouncementURL = (
"https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/getAnnouncementInfo"
)
if config == "":
# Verify config # Verify config
raise RunError( raise RunError(
f"请在Settings->Secrets->Actions页面中新建名为config的变量并将你的配置填入后再运行") f"请在Settings->Secrets->Actions页面中新建名为config的变量并将你的配置填入后再运行"
)
else: else:
token = config['token'] token = config["token"]
client_type = config['type'] client_type = config["type"]
sysver = config['sysver'] sysver = config["sysver"]
deviceid = config['deviceid'] deviceid = config["deviceid"]
devicename = config['devicename'] devicename = config["devicename"]
devicemodel = config['devicemodel'] devicemodel = config["devicemodel"]
appid = config['appid'] appid = config["appid"]
headers = { headers = {
'x-rpc-combo_token': token, "x-rpc-combo_token": token,
'x-rpc-client_type': str(client_type), "x-rpc-client_type": str(client_type),
'x-rpc-app_version': str(version), "x-rpc-app_version": str(version),
'x-rpc-sys_version': str(sysver), # Previous version need to convert the type of this var "x-rpc-sys_version": str(
'x-rpc-channel': 'cyydmihoyo', sysver
'x-rpc-device_id': deviceid, ), # Previous version need to convert the type of this var
'x-rpc-device_name': devicename, "x-rpc-channel": "cyydmihoyo",
'x-rpc-device_model': devicemodel, "x-rpc-device_id": deviceid,
'x-rpc-vendor_id': '1', # 2023/8/31更新不知道作用 "x-rpc-device_name": devicename,
'x-rpc-cg_game_biz': 'hk4e_cn', # 游戏频道,国服就是这个 "x-rpc-device_model": devicemodel,
'x-rpc-op_biz': 'clgm_cn', # 2023/8/31更新不知道作用 "x-rpc-vendor_id": "1", # 2023/8/31更新不知道作用
'x-rpc-language': 'zh-cn', "x-rpc-cg_game_biz": "hk4e_cn", # 游戏频道,国服就是这个
'Host': 'api-cloudgame.mihoyo.com', "x-rpc-op_biz": "clgm_cn", # 2023/8/31更新不知道作用
'Connection': 'Keep-Alive', "x-rpc-language": "zh-cn",
'Accept-Encoding': 'gzip', "Host": "api-cloudgame.mihoyo.com",
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0' "Connection": "Keep-Alive",
"Accept-Encoding": "gzip",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0",
} }
bbsid = re.findall(r'oi=[0-9]+', token)[0].replace('oi=', '') bbsid = re.findall(r"oi=[0-9]+", token)[0].replace("oi=", "")
wait_time = random.randint(1, 3600) # Random Sleep to Avoid Ban if config.get("region", "cn") == "os":
print(f'为了避免同一时间签到人数太多导致被官方怀疑,开始休眠 {wait_time}') # 国际服处理
time.sleep(wait_time) headers["x-rpc-channel"] = "mihoyo"
wallet = r.get(WalletURL, headers=headers, timeout=60) headers["x-rpc-cg_game_biz"] = "hk4e_global"
if json.loads(wallet.text) == {"data": None,"message":"登录已失效,请重新登录","retcode":-100}: headers["x-rpc-op_biz"] = "clgm_global"
print(f'当前登录已过期,请重新登陆!返回为:{wallet.text}') headers["x-rpc-cg_game_id"] = "9000254"
sct_msg += f'当前登录已过期,请重新登陆!返回为:{wallet.text}' headers["x-rpc-app_id"] = "600493"
# 国际服URL
NotificationURL = "https://sg-cg-api.hoyoverse.com/hk4e_global/cg/gamer/api/listNotifications?status=NotificationStatusUnread&type=NotificationTypePopup&is_sort=true"
WalletURL = (
"https://sg-cg-api.hoyoverse.com/hk4e_global/cg/wallet/wallet/get"
)
AnnouncementURL = "https://sg-cg-api.hoyoverse.com/hk4e_global/cg/gamer/api/getAnnouncementInfo"
wallet = httpx.get(WalletURL, headers=headers, timeout=60, verify=False)
print(wallet.text)
if json.loads(wallet.text) == {
"data": None,
"message": "登录已失效,请重新登录",
"retcode": -100,
}:
print(f"当前登录已过期,请重新登陆!返回为:{wallet.text}")
sct_msg += f"当前登录已过期,请重新登陆!返回为:{wallet.text}"
else: else:
print( print(
f"你当前拥有免费时长 {json.loads(wallet.text)['data']['free_time']['free_time']} 分钟,畅玩卡状态为 {json.loads(wallet.text)['data']['play_card']['short_msg']},拥有米云币 {json.loads(wallet.text)['data']['coin']['coin_num']}") f"你当前拥有免费时长 {json.loads(wallet.text)['data']['free_time']['free_time']} 分钟,畅玩卡状态为 {json.loads(wallet.text)['data']['play_card']['short_msg']},拥有米云币 {json.loads(wallet.text)['data']['coin']['coin_num']}"
)
sct_msg += f"你当前拥有免费时长 {json.loads(wallet.text)['data']['free_time']['free_time']} 分钟,畅玩卡状态为 {json.loads(wallet.text)['data']['play_card']['short_msg']},拥有米云币 {json.loads(wallet.text)['data']['coin']['coin_num']}" sct_msg += f"你当前拥有免费时长 {json.loads(wallet.text)['data']['free_time']['free_time']} 分钟,畅玩卡状态为 {json.loads(wallet.text)['data']['play_card']['short_msg']},拥有米云币 {json.loads(wallet.text)['data']['coin']['coin_num']}"
announcement = r.get(AnnouncementURL, headers=headers, timeout=60) announcement = httpx.get(
AnnouncementURL, headers=headers, timeout=60, verify=False
)
print(f'获取到公告列表:{json.loads(announcement.text)["data"]}') print(f'获取到公告列表:{json.loads(announcement.text)["data"]}')
res = r.get(NotificationURL, headers=headers, timeout=60) res = httpx.get(NotificationURL, headers=headers, timeout=60, verify=False)
success,Signed = False,False success, Signed = False, False
try: try:
if list(json.loads(res.text)['data']['list']) == []: if list(json.loads(res.text)["data"]["list"]) == []:
success = True success = True
Signed = True Signed = True
Over = False Over = False
elif json.loads(json.loads(res.text)['data']['list'][0]['msg']) == {"num": 15, "over_num": 0, "type": 2, "msg": "每日登录奖励", "func_type": 1}: elif json.loads(json.loads(res.text)["data"]["list"][0]["msg"]) == {
"num": 15,
"over_num": 0,
"type": 2,
"msg": "每日登录奖励",
"func_type": 1,
}:
success = True success = True
Signed = False Signed = False
Over = False Over = False
elif json.loads(json.loads(res.text)['data']['list'][0]['msg'])['over_num'] > 0: elif (
json.loads(json.loads(res.text)["data"]["list"][0]["msg"])[
"over_num"
]
> 0
):
success = True success = True
Signed = False Signed = False
Over = True Over = True
@ -130,38 +179,37 @@ if __name__ == '__main__':
success = False success = False
if success: if success:
if Signed: if Signed:
print( print(f"获取签到情况成功!今天是否已经签到过了呢?")
f'获取签到情况成功!今天是否已经签到过了呢?') sct_msg += f"获取签到情况成功!今天是否已经签到过了呢?"
sct_msg += f'获取签到情况成功!今天是否已经签到过了呢?' print(f"完整返回体为:{res.text}")
print(f'完整返回体为:{res.text}')
elif not Signed and Over: elif not Signed and Over:
print( print(
f'获取签到情况成功!当前免费时长已经达到上限!签到情况为{json.loads(res.text)["data"]["list"][0]["msg"]}') f'获取签到情况成功!当前免费时长已经达到上限!签到情况为{json.loads(res.text)["data"]["list"][0]["msg"]}'
)
sct_msg += f'获取签到情况成功!当前免费时长已经达到上限!签到情况为{json.loads(res.text)["data"]["list"][0]["msg"]}' sct_msg += f'获取签到情况成功!当前免费时长已经达到上限!签到情况为{json.loads(res.text)["data"]["list"][0]["msg"]}'
print(f'完整返回体为:{res.text}') print(f"完整返回体为:{res.text}")
else: else:
print( print(
f'获取签到情况成功!当前签到情况为{json.loads(res.text)["data"]["list"][0]["msg"]}') f'获取签到情况成功!当前签到情况为{json.loads(res.text)["data"]["list"][0]["msg"]}'
)
sct_msg += f'获取签到情况成功!当前签到情况为{json.loads(res.text)["data"]["list"][0]["msg"]}' sct_msg += f'获取签到情况成功!当前签到情况为{json.loads(res.text)["data"]["list"][0]["msg"]}'
print(f'完整返回体为:{res.text}') print(f"完整返回体为:{res.text}")
print('正在尝试清除15分钟弹窗……')
for popout in json.loads(res.text)['data']['list']:
popid = popout['id']
clear_result = r.post('https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/ackNotification', headers=headers, json={'id': str(popid)})
try:
if clear_result.status_code == 200 and clear_result.json()['msg'] == 'OK':
print(f'已清除id为{popid}的弹窗!')
else:
print(f'清除弹窗失败!返回信息为:{clear_result.text}')
except KeyError as e:
print(f'清除弹窗失败!返回信息为:{clear_result.text};错误信息为:{e}')
else: else:
raise RunError( raise RunError(
f"签到失败请带着本次运行的所有log内容到 https://github.com/ElainaMoe/MHYY-AutoCheckin/issues 发起issue解决或者自行解决。签到出错返回信息如下{res.text}") f"签到失败请带着本次运行的所有log内容到 https://github.com/GamerNoTitle/MHYY/issues 发起issue解决或者自行解决。签到出错返回信息如下{res.text}"
)
if sct_status: if sct_status:
res = r.post(sct_url, json={'title': '', 'short': 'MHYY-AutoCheckin 签到情况报告', 'desp': sct_msg}, timeout=30) res = httpx.post(
sct_url,
json={
"title": "",
"short": "MHYY-AutoCheckin 签到情况报告",
"desp": sct_msg,
},
timeout=30,
)
if res.status_code == 200: if res.status_code == 200:
print('sct推送完成') print("sct推送完成")
else: else:
print('sct无法推送') print("sct无法推送")
print(res.text) print(res.text)