Skip to content

Instantly share code, notes, and snippets.

@typenoob
Last active January 18, 2022 07:08
Show Gist options
  • Save typenoob/858083fb15ae0d4dc9c787e6fa78bc3c to your computer and use it in GitHub Desktop.
Save typenoob/858083fb15ae0d4dc9c787e6fa78bc3c to your computer and use it in GitHub Desktop.
青龙面板打卡脚本(浙江理工大学)
from Crypto.Cipher import DES
from Crypto.Util import Padding
from base64 import b64encode, b64decode, encode
from requests import Session
from re import compile
import os
import logging
import sys
logger = logging.getLogger(name=None) # 创建一个日志对象
logging.Formatter("%(message)s") # 日志内容格式化
logger.setLevel(logging.INFO) # 设置日志等级
logger.addHandler(logging.StreamHandler()) # 添加控制台日志
# logger.addHandler(logging.FileHandler(filename="text.log", mode="w")) # 添加文件日志
def load_send() -> None:
logger.info("加载推送功能中...")
global send
send = None
cur_path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(cur_path)
if os.path.exists(cur_path + "/notify.py"):
try:
from notify import send
except Exception:
send = None
logger.info(f"❌加载通知服务失败!!!\n{traceback.format_exc()}")
class ZstuSso:
def __init__(self, username: str, password: str) -> None:
if username == None or password == None:
raise RuntimeError
self.__username = username
self.__password = password
self.__session = Session()
def login(self) -> Session:
login_url = 'https://sso.zstu.edu.cn/login'
res = self.__session.get(login_url).text
execution, croypto = self.__get_execution_and_crypto(res)
payload = \
{
'username': self.__username,
'type': 'UsernamePassword',
'_eventId': 'submit',
'geolocation': '',
'execution': execution,
'captcha_code': '',
'croypto': croypto,
'password': self.__encrypto_password(croypto),
}
res = self.__session.post(login_url, payload, allow_redirects=False)
if len(res.content) != 0:
raise RuntimeError('Failed')
def get_session(self):
return self.__session
def __get_execution_and_crypto(self, data: str):
execution_pat = compile('<p id="login-page-flowkey">(.*?)</p>')
crypto_pat = compile('<p id="login-croypto">(.*?)</p>')
return execution_pat.search(data).group(1), crypto_pat.search(data).group(1)
def __encrypto_password(self, key: str) -> str:
key = b64decode(key)
enc = DES.new(key, DES.MODE_ECB)
data = Padding.pad(self.__password.encode('utf-8'), 16)
return b64encode(enc.encrypt(data))
class Report():
def __init__(self, session) -> None:
self.session = session
self.location = env.get('location')
self.vaccination_date = env.get('vaccination_date')
if self.location == None or self.vaccination_date == None:
raise RuntimeError
def report(self):
null = None
false = False
true = True
url = 'http://fangyi.zstu.edu.cn:6006/'
data = {"biz": {"GUID": "1243207709E34319A7EA51587", "CURRENTLOCATION": self.location, "CURRENTSITUATION": "低风险地区", "ARRIVESTATUS": "不在(入)校", "TEMPERATURESITUATION": "正常", "TEMPERATURE": "", "HEALTHCODESTATUS": "绿码", "VACCINATIONSTATUS": "已完成首轮全部针剂", "ZHJZSJ": self.vaccination_date, "WJZYY": "", "JTYY": "", "CONFIRMEDSTATE": "无", "CONFIRMEDDATETIME": null, "CONFIRMEDQUARANTINEDATETIME": null, "CONFIRMEDRELIEVEDATETIME": null, "QUARANTINESTATUS": "未隔离", "NOTIFICATIONMODE": "", "QUARANTINEREASON": "", "QUARANTINETYPE": "", "QUARANTINELOCATION": "", "QUARANTINESTARTTIME": "", "ESTIMATEQUARANTINEENDTIME": "", "PROCESSES": "", "LIVINGHISTORYSTATUS": "无",
"LIVINGHISTORYSTATUS1": "", "LIVINGHISTORYLOCATION": "", "SFYHSYXBG": "", "HSJCSJ": "", "HSJCDD": "", "TZRY": "否", "TZRYSM": "", "TJ_QRNR": "上述内容客观如实填写,填写人对本表真实性负责,如瞒报、虚报产生不良后果,承担相应责任。", "DKLX": "本人打卡", "CLR": "陈裕涛", "CLSJ": null, "ZHXGR": null, "XGNR": null, "ZHXGSJ": "2022-01-18"}, "task": {}, "sign": {}, "user": {"userId": "ZSTU/2019329600124", "userName": "陈裕涛", "domain": "ZSTU"}, "conf": {"bizId": "1243207709E34319A7EA51587", "platform": "Weixin", "IsDraft": false, "IsDeleteDraft": false}, "form": {"formId": "1817056F47E744D3B8488B", "formName": "疫情填报(学生)"}, "approvalBtn": {"code": "Submit", "visible": true, "title": "提交", "size": "medium", "type": "primary"}}
self.response = self.session.post(url, data)
def get_content(self):
return self.response.content
env = os.environ
def main():
try:
t = ZstuSso(env.get('sno'), env.get('password'))
s = t.get_session()
r = Report(s)
r.report()
load_send()
if send:
send("任务执行结果:", f"\n{r.get_content()}")
print(r.get_content())
except:
logger.info('❌没有设置环境变量')
if __name__ == '__main__':
main()
@typenoob
Copy link
Author

环境变量

  • sno 学号
  • password 密码
  • location 位置(格式:省 市 区)
  • vaccination_date 接种日期(格式:YYYY-MM-DD HH-MM-SS)

@typenoob
Copy link
Author

依赖

  • pycryptodome
  • requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment