import requests,json,time,datetime
username='0000'
passwd='1111'
#server酱推送
SCKEY='SCU89155Tafd73d4484e0aeb50a757825890e94865e6a525da0eb2'
name=''#签到后老师那里显示的名字,空着的话就是默认
address='中国湖南省'#地址
latitude='27'#纬度
longitude='110'#经度
picname='1.png'#同目录下的照片名字,如果不用就留空 picname=''
#设置轮询间隔(单位:秒,建议不低于5)
speed=60
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36'}
coursedata=[]
activeList=[]
course_index=0
status=0
activates=[]
a=1
index=0
def login(username,passwd): #获取cookie
url='https://passport2-api.chaoxing.com/v11/loginregister'
data={'uname':username,'code':passwd,}
session = requests.session()
cookie_jar = session.post(url=url, data=data, headers=headers).cookies
cookie_t = requests.utils.dict_from_cookiejar(cookie_jar)
return cookie_t
cookie=login(username,passwd)
uid=cookie['UID']
def token():#获取上传图片用的token
url='https://pan-yz.chaoxing.com/api/token/uservalid'
res=requests.get(url,headers=headers,cookies=cookie)
tokendict=json.loads(res.text)
return(tokendict['_token'])
def upload():#上传图片
if picname.isspace() or len(picname)==0:
return
else:
url='https://pan-yz.chaoxing.com/upload'
files={'file':(picname, open(picname,'rb'),'image/webp,image/*',),}
res=requests.post(url,data={'puid':uid,'_token':token()},files=files,headers=headers,cookies=cookie)
resdict=json.loads(res.text)
return(resdict['objectId'])
def taskactivelist(courseId,classId):#查找签到任务
global a
url="https://mobilelearn.chaoxing.com/ppt/activeAPI/taskactivelist?courseId="+str(courseId)+"&classId="+str(classId)+"&uid="+uid
res=requests.get(url,headers=headers,cookies=cookie)
respon = res.status_code
if respon==200:#网页状态码正常
data=json.loads(res.text)
activeList=data['activeList']
#print(activeList)
for item in activeList:
if("nameTwo" not in item):
continue
if(item['activeType']==2 and item['status']==1):
signurl=item['url']#提取activePrimaryId
aid = getvar(signurl)
if(aid not in activates):
print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'[签到]',coursedata[i]['name'],'查询到待签到活动 活动名称:%s 活动状态:%s 活动时间:%s aid:%s'%(item['nameOne'],item['nameTwo'],item['nameFour'],aid))
sign(aid,uid)#print('调用签到函数')
a=2
else:
print('error',respon)
def getvar(url):#查找activePrimaryId
var1 = url.split("&")
for var in var1:
var2 = var.split("=")
if(var2[0]=="activePrimaryId"):
return var2[1]
return "ccc"
def sign(aid,uid):#签到
global status,activates
url="https://mobilelearn.chaoxing.com/pptSign/stuSignajax"
objectId=upload()
res=requests.post(url,data={"name":name,"address":address,'activeId':aid,'uid':uid,'longitude':longitude,'latitude':latitude,'objectId':objectId},headers=headers,cookies=cookie)
if(res.text=="success"):
print("用户:"+uid+" 签到成功!")
push(SCKEY,res.text)
activates.append(aid)
status=2
else:
print(res.text,'签到失败')
activates.append(aid)
def push(SCKEY,msg):
if SCKEY.isspace() or len(SCKEY)==0:
return
else:
api = 'https://sc.ftqq.com/'+SCKEY+'.send'
title = u"zhm签到辣!"
content = '课程: '+coursedata[i]['name']+'\n\n签到状态:'+msg
data = {
"text":title,
"desp":content
}
req = requests.post(api,data = data)
url="http://mooc1-api.chaoxing.com/mycourse/backclazzdata?view=json&rss=1"
res=requests.get(url,headers=headers,cookies=cookie)
cdata=json.loads(res.text)
if(cdata['result']!=1):
print("课程列表获取失败")
for item in cdata['channelList']:
if("course" not in item['content']):
continue
pushdata={}
pushdata['courseid']=item['content']['course']['data'][0]['id']
pushdata['name']=item['content']['course']['data'][0]['name']
#pushdata['imageurl']=item['content']['course']['data'][0]['imageurl']
pushdata['classid']=item['content']['id']
coursedata.append(pushdata)
print("获取成功:")
for item in coursedata:#打印课程
print(str(index)+".课程名称:"+item['name'])
index+=1
print("请输入你需要的课程号")
#arr = input("")
#num1 = [int(n) for n in arr.split()]
#print(num1)
num1 = [0,1,2,3,4,7,8,9]
lcy = 5
while lcy:
for i in num1:
#for i in range(index):
taskactivelist(coursedata[i]['courseid'],coursedata[i]['classid'])
if a==2:
a=0
else:
print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'[监控运行中]课程:',coursedata[i]['name'],'未查询到签到活动')
time.sleep(speed)#休眠
lcy-=1
最后修改:2020 年 10 月 27 日
© 允许规范转载