Merge branch 'master' into master

This commit is contained in:
Womsxd 2022-08-28 17:40:00 +08:00 committed by GitHub
commit 75a1e95adb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 113 additions and 6 deletions

View File

@ -132,7 +132,7 @@ docker-compose pull && docker-compose up -d
1. 下载本项目 1. 下载本项目
2. 在脚本目录执行`pip3 install -r requirements.txt -t .` 2. 在脚本目录执行`pip3 install -r requirements_qcloud.txt -t .`
3. 在本地完整运行一次。 3. 在本地完整运行一次。
@ -152,7 +152,7 @@ docker-compose pull && docker-compose up -d
* 阿里云 * 阿里云
1. 下载本项目 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. 在本地完整运行一次。 3. 在本地完整运行一次。
4. 打开并登录[函数计算 FC](https://fcnext.console.aliyun.com/cn-hangzhou/services)。注意左上方显示的地区,可点击切换其他地区。 4. 打开并登录[函数计算 FC](https://fcnext.console.aliyun.com/cn-hangzhou/services)。注意左上方显示的地区,可点击切换其他地区。
5. 创建服务 (日志功能可能产生费用,建议关闭) 5. 创建服务 (日志功能可能产生费用,建议关闭)

50
cloud_genshin.py Normal file
View File

@ -0,0 +1,50 @@
import tools
import config
import setting
from request import http
from loghelper import log
class CloudGenshin:
def __init__(self) -> None:
self.headers = {
'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',
'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 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

View File

@ -9,7 +9,7 @@ serverless = False
update_config_need = False update_config_need = False
config = { config = {
'enable': True, 'version': 6, 'enable': True, 'version': 7,
'account': { 'account': {
'cookie': '', 'cookie': '',
'login_ticket': '', 'login_ticket': '',
@ -34,6 +34,12 @@ config = {
'enable': False, 'cookie': '', 'enable': False, 'cookie': '',
'genshin': {'auto_checkin': False, 'black_list': []} 'genshin': {'auto_checkin': False, 'black_list': []}
} }
},
'cloud_games': {
"genshin": {
'enable': False,
'token': ''
}
} }
} }
@ -79,6 +85,9 @@ def update_config():
continue continue
config['games']['cn'][i] = config_json['games']['cn'][i] config['games']['cn'][i] = config_json['games']['cn'][i]
config['games']['os'] = config_json['games']['os'] 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() save_config()
log.info('config更新完毕') log.info('config更新完毕')
if not serverless: if not serverless:
@ -87,12 +96,26 @@ def update_config():
log.error("请本地更新一下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(p_path=None): def load_config(p_path=None):
global config global config
if not p_path: if not p_path:
p_path=config_Path p_path=config_Path
with open(p_path, "r", encoding='utf-8') as f: with open(p_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加载完毕") log.info("Config加载完毕")
return config return config
@ -143,6 +166,18 @@ def clear_cookies():
log.info("Cookie删除完毕") 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__": if __name__ == "__main__":
# 初始化配置文件 # 初始化配置文件
# try: # try:
@ -153,4 +188,5 @@ if __name__ == "__main__":
# pass # pass
# save_config() # save_config()
# update_config() # update_config()
load_config()
pass pass

View File

@ -1,5 +1,5 @@
enable: true #这里控制整个config文件是否启用 enable: true #这里控制整个config文件是否启用
version: 6 #config的版本 version: 7 #config的版本
account: account:
cookie: "" #登入账号只需要修改这里就行了,下面会自动获取 cookie: "" #登入账号只需要修改这里就行了,下面会自动获取
login_ticket: "" login_ticket: ""
@ -39,3 +39,7 @@ games:
genshin: genshin:
auto_checkin: false auto_checkin: false
black_list: [] black_list: []
cloud_games: #云游戏专区
genshin: #云原神
enable: true #开启签到
token: "" #这里填入抓包获得的token

View File

@ -10,6 +10,7 @@ import setting
import mihoyobbs import mihoyobbs
import honkai3rd import honkai3rd
import tearsofthemis import tearsofthemis
import cloud_genshin
from error import * from error import *
from loghelper import log from loghelper import log
@ -95,6 +96,14 @@ def main():
ret_code = 3 ret_code = 3
return_data += "\n\n" + genshin_message return_data += "\n\n" + genshin_message
time.sleep(random.randint(2, 8)) time.sleep(random.randint(2, 8))
if config.config['cloud_games']['genshin']["enable"]:
log.info("正在进行云原神签到")
if config.config['cloud_games']['genshin']['token'] == "":
log.info("token为空,跳过任务")
else:
cloud_ys = cloud_genshin.CloudGenshin()
data = cloud_ys.sign_account()
return_data += "\n\n" + data
return ret_code, return_data return ret_code, return_data
elif config.config["account"]["cookie"] == "CookieError": elif config.config["account"]["cookie"] == "CookieError":
raise CookieError('Cookie expires') raise CookieError('Cookie expires')

2
requirements_qcloud.txt Normal file
View File

@ -0,0 +1,2 @@
requests>=2.26.0
PyYAML~=6.0

View File

@ -7,6 +7,9 @@ mihoyobbs_Version = "2.35.2" # Slat和Version相互对应
# 米游社的客户端类型 # 米游社的客户端类型
mihoyobbs_Client_type = "2" # 1为ios 2为安卓 mihoyobbs_Client_type = "2" # 1为ios 2为安卓
mihoyobbs_Client_type_web = "5" # 4为pc web 5为mobile web mihoyobbs_Client_type_web = "5" # 4为pc web 5为mobile web
# 云原神版本
cloudgenshin_Version = "3.0.0"
# 米游社的分区列表 # 米游社的分区列表
mihoyobbs_List = [{ mihoyobbs_List = [{
"id": "1", "id": "1",
@ -110,3 +113,7 @@ genshin_Act_id = "e202009291139501"
genshin_checkin_rewards = f'{web_Api}/event/bbs_sign_reward/home?act_id={genshin_Act_id}' 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={}&region={}&uid={}" genshin_Is_signurl = web_Api + "/event/bbs_sign_reward/info?act_id={}&region={}&uid={}"
genshin_Signurl = web_Api + "/event/bbs_sign_reward/sign" genshin_Signurl = web_Api + "/event/bbs_sign_reward/sign"
# 云原神相关api
cloud_genshin_Api = "https://api-cloudgame.mihoyo.com"
cloud_genshin_Inquire = cloud_genshin_Api + "/hk4e_cg_cn/wallet/wallet/get"

View File

@ -50,7 +50,6 @@ def get_ds2(q: str, b: str) -> str:
def get_device_id() -> str: def get_device_id() -> str:
return str(uuid.uuid3(uuid.NAMESPACE_URL, config.config["account"]["cookie"])) return str(uuid.uuid3(uuid.NAMESPACE_URL, config.config["account"]["cookie"]))
# 获取签到的奖励名称 # 获取签到的奖励名称
def get_item(raw_data: dict) -> str: def get_item(raw_data: dict) -> str:
temp_name = raw_data["name"] temp_name = raw_data["name"]