山东大学(威海)relax使用python和fiddler进行自动打卡2.0

自动打卡2.0版,运行至今没有出过一个bug。1.0版打卡需要1.5分钟,但这个2.0版只需3秒。效率成倍提高。

原很简单理:

 1. fiddler抓包
 2. python发包和接收包

通过fiddler抓包我发现relax的打卡过程是这样的:

 先发送登陆包,然后服务器会返回一个维持会话的cookie;
 之后再发一个包获得当天的打卡id;
 最后发打卡包。

然后使用python的requests库进行发包操作:

 将账号密码设为字典,之后发第一个登录包,用字符串操作获得cookie,
 并置入下一个获得id的包中,发包,用字符串的切片获得id,置入打卡包,
 发包,接受返回信息,如果是200,即成功。

最后附上代码

''' 
    每日打卡2.0版
    采用requests库进行发包和接收包
    方便快捷,整体用时3 s
'''
#加载库
import requests
import time
from requests.packages.urllib3.exceptions import InsecureRequestWarning #调用忽略警告的库

#忽略警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

time1=time.time()

#开始进行登录
headers = {
     
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'

}

url = 'https://xsc-health.wh.sdu.edu.cn/mobile/rpc?p=/v2/login/login&t=1601598512426'

data = {
     "jsonrpc":"2.0","method":"/v2/login/login","id":1,"params":["202000820","whsdu@202000820","false"]}

r = requests.post(url,json=data,verify=False)

str1=str(r.cookies)
coo=str1[27:67]
print(coo)

#获取id

headers = {
     
"User-Agent": "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3",
"content-type": "application/json",
"Cookie":coo}

url = 'https://xsc-health.wh.sdu.edu.cn/mobile/rpc?p=/v2/fight/ncp/health/report/getId&t=1601764550719'

data = {
     "jsonrpc":"2.0","method":"/v2/fight/ncp/health/report/getId","id":"1","params":[]}

r = requests.post(url,json=data,headers=headers)

str2=str(r.text)
id1=str2[36:72]
print(id1)

#发打卡包
headers = {
     
"User-Agent": "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3",
"content-type": "application/json",
"Cookie":coo}

url = 'https://xsc-health.wh.sdu.edu.cn/mobile/rpc?p=/v2/workorder/action/createWithValidate&t=1601598637325'

data = {
     "jsonrpc":"2.0","method":"/v2/workorder/action/createWithValidate","id":1,"params":[[{
     "id":id1,"type":"40bca208-5184-11ea-887d-cb65bdaac481","source":"mobile","apply_user":"420ca15c-f5f6-11ea-9f10-6309dd05d1d6","xllb":"本科生","szyx":"c16ecc52-f5f1-11ea-9475-b37e10b6536e","xm":"张大仙","xh":"202000820","xb":"male","lxdh":"110110","jkzt":"健康","shifoufare":"否","tiwen":36.3,"shifoujiuzhenzhuyuan":"","yiyuanmingcheng":"","shifougeli":"fou","gelifangshi":"","gelidizhi":"","dw":"{\"point\":null,\"address\":\"未获取到当前位置\",\"addressComponent\":null}","cunjieqijianshifouzaixiao":"fou","shifouzaixiao":"shi","shifouyifanhuihuocongweilikaixuexiao":"congweilikai","muqiansuozaichengshi":"guoneishengshi","sheng":"c68417d8-5afb-11ea-b7e1-278504feb271","shi":"cf1a8044-5afb-11ea-b815-53bce1ea2b16","qu":"da5508b2-5afb-11ea-b6e0-b70e441af322","xxdz":"文化西路180号","guowaidizhi":"","fanhuishijian":"","jinyigeyueshifouquguohubei":"fou","jinyigeyueshifoujiechuguoquezhenbingli":"fou","jinyigeyueshifoujiechuguoyisibingli":"fou","miqiejiechuguanxi":"","ganranzhe":"否","jiechuzhe":"否","juzhu":"否","fare":"否","hubeijingwai":"否"}],["8a525ad7-5187-11ea-a13f-53bf2079bf35"]]}

r = requests.post(url,json=data,headers=headers)
print(r.text)
time2=time.time()

end=""
if end==str(r):
    print("打卡成功")
else:
    print("打卡失败")

print("程序运行时间:",time2-time1,"秒")

你可能感兴趣的:(python,fiddler,cookie)