Python实现手机APP之自动打卡签到详细教程(小白合适)

前言每天一大早就被测温员吵醒 , 睡不好觉 , 于是国庆的时候 , 朋友在网上找到了一个大佬的教程looyeagee并修改出了一个适合我们学校的易班APP自动填写的脚本洛柒尘 , 但是他们脚本都是要在电脑执行比较方便 , 但是每天懒狗就是不想动 , 还有就是有些测温员在测温的时候他们在干别的事情就忘记填了 , 于是我就根据这两位大佬的基础上进行修改 , 然后就能不能不用电脑 , 直接用手机设置一波操作 , 为了让懒狗更加多时间不被吵醒 , 顺便我也会加一个电脑操作教程 。
私信小编01即可获取大量Python学习资料
我建议还是接受测温员的测温 , 学校这样做是为了每一位学生的安全 , 由于今年的新冠疫情 , 虽然我国在抗疫获得很不错的效果 , 但是目前国外还有很多人被感染了 , 我们还是不能放松 。 我这个教程只不过想懒得看手机和有时候忘记了填 , 就想给负责人减少一些工作负担 , 还是要啰嗦的提醒一点 , 必须测温 , 必须测温 , 必须测温 , 希望大家身体都健健康康
注意:我这个教程就是从洛柒尘这位大佬博客基础上再加一个电脑和手机上操作详细的教程 , 这个只适合江门职业技术学院 , 如果是其他学校的同学 , 需要重新抓包修改 , 这个脚本是可以读到创建的所有程序 , 通过修改可以提交几天后的任务都可以 , 但前提是发布人有创建这个任务(有些任务是到点才显示出来 , 只有通过读取数据才能发现)
我是在Linux系统运行python脚本 , 因为懒狗就不想在window和MacOS安装一个python环境
代码import reimport timeimport requestsimport jsonimport osimport urllibdef get_user():account = []passwd = []state = 0name_file = '/root/data/username.txt';pass_file = '/root/data/password.txt';try:f = open(name_file, mode='r');lines = f.readlines();for line in lines:conn = line.strip('\n');account.append(conn);f.close();except:state = 1;try:f = open(pass_file, mode='r');lines = f.readlines();for line in lines:conn = line.strip('\n');passwd.append(conn);f.close();except:state = 1;return account, passwd, state;def get_time_stamp():now_time = time.localtime(time.time());if now_time[3] == 7 or now_time[3] == 8 or now_time[3] == 9:start_time = '7:00:00';elif now_time[3] == 11 or now_time[3] == 12 or now_time[3] == 13:start_time = '11:00:00';elif now_time[3] >= 17 and now_time[3] <= 22:start_time = '17:30:00';else:return 1;now_year = str(now_time[0]);now_mouth = str(now_time[1]);now_day = str(now_time[2]);fixed_time = (str(now_year + '-' + now_mouth + '-' + now_day + ' ' + start_time));fixed_time = time.strptime(fixed_time, "%Y-%m-%d%H:%M:%S");timestamp = int(time.mktime(fixed_time));return timestamp;#登录页面def login(account, passwd, csrf, csrf_cookies, header):params = {"account": account,"ct": 1,"identify": 1,"v": "4.7.12","passwd": passwd}login_url = '';login_r = requests.get(login_url, params=params);login_json = login_r.json();user_name = login_json['data']['user']['name'];access_token = login_json['data']['access_token'];return user_name, access_token;#二次认证def auth(access_token, csrf, csrf_cookies, header):auth_first_url = ';v=' + access_token + '';auth_first_r = requests.get(auth_first_url, timeout=10, headers=header, allow_redirects=False).headers['Location'];verify_request = re.findall(r"verify_request=(.*?)auth_second_url = '' + verify_request + 'auth_result = requests.get(auth_second_url, timeout=10, headers=header, cookies=csrf_cookies);auth_cookie = auth_result.cookies;auth_json = auth_result.json();return auth_cookie;'''def get_complete_list(csrf,csrf_cookies,auth_cookie,header):complete_url = '{}'.format(csrf);result_cookie = {'csrf_token': csrf,'PHPSESSID': auth_cookie['PHPSESSID'],'cpi': auth_cookie['cpi']}complete_r = requests.get(complete_url, timeout = 10, headers = header, cookies = result_cookie);task_num = len(complete_r.json()['data']);time = get_time_stamp();for i in range(0, task_num):task_time = complete_r.json()['data'][i]['StartTime'];if time == task_time:task_id = complete_r.json()['data'][i]['TaskId'];get_task_detail(task_id, csrf, result_cookie, header);break;'''#未完成的任务def get_uncomplete_list(csrf, csrf_cookies, auth_cookie, header):uncomplete_url = '{}'.format(csrf);result_cookie = {'csrf_token': csrf,'PHPSESSID': auth_cookie['PHPSESSID'],'cpi': auth_cookie['cpi']}uncomplete_r = requests.get(uncomplete_url, timeout=10, headers=header, cookies=result_cookie);task_num = len(uncomplete_r.json()['data']);for i in range(0, task_num):task_time = uncomplete_r.json()['data'][i]['StartTime'];time = get_time_stamp();if time == task_time:task_id = uncomplete_r.json()['data'][i]['TaskId'];user_state = 0;return task_id, result_cookie, user_state;break;#获取表单信息def get_task_detail(task_id, csrf, result_cookie, header):task_detail_url = '{0}task_detail_r = requests.get(task_detail_url, timeout=10, headers=header, cookies=result_cookie);task_result = task_detail_r.json();task_wfid = task_result['data']['WFId'];return task_result, task_wfid;#提交表单def task_submit(task_wfid, csrf, result_cookie, header, task_result):extend = {"TaskId": task_result['data']['Id'],"title": "任务信息","content": [{"label": "任务名称", "value": task_result['data']['Title']},{"label": "发布机构", "value": task_result['data']['PubOrgName']},{"label": "发布人", "value": task_result['data']['PubPersonName']}]}data = http://kandian.youth.cn/index/{"0caddc48d709afde9cc4986b3a85155e": "36.5","a4f42d8428d2d4ca3f4562ff86305eb0": {"name": "江门职业技术学院6栋宿舍楼","location": "113.104625,22.628090","address": "潮连街道潮连大道6号江门职业技术学院"}}params = {'data': json.dumps(data),'extend': json.dumps(extend)}task_submit_url = '{0}?CSRF={1}'.format(task_wfid, csrf);task_submit_r = requests.post(task_submit_url, timeout=10, headers=header, cookies=result_cookie, data=http://kandian.youth.cn/index/params);return task_submit_r.json()['data'];#运行程序def start():csrf = "365a9bc7c77897e40b0c7ecdb87806d9"csrf_cookies = {"csrf_token": csrf}header = {"Origin": "", "User-Agent": "yiban"}get_time_stamp();account, passwd, state = get_user();if state == 1:print('账号或者密码文件打开有误');exit();if len(account) != len(passwd):print('账号和密码数量不一致');exit();for i in range(0, len(account)):print(account[i]);try:user_name, access_token = login(account[i], passwd[i], csrf, csrf_cookies, header);try:auth_cookie = auth(access_token, csrf, csrf_cookies, header);try:task_id, result_cookie, user_state = get_uncomplete_list(csrf, csrf_cookies, auth_cookie, header);try:task_result, task_wfid = get_task_detail(task_id, csrf, result_cookie, header);try:conncet = task_submit(task_wfid, csrf, result_cookie, header, task_result);if connect != '':print(user_name + '完成');except:print(user_name + '提交成功');except:print('');except:print(user_name + '没有获取到未完成的任务');continue;except:print(user_name + '没有获取到cookie');continue;except:print(user_name + '账号或者密码错误');continue;#脚本自动跑if __name__ == '__main__':def time_sleep(n):while True:a = get_time_stamp();now_time = time.localtime(time.time());print(str(now_time[1]) + '-' + str(now_time[2]) + ' ' + str(now_time[3]) + ':' + str(now_time[4]) + ':' + str(now_time[5]));start();if (now_time[3] >= 7 and now_time[3]