python脚本实现我在校园自动打卡

前言

此处略……

准备工具

1.下载vscode软件,并安装python扩展

2.使用py脚本1获取我在校园jwsession

3.使用py脚本2实现打卡

注意:本代码需要安装requests库

3.如需实现全自动需要服务器或腾讯云函数部署

教程

1.下载vscode软件

vscode:https://code.visualstudio.com/

2.下载完成后安装python扩展

3.py脚本1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import json

import requests

# 登陆接口
# self.loginUrl = "https://gw.wozaixiaoyuan.com/basicinfo/mobile/login/username"

# 登陆
class Login:
def __init__(self):
# 账户名或者手机号
self.username = "" #这里改成你的手机号
# 登录密码
self.password = "" #数字密码

# 登陆接口
self.loginUrl = "https://student.wozaixiaoyuan.com/basicinfo/mobile/login/username"

# 请求头
self.header = {
"Host": "student.wozaixiaoyuan.com",
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive",
"User-Agent": "xxxxxxxxxxxxxxx",
"Content-Length": "29",
}

# 请求体(必须有) self.body = "{}"
self.body = "{}"

def login(self):

# 用户名或账号
url = self.loginUrl + "?username=" + self.username + "&password=" + self.password
self.session = requests.session()


response = self.session.post(url=url, data=self.body, headers=self.header)
res = json.loads(response.text)
if res["code"] == 0:
print("登陆成功")
# 登录成功获取JWSESSION
jwsession = response.headers['JWSESSION']
print(jwsession)
return True
else:
print("登陆失败,请检查账号信息和密码是否正确")
self.status_code = 4
return False

if __name__ == "__main__":
Login().login()

在以上代码填写你的username(我在校园手机号)和password(密码)

注意:密码必须为数字

注意:运行前先安装requests库

pip install requests

4.运行py脚本2

运行py脚本1会获得一个jwsession,复制jwsession到py脚本2

为自动推送打卡返回结果到微信,请先注册pushplus

注册完成后获取pushplus的token

将token和jwsession填入以下代码对应位置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- encoding:utf-8 -*-
import requests
import json
from urllib.parse import urlencode

pushtoken = '' # 这里填pushplus的token,可以在http://www.pushplus.plus/ 扫码注册
jwsession = '' # 这里填我在校园的jwsession

dk = {
'token': pushtoken,
'title': '我在校园每日打卡',
'content': '',
}
header = {
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat",
"Content-Type": "application/x-www-form-urlencoded",
"Content-Length": "2",
"Host": "student.wozaixiaoyuan.com",
"Accept-Language": "en-us,en",
"Accept": "application/json, text/plain, */*",
'JWSESSION':jwsession
}
dkurl = 'http://www.pushplus.plus/send'
body = "{}"

try:
def main():
url = "https://student.wozaixiaoyuan.com/health/save.json"
sign_data = {
"answers": '["0"]',
"latitude": "109.186182", # 纬度
"longitude": "34.366191", # 经度
"country": "中国", # 国家
"city": "西安市", # 城市
"district": "临潼区", # 区、县
"province": "陕西省", # 省
"township": "", # 可以不填
"street": "", # 可以不填
}
data = urlencode(sign_data)
response = requests.post(url=url, data=data, headers=header)
response = json.loads(response.text)
print(response)
if response["code"] == 0:
dk['content'] = "打卡成功"
re = requests.post(url=dkurl, data=dk)
print(re.text)
else:
dk['content'] = "打卡失败"
re = requests.post(url=dkurl, data=dk)
print(re.text)

if __name__ == '__main__':
main()

except:
dk['content'] = '运行出错,请检查'
re = requests.post(url=dkurl, data=dk)
print(re.text)

运行后返回 打卡成功 即可。

注意:以上代码仅适用于临潼校区,其他校区请修改以下代码的值

1
2
3
4
5
6
7
8
9
10
11
sign_data = {
"answers": '["0"]',
"latitude": "109.186182", # 纬度
"longitude": "34.366191", # 经度
"country": "中国", # 国家
"city": "西安市", # 城市
"district": "临潼区", # 区、县
"province": "陕西省", # 省
"township": "", # 可以不填
"street": "", # 可以不填
}

测试完毕后将py脚本2上传至服务器或使用腾讯云云函数

上传至服务器(服务器需要安装python,自行百度)

计划任务脚本内容

python3 /你的py代码路径

以上代码路劲指向你的py脚本2上传路径

教程结束