记一次利用python在企业微信校园健康天天报并给自己发送通知邮箱
#0x00 前言
写在前头:本教程仅供交流学习使用,严禁用于非法违规用途。
主要意图是带大家认识python requests模块post和get请求使用,无不良用意。
学校需要每天进行健康天天报,虽然是一件容易的事情,但也容易遗忘掉,除了设置手机提醒,想着尝试做一个每天自动校园天天报的程序,到最后也还算成功了一半吧(code值找不到变化规律,也就确定不了最新的cookie值),起码主体逻辑已经实现。效果图如下:(图一)
#0x01 正文
首先利用抓包软件(我在这里用的burp)连接手机抓包,打开健康天天报,点击上报按钮,会获取到上次的上报信息:(图二)
我们在代码中利用requests模拟这个post请求,同样获取到响应:(图三)
把获取到的信息处理一下,并根据数据值利用注释对应标注:(图四)
再在手机上健康天天报中提交上报,抓包中显示数据:(图五)
利用(图三)同样的post提交方式把如上请求在python复现,并进行数据处理,返回值为赋值后的report_data(上报数据):
把返回的上报数据参数传入 发送邮箱 函数,进行发送邮箱:
至此便结束
#0x03 代码
import json
import requests
from datetime import date
import time
import pymysql
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
def time_processing():
ten_timeArray = time.localtime(time.time())
ten_otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", ten_timeArray)
return str(ten_otherStyleTime)
def Send_mail(body, receiver):
my_sender = 'denceun@qq.com' # 发件人邮箱账号
my_pass = '此处放邮箱授权吗' # 发件人邮箱授权码
my_user = receiver # 收件人邮箱账号,我这边发送给自己
def mail():
ret = True
try:
msg = MIMEText(body, 'plain', 'utf-8')
msg['From'] = formataddr(["思维", my_sender]) # 括号里的对应发件人邮箱昵称、发件人邮箱账号
msg['To'] = formataddr(["", my_user]) # 括号里的对应收件人邮箱昵称、收件人邮箱账号
msg['Subject'] = "HealthyReport" # 邮件的主题,也可以说是标题
server = smtplib.SMTP_SSL("smtp.qq.com", 465) # 发件人邮箱中的SMTP服务器,端口是25
server.login(my_sender, my_pass) # 括号中对应的是发件人邮箱账号、邮箱授权码
server.sendmail(my_sender, [my_user, ], msg.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
server.quit() # 关闭连接
except Exception: # 如果 try 中的语句没有执行,则会执行下面的 ret=False
ret = False
return ret
ret = mail()
if ret:
print("邮件发送成功")
else:
print("邮件发送失败")
def getUserInfo(userId, day, Cookie, QQmail):
healthy_url = "https://fwpt.sxgcxy.cn:4443/microapp/health_daily/alreadyReport?userId=" + userId + "&day=" + day
# print(healthy_url)
headers = {
"Host": "fwpt.sxgcxy.cn:4443",
"Cookie": Cookie,
"User-Agent": "Mozilla/5.0 (Linux; Android 10; TEL-AN00 Build/HONORTEL-AN00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.72 MQQBrowser/6.2 TBS/046125 Mobile Safari/537.36 wxwork/4.0.19 MicroMessenger/7.0.1 NetType/WIFI Language/zh Lang/zh ColorScheme/Dark",
"Origin": "https://fwpt.sxgcxy.cn:4443"
}
request_data = {
"Cookie": Cookie
}
UserInfo = requests.post(url=healthy_url, headers=headers, json=request_data)
# print(UserInfo.text)
data = json.loads(UserInfo.text)["data"]
if data:
data1 = json.dumps(data[0])
stu_id = json.loads(data1)["id"] # 学生id(不知道是啥)
userId = json.loads(data1)["userId"] # 学号
username = json.loads(data1)["username"] # 姓名
address = json.loads(data1)["address"] # 地址 山西工程职业学院(唐槐校区)
distance = json.loads(data1)["distance"] # 距离 距离上次上报距离
longitude = json.loads(data1)["longitude"] # 经度
latitude = json.loads(data1)["latitude"] # 纬度
temperature = json.loads(data1)["temperature"] # 温度
province = json.loads(data1)["province"] # 省份 山西省
city = json.loads(data1)["city"] # 市 太原市
county = json.loads(data1)["county"] # 区 小店区
billingContactName = json.loads(data1)["billingContactName"] # 监护联系人姓名
billingContactNameTel = json.loads(data1)["billingContactNameTel"] # 联系人电话
orgname = json.loads(data1)["orgname"] # 班级 软件2105
plusinfo = json.loads(data1)["plusinfo"] # 设备、网络、版本、浏览器内核等信息
healthCondition = json.loads(data1)["healthCondition"] # 健康状态 : 正常
familyCondition = json.loads(data1)["familyCondition"] # 家庭健康状况 :正常
healthCodeState = json.loads(data1)["healthCodeState"] # 健康码状态 :绿色
gtjzrhHealthCode = json.loads(data1)["gtjzrhHealthCode"] # 同居人健康码 : 绿色
jzdfxdj = json.loads(data1)["jzdfxdj"] # 居住地风险地区 : 无风险
nowOwnerState = json.loads(data1)["nowOwnerState"] # 当前状态 : 正常
report_data = {
"address": address, "locationErrorExplain": "null", "province": province, "city": city,
"county": county,
"distance": distance, "longitude": longitude, "latitude": latitude, "temperature": temperature,
"healthCondition": healthCondition,
"healthConditionExplain": "null", "familyCondition": familyCondition, "familyConditionExplain": "null",
"healthCodeState": healthCodeState,
"gtjzrhHealthCode": gtjzrhHealthCode, "jzdfxdj": jzdfxdj, "nowOwnerState": nowOwnerState,
"recentlyGoArea": "null",
"recentlyGoAreaExplain": "null", "ifContactCase": "null", "ifContactCaseExplain": "null",
"ifContactAreaBackPerson": "null", "ifContactAreaBackPersonExplain": "null", "ifContactRjry": "null",
"ifContactRjryExplain": "null", "ifReturnToSchool": "null", "ifReturnToSchoolExplain": "null",
"billingContactName": billingContactName, "billingContactNameTel": billingContactNameTel,
"specialSituation": "null",
"ifFromToFocusArea": "null", "ifFromToFocusAreaExplain": "", "fileUrl": "", "isReturnSchool": "null",
"returnSchoolDesc": "", "isQuarantine": "null", "quarantineDesc": "", "isReturnHome": "null",
"returnHomeDesc": "",
"time": time_processing(),
"plusinfo": plusinfo,
"id": stu_id
}
results = (report(report_data, Cookie))
# print(results)
Send_mail(results, QQmail)
else:
print("上报失败")
def report(report_data, Cookie):
report_url = "https://fwpt.sxgcxy.cn:4443/microapp/health_daily/report"
report_headers = {
"Host": "fwpt.sxgcxy.cn:4443",
"Cookie": Cookie,
"User-Agent": report_data["plusinfo"],
"Origin": "https://fwpt.sxgcxy.cn:4443"
}
reports = requests.post(url=report_url, headers=report_headers, json=report_data)
if reports:
reports_data = ("您今日已经上报成功!!!\n" + "上报数据:\n"+"地址:" + str(report_data["province"]) + str(report_data["city"]) + str(report_data["county"]) + str(report_data["address"]) + "\n与上次上报距离:" + str(report_data["distance"]) + " 上报时间:" + str(report_data["time"]) + "\n健康状态:" + str(report_data["healthCondition"]) + " 家庭健康状况:" + str(report_data["familyCondition"]) + "\n健康码状态:" + str(report_data["healthCodeState"]) + " 同住人员健康码状态:" + str(report_data["gtjzrhHealthCode"]) + "\n监护人姓名:" + str(report_data["billingContactName"]) + " 监护人联系方式:" + str(report_data["billingContactNameTel"]) + "\n居住地风险:" + str(report_data["jzdfxdj"]) + " 当前状态:" + str(report_data["nowOwnerState"]))
return reports_data
else:
return "上报失败"
# print(json.loads(reports.text)["msg"])
def User_data():
db = pymysql.connect(host="localhost", port=3306, user="root", password="root", database="HealthyReport")
cur = db.cursor()
table_name = "UserInfo"
for i in range(1, 999999):
sqlQuery = "SELECT * FROM " + table_name + " WHERE id = "+str(i) + ";"
try:
cur.execute(sqlQuery)
results = cur.fetchall()
if len(results) != 0:
day = date.fromtimestamp(time.time())
print("正在进行 " + results[0][1] + " 同学的上报操作...")
getUserInfo(str(results[0][2]), str(day), str(results[0][3]), str(results[0][4]))
print("已经完成 " + results[0][1] + " 同学的上报操作...请注意邮箱查收上报消息")
else:
break
except pymysql.Error as e:
print("数据查询失败:" + str(e))
if __name__ == '__main__':
User_data()
运行此代码需要数据库环境,创建数据库,并在148行编辑连接数据库:
#0x04 后记
cookie会总是变,目前研究到code值的变化规律,懒得弄了,如果有大佬研究出来跪求教我一下。
最后再声明一遍,本代码教程仅用于学习,用于非法用途与本人无关
阅读剩余
版权声明:
作者:admin
链接:https://www.denceun.com/archives/60
文章版权归作者所有,未经允许请勿转载。
THE END