def get_job_list(token): """ :param token: :return: """ talents_token = get_talents_token(token) headers = { "talents_token": talents_token, "content-type": "application/json;charset=UTF-8" } session = requests.session() try: session.post(f"https://api.xiaozhao365.com/jyb/pub/iface/userTalentsToken?token={talents_token}", headers=headers) except: pass post_json = {"cityCode": 310100, "keyword": "", "jobType": 1, "pageNumber": 1, "pageSize": 20} try: res = session.post("https://api.xiaozhao365.com/jyb/pub/iface/search/getRecommendJobsByEs", json=post_json, headers=headers).json() if not res['code']: log.info("查看校招实习成功") else: log.warning(f"{res} 查看校招实习失败") except Exception as e: log.warning(f"{e} 查看校招实习失败")
def info_push(push_dict, raw_info): push_funcs = { "email": wanxiao_email_push, "wechat": wanxiao_server_push, "qmsg": wanxiao_qmsg_push, "pipehub": wanxiao_pipe_push, "wechat_enterprise": wanxiao_wechat_enterprise_push } push_raw_info = { "check_info_list": raw_info } for push_name, push_func in push_funcs.items(): enable = push_dict.get(push_name, {}).get("enable") if not enable: pass else: del push_dict[push_name]["enable"] push_dict[push_name].update(push_raw_info) params_dict = push_dict[push_name] push_res = push_func(**params_dict) if push_res['status']: log.info(push_res["msg"]) else: log.warning(push_res["errmsg"])
def get_healthy2_check_posh_json(token): """ 获取第二类健康打卡的打卡数据 :param token: 用户令牌 :return: 返回dict数据 """ for _ in range(3): try: res = requests.post( url="https://reportedh5.17wanxiao.com/api/reported/recall", data={ "token": token }, timeout=10, ).json() except: log.warning("完美校园第二类健康打卡post参数获取失败,正在重试...") time.sleep(1) continue if res["code"] == 0: log.info("完美校园第二类健康打卡post参数获取成功") return res["data"] else: log.warning(f"完美校园第二类健康打卡post参数获取失败,{res}") return None
def info_push(push_dict, raw_info): flag = [] if push_dict['wechat']['enable']: push = wanxiao_server_push(push_dict['wechat']['send_key'], raw_info) if push['status']: flag.append(1) log.info(push['msg']) else: flag.append(0) log.warning(push['errmsg']) if push_dict['email']['enable']: push = wanxiao_email_push(push_dict['email']['send_email'], push_dict['email']['send_pwd'], push_dict['email']['receive_email'], push_dict['email']['smtp_address'], push_dict['email']['smtp_port'], raw_info) if push['status']: flag.append(1) log.info(push['msg']) else: flag.append(0) log.warning(push['errmsg']) if push_dict['qmsg']['enable']: push = wanxiao_qmsg_push(push_dict['qmsg']['key'], push_dict['qmsg']['qq_num'], push_dict['qmsg']['type'], raw_info) if push['status']: flag.append(1) log.info(push['msg']) else: flag.append(0) log.warning(push['errmsg']) if push_dict['pipehub']['enable']: push = wanxiao_pipe_push(push_dict['pipehub']['key'], raw_info) if push['status']: flag.append(1) log.info(push['msg']) else: flag.append(0) log.warning(push['errmsg']) if push_dict['wechat_enterprise']['enable']: push = wanxiao_wechat_enterprise_push( push_dict['wechat_enterprise']['corp_id'], push_dict['wechat_enterprise']['corp_secret'], push_dict['wechat_enterprise']['agent_id'], push_dict['wechat_enterprise']['to_user'], raw_info) if push['status']: flag.append(1) log.info(push['msg']) else: flag.append(0) log.warning(push['errmsg']) if 1 in flag: return True return False
def campus_check_in(phone, token, post_dict, custom_rule_id): """ 校内打卡 :param phone: 电话号 :param token: 用户令牌 :param post_dict: 校内打卡数据 :param custom_rule_id: 校内打卡id :return: """ check_json = { "businessType": "epmpics", "method": "submitUpInfoSchool", "jsonData": { "deptStr": post_dict["deptStr"], "areaStr": post_dict["areaStr"], "reportdate": round(time.time() * 1000), "customerid": post_dict["customerid"], "deptid": post_dict["deptid"], "source": "app", "templateid": post_dict["templateid"], "stuNo": post_dict["stuNo"], "username": post_dict["username"], "phonenum": phone, "userid": post_dict["userid"], "updatainfo": post_dict["updatainfo"], "customerAppTypeRuleId": custom_rule_id, "clockState": 0, "token": token, }, "token": token, } try: res = requests.post( "https://reportedh5.17wanxiao.com/sass/api/epmpics", json=check_json ).json() """ {'msg': '业务异常', 'code': '10007', 'data': '请在正确的打卡时间打卡'} """ if res["code"] == "10000": log.info(res) elif res['data'] == "areaStr can not be null": log.warning("当前用户无法获取校内打卡地址信息,请前往配置文件,campus_checkin 下的 areaStr 设置地址信息") elif res['data'] == "请在正确的打卡时间打卡": log.warning( f'当前已不在该打卡时间范围内,{res["data"]}') else: log.warning(res) return { 'status': 1, 'res': res, 'post_dict': post_dict, 'check_json': check_json, 'type': post_dict["templateid"] } except: errmsg = f"```校内打卡请求出错```" log.warning("校内打卡请求出错") return {'status': 0, 'errmsg': errmsg}
def get_class_score(token): post_json = {"token": token, "command": "CURRI_SERVER.WEEK_CURRI", "week": ""} try: res = requests.post("https://course.59wanmei.com/campus-score/curriculum/_iface/server/invokInfo.action", json=post_json) if res.status_code == 200: log.info("查看课表成功") else: log.warning("查看课表失败") except Exception as e: log.warning(f"{e} 查看课表失败")
def get_token(username, password, device_id): try: campus_login = CampusLogin(phone_num=username, device_id=device_id) except Exception as e: log.warning(e) return None login_dict = campus_login.pwd_login(password) if login_dict["status"]: log.info(f"{username[:4]},{login_dict['msg']}") return login_dict["token"] else: log.warning(f"{username[:4]},{login_dict['errmsg']}") return None
def main_handler(*args, **kwargs): # 推送数据 raw_info = [] # 加载用户配置文件 user_config_dict = load_config(kwargs['user_config_path']) for user_config in user_config_dict: if not user_config['phone']: continue log.info(user_config['welcome']) # 单人打卡 check_dict = check_in(user_config) # 单人推送 if info_push(user_config['push'], check_dict): pass else: log.info("当前用户并未配置 push 参数,将统一进行推送") raw_info.extend(check_dict) # 统一推送 if raw_info: all_push_config = load_config(kwargs['push_config_path']) if info_push(all_push_config, raw_info): pass else: log.info('统一推送未开启,如要开启,请修改 conf/push.json 配置文件') else: log.info('所有打卡数据已推送完毕,无需统一推送')
def ykt_check_in(token): """ 获取签到粮票 :param token: """ data = f"token={token}" \ "&method=WX_h5signIn" \ f"¶m=%7B%22token%22%3A%22{token}%22%7D" headers = { 'content-type': 'application/x-www-form-urlencoded' } try: res = requests.post("https://server.17wanxiao.com/YKT_Interface/xyk", data=data, headers=headers).json() log.info(res['data']['alertMessage']) except: log.warning("签到失败")
def get_circle_score(token, circle_dict): """ 获取其他奖励 """ data = f"token={token}" \ "&method=gainScoreCircle" \ f"¶m=%7B%22token%22%3A%22{token}%22%2C%22scoreCircleId%22%3A{circle_dict['id']}%7D" headers = { 'content-type': 'application/x-www-form-urlencoded' } try: res = requests.post("https://server.17wanxiao.com/YKT_Interface/score", data=data, headers=headers).json() msg = f'{circle_dict["title"]}({circle_dict["id"]}):{circle_dict["foodCoupon"]}个粮票,' if res['result_']: log.info(msg + res['message_']) else: log.warning(msg + res['message_']) except Exception as e: log.warning(f'{e.__class__}:{e}操作失败')
def get_token(username, password, device_id): try: campus_login = CampusLogin(phone_num=username, device_id=device_id) except Exception as e: log.warning(e) return None login_dict = campus_login.pwd_login(password) if login_dict["status"]: log.info(f"{username[:4]},{login_dict['msg']}") return login_dict["token"] elif login_dict['errmsg'] == "该手机号未注册完美校园": log.warning(f"{username[:4]},{login_dict['errmsg']}") return None elif login_dict['errmsg'].startswith("密码错误"): log.warning(f"{username[:4]},{login_dict['errmsg']}") log.warning("代码是死的,密码错误了就是错误了,赶紧去查看一下是不是输错了!") return None else: return None
def main_handler(*args, **kwargs): # 推送数据 raw_info = [] # 加载用户配置文件 user_config_dict = load_config(kwargs['user_config_path']) for user_config in user_config_dict: if not user_config['phone']: continue log.info(user_config['welcome']) # 单人打卡 check_dict = check_in(user_config) # 单人推送 info_push(user_config['push'], check_dict) raw_info.extend(check_dict) # 统一推送 all_push_config = load_config(kwargs['push_config_path']) info_push(all_push_config, raw_info)
def main_handler(*args, **kwargs): # 推送数据 raw_info = [] # 加载用户配置文件 user_config_path = kwargs['user_config_path'] if kwargs.get('user_config_path') else './conf/user.json' push_config_path = kwargs['push_config_path'] if kwargs.get('push_config_path') else './conf/push.json' user_config_dict = load_config(user_config_path) for user_config in user_config_dict: if not user_config['phone']: continue log.info(user_config.get('welcome')) # 单人打卡 check_dict = check_in(user_config) # 单人推送 info_push(user_config['push'], check_dict) raw_info.extend(check_dict) # 统一推送 all_push_config = load_config(push_config_path) info_push(all_push_config, raw_info)
def check_in(user): check_dict_list = [] # 登录获取token用于打卡 token = get_token(user['phone'], user['password'], user['device_id']) if not token: errmsg = f"{user['phone'][:4]},获取token失败,打卡失败," log.warning(errmsg) check_dict_list.append({"status": 0, "errmsg": errmsg}) return check_dict_list # 获取个人信息 user_info = get_user_info(token) if not user_info: errmsg = f"{user['phone'][:4]},获取个人信息失败,打卡失败" log.warning(errmsg) check_dict_list.append({"status": 0, "errmsg": errmsg}) return check_dict_list log.info(f'{user_info["username"][0]}-{user_info["school"]},获取个人信息成功') healthy1_check_config = user.get('healthy_checkin', {}).get('one_check') healthy2_check_config = user.get('healthy_checkin', {}).get('two_check') if healthy1_check_config.get('enable'): # 第一类健康打卡 # 获取第一类健康打卡的参数 post_dict = get_healthy1_check_post_json(token, healthy1_check_config.get('templateid', "pneumonia")) # 合并配置文件的打卡信息 merge_post_json(post_dict, healthy1_check_config.get('post_json', {})) healthy1_check_dict = healthy1_check_in(token, user['phone'], post_dict) check_dict_list.append(healthy1_check_dict) elif healthy2_check_config.get('enable'): # 第二类健康打卡 # 获取第二类健康打卡参数 post_dict = get_healthy2_check_posh_json(token) # 合并配置文件的打卡信息 if not healthy2_check_config['post_json']['latitude'] and not healthy2_check_config['post_json']['longitude']: post_dict['latitude'] = "" post_dict['longitude'] = "" log.info('当前打卡未设置经纬度,后台会将此次打卡计为手动打卡(学校没做要求可不管)') for i, j in healthy2_check_config['post_json'].items(): if j: post_dict[i] = j healthy2_check_dict = healthy2_check_in(token, user_info["customerId"], post_dict) check_dict_list.append(healthy2_check_dict) else: log.info('当前并未配置健康打卡方式,暂不进行打卡操作') # 校内打卡 campus_check_config = user.get('campus_checkin', {}) if not campus_check_config.get('enable'): log.info('当前并未开启校内打卡,暂不进行打卡操作') else: # 获取校内打卡ID custom_type_id = user_info.get('customerAppTypeId', get_customer_type_id(token)) if custom_type_id: id_list = get_id_list_v2(token, custom_type_id) else: id_list = get_id_list_v1(token) if not id_list: log.warning('当前未获取到校内打卡ID,请尝试重新运行,如仍未获取到,请反馈') return check_dict_list for index, i in enumerate(id_list): start_end = f'{i["templateid"]} ({i.get("startTime", "")}-{i.get("endTime", "")})' log.info(f"{start_end:-^40}") # 获取校内打卡参数 campus_dict = get_campus_check_post( template_id=i['templateid'], custom_rule_id=i['id'], stu_num=user_info['stuNo'], token=token ) # 合并配置文件的打卡信息 merge_post_json(campus_dict, campus_check_config['post_json']) # 校内打卡 campus_check_dict = campus_check_in(user['phone'], token, campus_dict, i['id']) check_dict_list.append(campus_check_dict) log.info("-" * 40) # 粮票收集 if user.get('ykt_score'): ykt_check_in(token) get_all_score(token) task_list = get_task_list(token) for task in task_list: if task['name'] == '校园头条': if not task['finished']: article_id = get_article_id(token) for _ in range(8): time.sleep(1) get_article_score(token, article_id) else: log.info("校园头条任务已完成") get_all_score(token) if task['name'] == '查看课表': if not task['finished']: get_class_score(token) else: log.info("查看课表任务已完成") # 获取活跃奖励 get_active_score(token, get_score_list(token)['active'][0]) # 获取其他奖励 get_all_score(token) return check_dict_list
def get_healthy1_check_post_json(token, templateid): """ 获取打卡数据 :param token: :return: """ healthy1_check_post_json = { "businessType": "epmpics", "jsonData": { "templateid": templateid, "token": token }, "method": "userComeApp", } for _ in range(3): try: res = requests.post( url="https://reportedh5.17wanxiao.com/sass/api/epmpics", json=healthy1_check_post_json, timeout=10, ).json() except: log.warning("完美校园第一类健康打卡post参数获取失败,正在重试...") time.sleep(1) continue if res["code"] != "10000": """ {'msg': '业务异常', 'code': '10007', 'data': '无法找到该机构的投票模板数据!'} """ log.warning(f'完美校园第一类健康打卡post参数获取失败{res}') return None data = json.loads(res["data"]) post_dict = { "areaStr": data['areaStr'], "ver": data["ver"], "deptStr": data['deptStr'], "deptid": data['deptStr']['deptid'] if data['deptStr'] else None, "customerid": data['customerid'], "userid": data['userid'], "username": data['username'], "stuNo": data['stuNo'], "phonenum": data["phonenum"], "templateid": data["templateid"], "updatainfo": [{ "propertyname": i["propertyname"], "value": i["value"] } for i in data["cusTemplateRelations"]], "updatainfo_detail": [{ "propertyname": i["propertyname"], "checkValues": i["checkValues"], "description": i["decription"], "value": i["value"], } for i in data["cusTemplateRelations"]], "checkbox": [{ "description": i["decription"], "value": i["value"], "propertyname": i["propertyname"] } for i in data["cusTemplateRelations"]], } log.info("完美校园第一类健康打卡post参数获取成功") return post_dict return None
def check_in(user): check_dict_list = [] # 登录获取token用于打卡 token = get_token(user['phone'], user['password'], user['device_id']) if not token: errmsg = f"{user['phone'][:4]},获取token失败,打卡失败" log.warning(errmsg) check_dict_list.append({"status": 0, "errmsg": errmsg}) return check_dict_list # 获取个人信息 user_info = get_user_info(token) if not user_info: errmsg = f"{user['phone'][:4]},获取个人信息失败,打卡失败" log.warning(errmsg) check_dict_list.append({"status": 0, "errmsg": errmsg}) return check_dict_list log.info(f'{user_info["username"][0]}-{user_info["school"]},获取个人信息成功') healthy1_check_config = user['healthy_checkin']['one_check'] healthy2_check_config = user['healthy_checkin']['two_check'] if healthy1_check_config['enable']: # 第一类健康打卡 # 获取第一类健康打卡的参数 post_dict = get_healthy1_check_post_json(token) # 合并配置文件的打卡信息 merge_post_json(post_dict, healthy1_check_config['post_json']) healthy1_check_dict = healthy1_check_in(token, user['phone'], post_dict) check_dict_list.append(healthy1_check_dict) elif healthy2_check_config['enable']: # 第二类健康打卡 # 获取第二类健康打卡参数 post_dict = get_healthy2_check_posh_json(token) # 合并配置文件的打卡信息 if not healthy2_check_config['post_json'][ 'latitude'] and not healthy2_check_config['post_json'][ 'longitude']: post_dict['latitude'] = "" post_dict['longitude'] = "" log.info('当前打卡未设置经纬度,后台会将此次打卡计为手动打卡(学校没做要求可不管)') for i, j in healthy2_check_config['post_json'].items(): if j: post_dict[i] = j healthy2_check_dict = healthy2_check_in(token, user_info["customerId"], post_dict) check_dict_list.append(healthy2_check_dict) else: log.info('当前并未配置健康打卡方式,暂不进行打卡操作') # 校内打卡 campus_check_config = user['campus_checkin'] if not campus_check_config['enable']: log.info('当前并未开启校内打卡,暂不进行打卡操作') else: # 获取校内打卡ID custom_type_id = user_info.get('customerAppTypeId', get_customer_type_id(token)) if custom_type_id: id_list = get_id_list_v2(token, custom_type_id) else: id_list = get_id_list_v1(token) if not id_list: log.warning('当前未获取到校内打卡ID,请尝试重新运行,如仍未获取到,请反馈') return check_dict_list for index, i in enumerate(id_list): start_end = f'{i["templateid"]} ({i.get("startTime", "")}-{i.get("endTime", "")})' log.info(f"{start_end:-^40}") # 获取校内打卡参数 campus_dict = get_campus_check_post(template_id=i['templateid'], custom_rule_id=i['id'], stu_num=user_info['stuNo'], token=token) # 合并配置文件的打卡信息 merge_post_json(campus_dict, campus_check_config['post_json']) # 校内打卡 campus_check_dict = campus_check_in(user['phone'], token, campus_dict, i['id']) check_dict_list.append(campus_check_dict) log.info("-" * 40) return check_dict_list
def healthy2_check_in(token, custom_id, post_dict): """ 第二类健康打卡 :param token: 用户令牌 :param custom_id: 健康打卡id :param post_dict: 健康打卡数据 :return: """ check_json = { "userId": post_dict["userId"], "name": post_dict["name"], "stuNo": post_dict["stuNo"], "whereabouts": post_dict["whereabouts"], "familyWhereabouts": "", "beenToWuhan": post_dict["beenToWuhan"], "contactWithPatients": post_dict["contactWithPatients"], "symptom": post_dict["symptom"], "fever": post_dict["fever"], "cough": post_dict["cough"], "soreThroat": post_dict["soreThroat"], "debilitation": post_dict["debilitation"], "diarrhea": post_dict["diarrhea"], "cold": post_dict["cold"], "staySchool": post_dict["staySchool"], "contacts": post_dict["contacts"], "emergencyPhone": post_dict["emergencyPhone"], "address": post_dict["address"], "familyForAddress": "", "collegeId": post_dict["collegeId"], "majorId": post_dict["majorId"], "classId": post_dict["classId"], "classDescribe": post_dict["classDescribe"], "temperature": post_dict["temperature"], "confirmed": post_dict["confirmed"], "isolated": post_dict["isolated"], "passingWuhan": post_dict["passingWuhan"], "passingHubei": post_dict["passingHubei"], "patientSide": post_dict["patientSide"], "patientContact": post_dict["patientContact"], "mentalHealth": post_dict["mentalHealth"], "wayToSchool": post_dict["wayToSchool"], "backToSchool": post_dict["backToSchool"], "haveBroadband": post_dict["haveBroadband"], "emergencyContactName": post_dict["emergencyContactName"], "helpInfo": "", "passingCity": "", "longitude": post_dict["longitude"], "latitude": post_dict["latitude"], "token": token, } headers = { "referer": f"https://reportedh5.17wanxiao.com/nCovReport/index.html?token={token}&customerId={custom_id}", "content-type": "application/x-www-form-urlencoded;charset=UTF-8", } try: res = requests.post( "https://reportedh5.17wanxiao.com/api/reported/receive", headers=headers, data=check_json, ).json() if res["code"] == 0: log.info(res) return dict( status=1, res=res, post_dict={ 'name': post_dict["name"], "updatainfo_detail": post_dict, 'checkbox': [{ 'description': key, 'value': value } for key, value in check_json.items()] }, check_json=check_json, type="healthy2", ) else: log.warning(res) return dict( status=1, res=res, post_dict={ 'name': post_dict["name"], "updatainfo_detail": post_dict, 'checkbox': [{ 'description': key, 'value': value } for key, value in check_json.items()] }, check_json=check_json, type="healthy2", ) except: errmsg = f"```打卡请求出错```" log.warning("打卡请求出错,网络不稳定") return dict(status=0, errmsg=errmsg)
def healthy1_check_in(token, phone, post_dict): """ 第一类健康打卡 :param phone: 手机号 :param token: 用户令牌 :param post_dict: 打卡数据 :return: """ check_json = { "businessType": "epmpics", "method": "submitUpInfo", "jsonData": { "deptStr": post_dict["deptStr"], "areaStr": post_dict["areaStr"], "reportdate": round(time.time() * 1000), "customerid": post_dict["customerid"], "deptid": post_dict['deptStr']['deptid'] if post_dict['deptStr'] else None, "source": "app", "templateid": post_dict["templateid"], "stuNo": post_dict["stuNo"], "username": post_dict["username"], "phonenum": phone, "userid": post_dict["userid"], "updatainfo": post_dict["updatainfo"], "gpsType": 1, "ver": post_dict["ver"], "token": token, }, } for _ in range(3): try: res = requests.post( "https://reportedh5.17wanxiao.com/sass/api/epmpics", json=check_json).json() if res['code'] == '10000': log.info(res) return { "status": 1, "res": res, "post_dict": post_dict, "check_json": check_json, "type": "healthy1", } elif res['data'] == "areaStr can not be null": log.warning( '当前用户无法获取第一类健康打卡地址信息,请前往配置 user.json 文件,one_check 下的 areaStr 设置地址信息' ) elif "频繁" in res['data']: log.info(res) return { "status": 1, "res": res, "post_dict": post_dict, "check_json": check_json, "type": "healthy1", } else: log.warning(res) return { "status": 0, "errmsg": f"{post_dict['username']}: {res}" } except: errmsg = f"```打卡请求出错```" log.warning("健康打卡请求出错") return {"status": 0, "errmsg": errmsg} return {"status": 0, "errmsg": "健康打卡请求出错"}