[Python] 纯文本查看 复制代码
import requests, json, time
import email168,webbrowser
class LOLFriend():
def __init__(self, cookies=""):
self.cookies = cookies
self.session = requests.Session()
headers = {
'Host': 'www.wegame.com.cn',
'Connection': 'keep-alive',
'Content-Length': '112',
'sec-ch-ua': '" Not;A Brand";v="99", "Microsoft Edge";v="97", "Chromium";v="97"',
'accept': 'json',
'Content-Type': 'application/json',
'sec-ch-ua-mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36 Edg/97.0.1072.69',
'sec-ch-ua-platform': '"Windows"',
'Origin': 'https://www.wegame.com.cn',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://www.wegame.com.cn/platform/social/friend',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
}
self.session.headers.update(headers)
def get_friends_status(self, friends: list):
'''
返回好友们的状态(上线,离线或者某种游戏状态)
:param friends: 查询的好友们的id[]
:return: 对应的状态列表 错误返回[]
'''
headers = {
'cookie': self.cookies,
'content-type': 'application/json',
'content-length': '38',
'accept': 'json',
}
self.session.headers.update(headers)
url = "https://www.wegame.com.cn/api/mwg_im/lua/proxy/index/mwg_members_svr/bt_get_online_status"
data = json.dumps({
'app_id': 10001,
'uid_list': friends,
})
try:
ret = self.session.post(url, data=data, )
return ret.json()['data']['user_info']
except:
return []
def get_friend_list(self):
'''
获取所有好友列表信息
:return:
'''
url = "https://www.wegame.com.cn/api/mwg_im/lua/imsnssvr/get_game_friend_list"
headers = {
'cookie': self.cookies,
'content-type': 'application/json',
'content-length': '38',
'accept': 'json',
}
self.session.headers.update(headers)
friend_list = []
start_index = 0
while True:
# 一次最多50个好友 0-49
data = json.dumps(
{"app_id": 10001, "game_id": 26, "client_type": 1000000, "start_index": start_index, "area_id": 14,
"data_version": 0,
"reqfrom": "pc"})
try:
ret = self.session.post(url=url, data=data)
except:
return friend_list
data = ret.json()['data']
friend_list += data['friend_list']
# 获取下一次的启动序号
start_index = data['next_start_index']
time.sleep(0.2)
if start_index == 0:
break
return friend_list
def send_msg(item):
'''
提醒用户该好友状态
:param item: 当前好友信息
:return:
'''
global idexs,old_states,send_targets
# 查询名字
name = [user_data['game_nick'] for user_data in idexs if user_data['user_nick'] == item['name']]
name = name[0]
# 判断是否有发送过邮箱
for i, old_st in enumerate(old_states):
if name == old_st['name']:
if old_st['states'] != item['online_state']:
# 如果没有提醒过,则发送邮箱
# 并且记录
old_states['states'] = item['online_state']
title = '监控提醒:'
text = f"检测到这个B {name} {item['online_desc']} \n{time.time()}"
print(text)
for send_target in send_targets:
email168.msg(text, send_target, title)
break
if __name__ == '__main__':
print('朋友开黑不带你?私自偷摸上线玩游戏?孩子逃课上网治不了?女朋友和别人玩夫妻双打网游?')
print("请按照步骤操作:")
webbrowser.open("https://www.wegame.com.cn/platform/social/friend")
print("1.请在打开的网址中登录QQ https://www.wegame.com.cn/platform/social/friend")
print('2.请登录好qq后,在浏览器中按F12')
print('3.请找到控制台 或者 Console 栏目 ')
print('4.在控制台中输入:document.cookie 然后回车')
cookies=input("请将控制台返回的信息粘贴在此处(引号中间的):")
with open('接收邮箱目标.txt', 'r', encoding='utf-8')as f:
send_targets = f.read().split('\n')
lol = LOLFriend(cookies)
print(f"正在获取好友列表...")
friend_list = lol.get_friend_list()
idexs = [] # 监控的好友们数据
for i, friend in enumerate(friend_list):
print(i, friend['user_nick'],friend['game_nick'])
print(f"done!您一共有{len(friend_list)}为好友")
while True: # 循环添加监控好友列表
while True:
try:
idex = int(input(f"请输入你要查询在线状态的朋友/家人对应序号[0-{len(friend_list) - 1}]:"))
break
except:
print("请输入正确的序号!!!!!!!!!!!!!!!!!!!!!!!!")
# 是否加入24小时监控列表
isorno = input(f"是否将 {friend_list[idex]['game_nick']} 加入24小时监控列表(yes or no):")
if isorno == 'yes' or isorno == 'YES':
idexs.append(friend_list[idex])
isorno = input(f"是否继续添加监控列表?(yes or no)")
if isorno == 'yes' or isorno == 'YES':
pass
else:
# 不添加了,因此退出大循环
break
#------------------------------------------开始监控--------------------------------------
type_ = input(f"请选择监控提醒类型(PC在线输入0 游戏在线输入1):")
# 只要user_id数据
user_ids = [int(item['user_id']) for item in idexs]
# 用来存是否已经提醒过了
old_states = [{'name':item['game_nick'],'states':None} for item in idexs]
while True:
# 读取好友当前状态
friend_status_datas = lol.get_friends_status(user_ids)
for item in friend_status_datas:
# 监控在线
if type_ == '0':
# 状态=0为PC在线 说明在偷偷摸摸玩电脑
if item['online_state'] == 0 :
send_msg(item)
else:
# 状态=1 2 3 说明在偷偷摸摸玩游戏
if item['online_state'] != 4:
send_msg( item)
time.sleep(60)