前言
写了一个简单地程序
定时日报加发邮件提醒状态
本质:发送了一个请求(保存/更新)
流程:
fiddler获取登录header,data,token等数据- >postman尝试发送请求 ->postman生成py代码 ->增添发送邮件模块->服务器定时运行脚本
fiddler获取请求数据
下载fiddler(略)
打开fiddler,同时打开wx,健康日报(可以先清空一下)。
这时fillder会截取到发送的数据和请求的类型
把传送的数据和请求头都记录下来,放到postman上,postman发送请求测试。成功则生成py代码
完整代码:
import smtplib
from email.mime.text import MIMEText
mailserver = "mail.qq.com"
username_send = 'xxx@qq.com'
password = 'yourpwd'
username_recv = 'xxx@qq.com'
def sendEmil(status):
if status==1:
mail = MIMEText('上报成功')
mail['Subject'] = '您的健康日报上报成功'
else:
mail = MIMEText('上报失败')
mail['Subject'] = '您的健康日报上报失败'
mail['From'] = username_send
mail['To'] = username_recv
smtp=smtplib.SMTP_SSL('smtp.qq.com',port=465)
smtp.login(username_send,password)
smtp.sendmail(username_send,username_recv,mail.as_string()
smtp.quit()
import requests
url = "https://xg.nyist.vip/v1/trace/Student/dailyreportadd"
payload={'location': '1',
'pcc': '410000,411300,411302',
'gps': '32.99073,112.52851'}
files=[
]
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat',
'guest': 'b2w4YlB2X3osNzMzOCxUNjVHNTBKTCwxNjMwMjkwMzU5LjUxMjMsRWRLVm9CVlpYeHdBLDMyOGIzOWI3ZTMzYjlmOTRlZjk2MGM5NDFjOTA0YmNi',
'Referer': 'xxx',
'token': 'xxx',
'content-type': 'application/x-www-form-urlencoded',
'appid': '1',
'Accept': 'application/json, text/plain, */*',
'Cookie': 'xxx'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
import json
res=json.loads(response.text)
if res['msg']=='上报成功':
sendEmil(1)
else:
sendEmil(0)
放到服务器定时运行
00 8 * * * root /usr/bin/python3 /home/name.py
每天8点准时健康日报,并且把健康日报状态以邮件的方式告诉你