import requests
import json
import psutil
import timeusername = ""
#密码得是加密后的
password = ""
#需要监控的游戏
process_name = "cloudmusic.exe"session = requests.Session()
""" 获取token """
def getAccountToken():url = "https://webapi.nn.com/api/auth/login"data = '{"username":"'+username+'","password":"'+password+'","user_type":"0","src_channel":"guanwang","country_code":86,"lang":"zh_CN","region_code":1,"account_token":null}'res = session.post(url=url,data=data)jsonRes = json.loads(res.text)if jsonRes['code'] !=0:print(jsonRes)return ""return jsonRes['data']['login_info']['account_token']""" 暂停=pause 恢复=recover """
def doAction(action,token):url = "https://webapi.nn.com/api/user/"+actiondata ='{"account_token":"'+token+'","lang":"zh_CN"}'res = session.post(url=url,data=data)print("响应",json.loads(res.text))""" 判断游戏是否运行 """
def proc_exist(process_name):pl = psutil.pids()for pid in pl:if psutil.Process(pid).name() == process_name:return pid""" 每n秒执行一次"""
def timer(n): while True: if isinstance(proc_exist(process_name),int):print(process_name+' is running')else:print('no such process...,我tm要暂停了')token = getAccountToken()doAction("pause",token)breaktime.sleep(n)
timer(2)
如何获取password
- 打开雷神官网 https://jiasu.nn.com/
- 按F12,进入调试状态
- 输入账户密码,点击登录
- 在左侧network,找到url为login后缀的地址
- 获取加密后的password