mirror of
https://github.com/TDSCDMAA/AutoMihoyoBBS.git
synced 2026-06-02 18:43:42 +08:00
push
push
This commit is contained in:
parent
3517364a63
commit
b0db90f61a
3
.gitignore
vendored
3
.gitignore
vendored
@ -127,3 +127,6 @@ dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# VSCode
|
||||
.vscode/
|
||||
12
config.py
12
config.py
@ -1,12 +1,12 @@
|
||||
import os
|
||||
import json
|
||||
from tools import log
|
||||
import tools
|
||||
|
||||
#这里的内容会自动获取
|
||||
mihoyobbs_Login_ticket = ""
|
||||
mihoyobbs_Stuid = ""
|
||||
mihoyobbs_Stoken = ""
|
||||
#这里填入你的米游社Cookie
|
||||
#这里是米游社的cookie
|
||||
mihoyobbs_Cookies = ""
|
||||
#这个dist里面的内容和米游社有关
|
||||
mihoyobbs = {
|
||||
@ -30,7 +30,7 @@ mihoyobbs = {
|
||||
#原神自动签到
|
||||
genshin_AutoSingin = True
|
||||
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
path = os.path.dirname(os.path.realpath(__file__)) + "/config"
|
||||
|
||||
def Load_config():
|
||||
with open(f"{path}/config.json", "r") as f:
|
||||
@ -54,7 +54,7 @@ def Load_config():
|
||||
mihoyobbs["bbs_Share"] = data["mihoyobbs"]["bbs_Share"]
|
||||
genshin_AutoSingin = data["genshin_AutoSingin"]
|
||||
f.close()
|
||||
log.info("Config加载完毕")
|
||||
tools.log.info("Config加载完毕")
|
||||
|
||||
def Save_config():
|
||||
with open(f"{path}/config.json","r+") as f:
|
||||
@ -68,7 +68,7 @@ def Save_config():
|
||||
f.write(temp_Text)
|
||||
f.flush()
|
||||
f.close()
|
||||
log.info("Config保存完毕")
|
||||
tools.log.info("Config保存完毕")
|
||||
|
||||
def Clear_cookies():
|
||||
with open(f"{path}/config.json","r+") as f:
|
||||
@ -83,4 +83,4 @@ def Clear_cookies():
|
||||
f.write(temp_Text)
|
||||
f.flush()
|
||||
f.close()
|
||||
log.info("Cookie删除完毕")
|
||||
tools.log.info("Cookie删除完毕")
|
||||
50
genshin.py
50
genshin.py
@ -1,8 +1,6 @@
|
||||
import time
|
||||
import httpx
|
||||
import tools
|
||||
import config
|
||||
import random
|
||||
import setting
|
||||
|
||||
class genshin:
|
||||
@ -12,23 +10,63 @@ class genshin:
|
||||
'DS': tools.Get_ds(web=True, web_old=True),
|
||||
'Origin': 'https://webstatic.mihoyo.com',
|
||||
'x-rpc-app_version': setting.mihoyobbs_Version_old,
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.2.0',
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0',
|
||||
'x-rpc-client_type': setting.mihoyobbs_Client_type_web,
|
||||
'Referer': 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required=true&act_id=e202009291139501&utm_source=bbs&utm_medium=mys&utm_campaign=icon',
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Accept-Language': 'zh-CN,en-US;q=0.8',
|
||||
'X-Requested-With': 'com.mihoyo.hyperion',
|
||||
"Cookie": config.mihoyobbs_Cookies
|
||||
"Cookie": config.mihoyobbs_Cookies,
|
||||
'x-rpc-device_id': tools.Get_driveid()
|
||||
}
|
||||
self.acc_List = self.Getacc_list()
|
||||
self.sing_Give = self.Get_singgive()
|
||||
#获取绑定的账号列表
|
||||
def Getacc_list(self) -> list:
|
||||
temp_List = []
|
||||
req = httpx.get(setting.accinfo_Url, headers=self.headers)
|
||||
req = httpx.get(setting.genshin_Accinfo_url, headers=self.headers)
|
||||
data = req.json()
|
||||
if (data["rercode"] != 0):
|
||||
if (data["retcode"] != 0):
|
||||
tools.log.warn("获取账号列表失败!")
|
||||
exit()
|
||||
for i in data["data"]["list"]:
|
||||
temp_List.append([i["nickname"], i["game_uid"], i["region"]])
|
||||
return (temp_List)
|
||||
#获取已经签到奖励列表
|
||||
def Get_singgive(self) -> list:
|
||||
req = httpx.get(setting.genshin_Singlisturl.format(setting.genshin_Act_id),headers=self.headers)
|
||||
data = req.json()
|
||||
if (data["retcode"] != 0):
|
||||
tools.log.warn("获取签到奖励列表失败")
|
||||
print (req.text)
|
||||
exit()
|
||||
return (data["data"]["awards"])
|
||||
#判断签到
|
||||
def Is_sing(self, region:str, uid:str) -> list:
|
||||
req = httpx.get(setting.genshin_Is_singurl.format(setting.genshin_Act_id, region, uid), headers=self.headers)
|
||||
data = req.json()
|
||||
if (data["retcode"] != 0):
|
||||
tools.log.warn("获取账号签到信息失败!")
|
||||
print (req.text)
|
||||
exit()
|
||||
return (data[data])
|
||||
#签到
|
||||
def Sing_acc(self):
|
||||
for i in self.acc_List:
|
||||
is_data = self.Is_sing(region = i[2], uid = i[1])
|
||||
if (is_data["first_bind"] == True):
|
||||
tools.log.warn(f"旅行者{i[0]}是第一次绑定米游社,请先手动签到一次")
|
||||
else:
|
||||
sing_Days = is_data["total_sign_day"]
|
||||
if (is_data["is_sing"] == True):
|
||||
tools.log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{self.sing_Give[sing_Days]}")
|
||||
req = httpx.post(url=setting.genshin_Singurl, headers=self.headers,
|
||||
json={'act_id': setting.genshin_Act_id, 'region': i[2], 'uid': i[1]})
|
||||
data = req.json()
|
||||
if (data["retcode"] == 0):
|
||||
tools.log.info(f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是{self.sing_Give[sing_Days + 1]}")
|
||||
elif (data["retcode"] == -5003):
|
||||
tools.log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{self.sing_Give[sing_Days]}")
|
||||
else:
|
||||
tools.log.warn("账号签到失败!")
|
||||
print (req.text)
|
||||
|
||||
4
login.py
4
login.py
@ -14,10 +14,10 @@ def login():
|
||||
if (i.split("=")[0] == " login_ticket"):
|
||||
config.mihoyobbs_Login_ticket = i.split("=")[1]
|
||||
break
|
||||
data = request.get(url=setting.cookieUrl.format(config.mihoyobbs_Login_ticket))
|
||||
data = request.get(url=setting.bbs_Cookieurl.format(config.mihoyobbs_Login_ticket))
|
||||
if ("成功" in data["data"]["msg"]):
|
||||
config.mihoyobbs_Stuid = str(data["data"]["cookie_info"]["account_id"])
|
||||
data = request.get(url=setting.cookieUrl2.format(config.mihoyobbs_Login_ticket, config.mihoyobbs_Stuid))
|
||||
data = request.get(url=setting.bbs_Cookieurl2.format(config.mihoyobbs_Login_ticket, config.mihoyobbs_Stuid))
|
||||
config.mihoyobbs_Stoken = data["data"]["list"][0]["token"]
|
||||
log.info("登录成功!")
|
||||
log.info("正在保存Config!")
|
||||
|
||||
38
main.py
Normal file
38
main.py
Normal file
@ -0,0 +1,38 @@
|
||||
import login
|
||||
import config
|
||||
import genshin
|
||||
import setting
|
||||
import mihoyobbs
|
||||
|
||||
def main():
|
||||
#初始化,加载配置
|
||||
config.Load_config()
|
||||
#检测参数是否齐全,如果缺少就进行登入操作if (config.mihoyobbs_Login_ticket == "" or config.mihoyobbs_Stuid == "" or config.mihoyobbs_Stoken == ""):
|
||||
#登入
|
||||
login.login()
|
||||
#获取要使用的BBS列表,#判断是否开启bbs_Singin_multiif (config.mihoyobbs["bbs_Singin_multi"] == True):
|
||||
for i in setting.mihoyobbs_List:
|
||||
if (int(i["id"]) in config.mihoyobbs["bbs_Singin_multi_list"]):
|
||||
setting.mihoyobbs_List_Use.append(i)
|
||||
else:
|
||||
#关闭bbs_Singin_multi后只签到大别墅
|
||||
for i in setting.mihoyobbs_List:
|
||||
if (int(i["id"]) == 5):
|
||||
setting.mihoyobbs_List_Use.append(i)
|
||||
#米游社签到if(config.mihoyobbs["bbs_Gobal"] == True):
|
||||
bbs = mihoyobbs.mihoyobbs()
|
||||
if (config.mihoyobbs["bbs_Singin"] == True):
|
||||
bbs.Singin()
|
||||
if (config.mihoyobbs["bbs_Read_posts"] == True):
|
||||
bbs.Readposts()
|
||||
if (config.mihoyobbs["bbs_Like_posts"] == True):
|
||||
bbs.Likeposts()
|
||||
if (config.mihoyobbs["bbs_Share"] == True):
|
||||
bbs.Share()
|
||||
if(config.genshin_AutoSingin == True):
|
||||
genshin_Help = genshin
|
||||
genshin_Help.Sing_acc()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
pass
|
||||
21
mihoyobbs.py
21
mihoyobbs.py
@ -15,7 +15,7 @@ class mihoyobbs:
|
||||
"x-rpc-app_version": setting.mihoyobbs_Version,
|
||||
"x-rpc-sys_version": "6.0.1",
|
||||
"x-rpc-channel": "mihoyo",
|
||||
"x-rpc-device_id": tools.Random_text(20) + tools.Random_text(12),
|
||||
"x-rpc-device_id": tools.Get_driveid(),
|
||||
"x-rpc-device_name": tools.Random_text(random.randint(1, 10)),
|
||||
"x-rpc-device_model": "Mi 10",
|
||||
"Referer": "https://app.mihoyo.com",
|
||||
@ -27,7 +27,7 @@ class mihoyobbs:
|
||||
def Singin(self):
|
||||
tools.log.info("正在签到......")
|
||||
for i in setting.mihoyobbs_List_Use:
|
||||
req = httpx.post(url=setting.signUrl.format(i["id"]), data="" ,headers=self.headers)
|
||||
req = httpx.post(url=setting.bbs_Signurl.format(i["id"]), data="" ,headers=self.headers)
|
||||
data = req.json()
|
||||
if ("err" not in data["message"]):
|
||||
tools.log.info(str(i["name"]+ data["message"]))
|
||||
@ -41,42 +41,43 @@ class mihoyobbs:
|
||||
temp_List = []
|
||||
tools.log.info("正在获取帖子列表......")
|
||||
for i in setting.mihoyobbs_List_Use:
|
||||
req = httpx.get(url=setting.listUrl.format(i["forumId"]), headers=self.headers)
|
||||
req = httpx.get(url=setting.bbs_Listurl.format(i["forumId"]), headers=self.headers)
|
||||
data = req.json()
|
||||
for n in range(10):
|
||||
temp_List.append([data["data"]["list"][n]["post"]["post_id"], data["data"]["list"][n]["post"]["subject"]])
|
||||
tools.log.info("已获取{}个帖子".format(len(temp_List)))
|
||||
time.sleep(2)
|
||||
time.sleep(random.randrange(5))
|
||||
return (temp_List)
|
||||
#看帖子
|
||||
def Readposts(self):
|
||||
tools.log.info("正在看帖......")
|
||||
for i in range(3):
|
||||
req = httpx.get(url=setting.detailUrl.format(self.postsList[i][0]), headers=self.headers)
|
||||
req = httpx.get(url=setting.bbs_Detailurl.format(self.postsList[i][0]), headers=self.headers)
|
||||
data = req.json()
|
||||
if data["message"] == "OK":
|
||||
tools.log.info("看帖:{} 成功".format(self.postsList[i][1]))
|
||||
time.sleep(2)
|
||||
time.sleep(random.randrange(5))
|
||||
#点赞
|
||||
def Likeposts(self):
|
||||
tools.log.info("正在点赞......")
|
||||
for i in range(5):
|
||||
req = httpx.post(url=setting.likeUrl, headers=self.headers,
|
||||
req = httpx.post(url=setting.bbs_Likeurl, headers=self.headers,
|
||||
json={"post_id": self.postsList[i][0], "is_cancel": False})
|
||||
data = req.json()
|
||||
if (data["message"] == "OK"):
|
||||
tools.log.info("点赞:{} 成功".format(self.postsList[i][1]))
|
||||
#判断取消点赞是否打开
|
||||
if (config.mihoyobbs["bbs_Unlike"] == True):
|
||||
req = httpx.post(url=setting.likeUrl, headers=self.headers,
|
||||
time.sleep(random.randrange(5))
|
||||
req = httpx.post(url=setting.bbs_Likeurl, headers=self.headers,
|
||||
json={"post_id": self.postsList[i][0], "is_cancel": True})
|
||||
data = req.json()
|
||||
if (data["message"] == "OK"):
|
||||
tools.log.info("取消点赞:{} 成功".format(self.postsList[i][1]))
|
||||
time.sleep(2)
|
||||
time.sleep(random.randrange(5))
|
||||
def Share(self):
|
||||
tools.log.info("正在分享......")
|
||||
req = httpx.get(url=setting.shareUrl.format(self.postsList[0][0]), cookies=self.Cookie, headers=self.headers)
|
||||
req = httpx.get(url=setting.bbs_Shareurl.format(self.postsList[0][0]), headers=self.headers)
|
||||
data = req.json()
|
||||
if data["message"] == "OK":
|
||||
tools.log.info("分享:{} 成功".format(self.postsList[0][1]))
|
||||
33
run.py
33
run.py
@ -1,33 +0,0 @@
|
||||
import login
|
||||
import config
|
||||
import setting
|
||||
import mihoyobbs
|
||||
|
||||
#初始化,加载配置
|
||||
config.Load_config()
|
||||
#检测参数是否齐全,如果缺少就进行登入操作
|
||||
if (config.mihoyobbs_Login_ticket == "" or config.mihoyobbs_Stuid == "" or config.mihoyobbs_Stoken == ""):
|
||||
#登入
|
||||
login.login()
|
||||
#获取要使用的BBS列表
|
||||
#判断是否开启bbs_Singin_multi
|
||||
if (config.mihoyobbs["bbs_Singin_multi"] == True):
|
||||
for i in setting.mihoyobbs_List:
|
||||
if (int(i["id"]) in config.mihoyobbs["bbs_Singin_multi_list"]):
|
||||
setting.mihoyobbs_List_Use.append(i)
|
||||
else:
|
||||
#关闭bbs_Singin_multi后只签到大别墅
|
||||
for i in setting.mihoyobbs_List:
|
||||
if (int(i["id"]) == 5):
|
||||
setting.mihoyobbs_List_Use.append(i)
|
||||
#米游社签到
|
||||
if(config.mihoyobbs["bbs_Gobal"] == True):
|
||||
bbs = mihoyobbs.mihoyobbs()
|
||||
if (config.mihoyobbs["bbs_Singin"] == True):
|
||||
bbs.Singin()
|
||||
if (config.mihoyobbs["bbs_Read_posts"] == True):
|
||||
bbs.Readposts()
|
||||
if (config.mihoyobbs["bbs_Like_posts"] == True):
|
||||
bbs.Likeposts()
|
||||
if (config.mihoyobbs["bbs_Share"] == True):
|
||||
bbs.Share()
|
||||
21
setting.py
21
setting.py
@ -40,14 +40,17 @@ mihoyobbs_List = [{
|
||||
mihoyobbs_List_Use= []
|
||||
|
||||
#米游社的API列表
|
||||
cookieUrl = "https://webapi.account.mihoyo.com/Api/cookie_accountinfo_by_loginticket?login_ticket={}"
|
||||
cookieUrl2 = "https://api-takumi.mihoyo.com/auth/api/getMultiTokenByLoginTicket?login_ticket={}&token_types=3&uid={}"
|
||||
signUrl = "https://bbs-api.mihoyo.com/apihub/sapi/signIn?gids={}" # post
|
||||
listUrl = "https://bbs-api.mihoyo.com/post/api/getForumPostList?forum_id={}&is_good=false&is_hot=false&page_size=20&sort_type=1"
|
||||
detailUrl = "https://bbs-api.mihoyo.com/post/api/getPostFull?post_id={}"
|
||||
shareUrl = "https://bbs-api.mihoyo.com/apihub/api/getShareConf?entity_id={}&entity_type=1"
|
||||
likeUrl = "https://bbs-api.mihoyo.com/apihub/sapi/upvotePost" # post json
|
||||
bbs_Cookieurl = "https://webapi.account.mihoyo.com/Api/cookie_accountinfo_by_loginticket?login_ticket={}"
|
||||
bbs_Cookieurl2 = "https://api-takumi.mihoyo.com/auth/api/getMultiTokenByLoginTicket?login_ticket={}&token_types=3&uid={}"
|
||||
bbs_Signurl = "https://bbs-api.mihoyo.com/apihub/sapi/signIn?gids={}" # post
|
||||
bbs_Listurl = "https://bbs-api.mihoyo.com/post/api/getForumPostList?forum_id={}&is_good=false&is_hot=false&page_size=20&sort_type=1"
|
||||
bbs_Detailurl = "https://bbs-api.mihoyo.com/post/api/getPostFull?post_id={}"
|
||||
bbs_Shareurl = "https://bbs-api.mihoyo.com/apihub/api/getShareConf?entity_id={}&entity_type=1"
|
||||
bbs_Likeurl = "https://bbs-api.mihoyo.com/apihub/sapi/upvotePost" # post json
|
||||
|
||||
#原神自动签到相关的设置
|
||||
act_ID = "e202009291139501"
|
||||
accinfo_Url = "https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=hk4e_cn"
|
||||
genshin_Act_id = "e202009291139501"
|
||||
genshin_Accinfo_url = "https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=hk4e_cn"
|
||||
genshin_Singlisturl = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/home?act_id={}"
|
||||
genshin_Is_singurl = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/info?act_id={}®ion={}&uid={}"
|
||||
genshin_Singurl = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/sign"
|
||||
8
tools.py
8
tools.py
@ -1,7 +1,9 @@
|
||||
import logging
|
||||
import uuid
|
||||
import time
|
||||
import config
|
||||
import random
|
||||
import string
|
||||
import logging
|
||||
import hashlib
|
||||
import setting
|
||||
|
||||
@ -41,6 +43,10 @@ def Get_ds(web:bool, web_old:bool) -> str:
|
||||
c = MD5("salt=" + n + "&t=" + i + "&r=" + r)
|
||||
return (i + "," + r + "," + c)
|
||||
|
||||
def Get_driveid() -> str:
|
||||
return (str(uuid.uuid3(uuid.NAMESPACE_URL, config.mihoyobbs_Cookies)).replace(
|
||||
'-', '').upper())
|
||||
|
||||
#获取明天早晨0点的时间戳
|
||||
def Nextday() -> int:
|
||||
now_time = int(time.time())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user