Skip to content

Instantly share code, notes, and snippets.

@chuangzhu
Last active December 13, 2022 06:35
Show Gist options
  • Save chuangzhu/3c90c0add50590ef25ed03e3d6221470 to your computer and use it in GitHub Desktop.
Save chuangzhu/3c90c0add50590ef25ed03e3d6221470 to your computer and use it in GitHub Desktop.
requests==2.28.1
pycryptodome==3.15.0
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
import re
import os
import requests
import urllib
from datetime import date
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
import random
import base64
AUTH_INIT_URL = 'https://auth.dgut.edu.cn/authserver/oauth2.0/authorize?response_type=code&client_id=1021534300621787136&redirect_uri=https%3A%2F%2Fyqfk-daka.dgut.edu.cn%2Fnew_login%2Fdgut&state=yqfk'
AUTH_URL = 'https://auth.dgut.edu.cn/authserver/login?service=https%3A%2F%2Fauth.dgut.edu.cn%2Fauthserver%2Foauth2.0%2FcallbackAuthorize%3Fclient_id%3D1021534300621787136%26redirect_uri%3Dhttps%253A%252F%252Fyqfk-daka.dgut.edu.cn%252Fnew_login%252Fdgut%26response_type%3Dcode%26client_name%3DCasOAuthClient'
YQFK_URL = 'https://yqfk-daka.dgut.edu.cn'
API_URL = 'https://yqfk-daka-api.dgut.edu.cn'
USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/82.0.4051.0 Safari/537.36 Edg/82.0.425.3'
def encrypt(data: str, key: str) -> str:
alphabet = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
key = key.strip()
data = ''.join(random.choices(alphabet, k=64)) + data
iv = ''.join(random.choices(alphabet, k=16)).encode()
cipher = AES.new(key.encode(), AES.MODE_CBC, iv=iv)
pkcs7 = pad(data.encode(), 16)
ciphertext = cipher.encrypt(pkcs7)
return base64.b64encode(ciphertext).decode()
session = requests.Session()
session.headers.update({'Connection': 'keep-alive',
'Referer': YQFK_URL,
'User-Agent': USER_AGENT})
session.get(AUTH_INIT_URL)
origin = session.get(AUTH_URL)
html = origin.text
salt = re.search('<input type="hidden" id="pwdEncryptSalt" value="(.*?)" />', html).group(1)
execution = re.search('<input type="hidden" id="execution" name="execution" value="(.*?)" />', html).group(1)
if os.sys.argv[1] == '-c':
config = open(os.sys.argv[2]).readlines()
username = config[0].strip()
password = config[1].strip()
else:
username = os.sys.argv[1]
password = os.sys.argv[2]
session.headers.update({'Origin': 'https://auth.dgut.edu.cn',
'Referer': AUTH_URL})
auth_payload = {'username': username,
'password': encrypt(password, salt),
'captcha': '',
'_eventId': 'submit',
'cllt': 'userNameLogin',
'dllt': 'generalLogin',
'lt': '',
'execution': execution}
redirected = session.post(AUTH_URL, data=auth_payload, allow_redirects=False)
while redirected.headers.get('Location') is not None:
redirected = session.get(redirected.headers.get('Location'), allow_redirects=False)
callback_query = urllib.parse.urlparse(redirected.url).query
token = urllib.parse.parse_qs(callback_query)['code'][0]
session.headers.update({'Accept': 'application/json',
'Origin': YQFK_URL,
'Referer': f'{YQFK_URL}/'})
session.options(f'{API_URL}/auth')
auth = session.post(f'{API_URL}/auth', json={'state': 'yqfk', 'token': token})
access_token = auth.json()['access_token']
session.headers.update({'Authorization': 'Bearer ' + access_token})
fetched_info = session.get(f'{API_URL}/record/').json()
base_info = fetched_info['user_data']
base_info['submit_time'] = date.today().isoformat()
base_info['body_temperature'] = f'{random.uniform(36.1, 37.2):.1f}'
base_info['health_situation'] = 1
base_info['is_in_school'] = 1
base_info.pop('is_en', None)
base_info.pop('is_important_area_people', None)
base_info.pop('created_time', None)
base_info.pop('faculty_id', None)
base_info.pop('class_id', None)
base_info.pop('grade_name', None)
base_info.pop('last_submit_time', None)
base_info.pop('off_campus_person_type', None)
base_info.pop('reset_times', None)
base_info.pop('submit_times', None)
base_info.pop('is_reset_submit', None)
base_info.pop('jiguan_district', None)
base_info.pop('huji_district', None)
base_info.pop('holiday_go_out', None)
base_info.pop('school_connect_person', None)
base_info.pop('school_connect_tel', None)
base_info.pop('have_diagnosis', None)
base_info.pop('diagnosis_result', None)
base_info.pop('processing_method', None)
base_info.pop('important_area', None)
base_info.pop('leave_important_area_time', None)
base_info.pop('last_time_contact_hubei_people', None)
base_info.pop('last_time_contact_illness_people', None)
base_info.pop('plan_back_dg_time', None)
base_info.pop('back_dg_transportation', None)
base_info.pop('plan_details', None)
base_info.pop('finally_back_time', None)
base_info.pop('finally_back_transportation', None)
base_info.pop('finally_plan_details', None)
base_info.pop('recent_travel_situation', None)
base_info.pop('acid_test_results', None)
base_info.pop('two_week_itinerary', None)
base_info.pop('focus_area', None)
base_info.pop('plan_vaccination_date', None)
base_info.pop('holiday_travel_situation', None)
base_info.pop('current_street', None)
base_info.pop('current_community_and_house', None)
base_info.pop('end_isolation_time', None)
base_info.pop('current_region_name', None)
base_info.pop('request_health_code_api', None)
base_info.pop('origin_acid_test_from_api', None)
base_info.pop('request_acid_test_api', None)
base_info.pop('request_ymjz_api', None)
base_info.pop('change_comment', None)
base_info.pop('is_change', None)
base_info.pop('body_temperature_origin', None)
base_info.pop('health_situation_origin', None)
base_info.pop('is_in_school_origin', None)
result = session.post(f'{API_URL}/record/', json={'data': base_info})
message = result.json()['message']
if '已经提交' not in message and '成功' not in message:
print(message)
os.sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment