def get_qrcode_info(request): """ 获取二维码相关信息 :param request: :return: """ ret_data = {} try: qrurl = "https://qrlogin.taobao.com/qrcodelogin/generateQRCode4Login.do" res = get_response_by_requests(qrurl, headers=DEFAULT_HEADERS).json() if res.get("success"): url = res.get("url", "") qrcode_url = "https:" + url if not url.startswith("http") else url qrcode_body = get_response_by_requests( qrcode_url, headers=DEFAULT_HEADERS).content qrcode_info = { "lgToken": res.get("lgToken", ""), "adToken": res.get("adToken", ""), "qrcode_url": qrcode_url, "qrcode_body": bytes.decode(b64encode(qrcode_body)) } ret_data["msg"] = "获取二维码相关信息成功" ret_data["data"] = qrcode_info else: add_ajax_error_json(ret_data, "获取二维码相关信息失败") except Exception: add_ajax_error_json(ret_data, "获取二维码相关信息出错") else: add_ajax_ok_json(ret_data) finally: return JsonResponse(ret_data)
def _handle_bank_crawling(args): """ 银行交易数据爬虫处理 """ username = args["username"].strip() ret_data = {} if not username: add_ajax_error_json(ret_data) return JsonResponse(ret_data) bank = args["bank"].strip() spider_name = BANK_DICT[bank] account_type = args["account_type"].strip() ssdb_data = _format_ssdb_data(args) ssdb_data.update({ "bank": bank, "id": args.get("id", "").strip(), }) push_data_2_ssbd(username, spider_name, account_type, ssdb_data) add_ajax_ok_json(ret_data) return JsonResponse(ret_data)
def _handle_5xian1jin_crawling(args, account_type): """ 五险一金爬虫处理 """ username = args["username"].strip() ret_data = {} if not username: add_ajax_error_json(ret_data) return JsonResponse(ret_data) city = args["city"].strip() try: if "housefund" == account_type: spider_name = HOUSEFUND_CITY_DICT[city] else: spider_name = SHEBAO_CITY_DICT[city] except KeyError: add_ajax_error_json(ret_data, "暂不支持该城市") return JsonResponse(ret_data) ssdb_data = _format_ssdb_data(args) ssdb_data["city"] = city push_data_2_ssbd(username, spider_name, account_type, ssdb_data) add_ajax_ok_json(ret_data) return JsonResponse(ret_data)
def get_zhengxin_AcvitaveCode(request): """ 获取短信验证码 """ phone_number = request.POST["number"] data = {"method": "getAcvitaveCode", "mobileTel": phone_number} headers = DEFAULT_REQUEST_HEADERS.copy() headers["Referer"] = "https://ipcrs.pbccrc.org.cn/userReg.do" kwargs = {"timeout": 6, "verify": False, "headers": headers, "cookies": request.session.get("req_cookie") } resp = http_post("https://ipcrs.pbccrc.org.cn/userReg.do", data, **kwargs) text = resp.text # TODO 容错 ret_data = {} if resp.status_code == 200 and text: add_ajax_ok_json(ret_data) ret_data["tcId"] = text else: add_ajax_error_json(ret_data) return JsonResponse(ret_data)
def get_img_captcha_find_password(request): """ 获取找回密码图片验证码 :param request: :return: """ ret_data = {} try: uuid = request.session.get("request_data", {}).get("uuid") code_url = "https://authcode.jd.com/verify/image?acid=%s&srcid=%s&_t=%s" \ % (uuid, sourceId, get_js_time()) captcha_headers = HEADERS.copy() captcha_headers.update({ "Host": "authcode.jd.com", "Referer": "https://safe.jd.com/findPwd/index.action", "Accept": "image/webp,image/*,*/*;q=0.8" }) code_content = http_get(code_url, headers=captcha_headers, verify=False).content ret_data["img_data"] = bytes.decode(b64encode(code_content)) except Exception: add_ajax_error_json(ret_data, "无法获取验证码") else: add_ajax_ok_json(ret_data) return JsonResponse(ret_data)
def back_submit_passwd_question(request): args = request.POST session = request.session # awsers = args.get('dict') datas = session.get('submit_passwd_quest_data') passwd_cookies = session.get('passwd_cookies') for x in range(5): i = str(x) datas['kbaList[' + i + '].answerresult'] = args.get("dict[key[" + i + "].options]") datas['kbaList[' + i + '].options'] = args.get("dict[key[" + i + "].options]") url = 'https://ipcrs.pbccrc.org.cn/resetPassword.do' headers = HEADERS.copy() headers['Referer'] = url response = http_post(url=url, data=datas, headers=headers, cookies=passwd_cookies, verify=False) test = '' try: test = etree.HTML(response.text).xpath('//font[@class="span-14 padding_left_130"]/text()')[0] except Exception: pass result = {} if '您的重置密码申请已提交' in test: result['msg'] = test add_ajax_ok_json(result) else: add_ajax_error_json(result, "重置密码失败") return JsonResponse(result)
def submit_question(request): """ 用户提交答案: :param request: :return: """ args = request.POST session = request.session # awsers = args.get('st') datas = session.get('quest_data') cookies = session.get('question_cookies') for x in range(5): i = str(x) datas['kbaList[' + i + '].answerresult'] = args.get("st[key[" + i + "].options]") datas['kbaList[' + i + '].options'] = args.get("st[key[" + i + "].options]") url = 'https://ipcrs.pbccrc.org.cn/reportAction.do?method=submitKBA' headers = HEADERS.copy() headers['Referer'] = 'https://ipcrs.pbccrc.org.cn/reportAction.do?method=checkishasreport' response = http_post(url=url, data=datas, headers=headers, cookies=cookies, verify=False) result = dict() try: msg = etree.HTML(response.text).xpath('//div[@class="span-grey2 span-14 p1 margin_top_80"]')[0] if '您的查询申请已提交' in msg.xpath('string(.)'): result['msg'] = msg.xpath('string(.)') add_ajax_ok_json(result) else: add_ajax_error_json(result) except Exception: add_ajax_error_json(result) result['msg'] = "用户提交异常,请<a href='/account_spider/zhengxin/'>返回</a>重新提交;" return JsonResponse(result)
def send_sms_code_find_password(request): """ 找回密码发送短信验证码 :param request: :return: """ ret_data = {} succ = False try: ret_k = request.POST.get("ret_k", "") post_url = "{host}/findPwd/getCode.action?k={ret_k}".format(host=host, ret_k=ret_k) ret_page = http_get(post_url, headers=HEADERS).json() if ret_page == 0: msg = "短信发送成功" succ = True elif ret_page == "kError": msg = "参数错误" elif ret_page == 503: msg = "120秒内仅能获取一次验证码,请稍后重试" elif ret_page == 504: msg = "您申请获取短信验证码的次数过多,请于24小时后重试" elif ret_page == "lock": msg = "您的账户信息异常,暂时限制找回密码" elif isinstance(ret_page, dict) and ret_page.get("resultMessage"): msg = ret_page["resultMessage"] else: msg = "发送短信验证码失败,未知错误" if succ: add_ajax_ok_json(ret_data) else: add_ajax_error_json(ret_data, msg) except Exception: add_ajax_error_json(ret_data, "找回密码发送短信验证码失败") return JsonResponse(ret_data)
def _get_unicom_bills_sms_captcha(args): """联通发送一般短信验证码""" ret_data = {} username = args["username"].strip() the_time = get_js_time() form_data = {'mobile': username, 'req_time': the_time, '_': int(the_time) + 1, 'callback': "jQuery1720" + str(randint(1E16, 1E17 - 1)) + "_" + the_time } # url = "https://uac.10010.com/portal/Service/SendMSG?" + urlencode(form_data) url = "https://uac.10010.com/portal/Service/SendMSG" key = username + ACCOUNT_CRAWLING_SMS_HEADERS_SSDB_SUFFIX + args["account_type"] try: ssdb_conn = get_ssdb_conn() headers = ssdb_conn.get(key) if headers is not None: sms_content = http_get(url, headers=eval(headers), params=form_data, verify=False).text if 'resultCode:"0000"' in sms_content: add_ajax_ok_json(ret_data) elif 'resultCode:"7096"' in sms_content: # 验证码请求过快 add_ajax_error_json(ret_data, "验证码请求过快,请稍后再试。") elif 'resultCode:"7098"' in sms_content: # 7098谁请求达到上限 add_ajax_error_json(ret_data, "请求短信验证码达到上限,请明天再试!") else: add_ajax_error_json(ret_data, "发送失败:" + sms_content) else: add_ajax_error_json(ret_data, "无法获取短信验证码,请刷新页面重试!") except Exception: add_ajax_error_json(ret_data, "无法获取短信验证码,请重试。") return JsonResponse(ret_data)
def update_password(request): """ 找回密码第三步:更新密码 :param request: :return: """ ret_data = {} succ = False try: args = request.POST new_password = args.get("new_password") key = args.get("ret_key") mobile = args.get("mobile") need_history_name = args.get("history_name", "") # rsa_tool = RsaUtil(key_is_hex=True) # en_pwd = rsa_tool.encrypt(new_password, pubkey=rsa_pubkey, get_hex=True) rsa_tool = RsaNoPadding(pubkey=rsa_pubkey) en_pwd = rsa_tool.encrypt(new_password) params = { "host": host, "key": key, "en_newpwd": quote(en_pwd), "mobile": mobile, "name": quote(need_history_name), "eid": eid, "fp": fp, } my_headers = HEADERS.copy() referer = "https://safe.jd.com/findPwd/resetPassword.action?key={key}".format(key=key) my_headers["Referer"] = referer post_url = "{host}/findPwd/doResetPwd.action?key={key}&password={en_newpwd}&" \ "mobile={mobile}&historyName={name}&eid={eid}&fp={fp}".format(**params) ret_json = http_post(post_url, headers=my_headers, verify=False).json() result_code = ret_json.get("resultCode") if result_code == "0": msg = "重置密码成功" succ = True elif result_code in ["101", "102", "112", "116", "606", "801", "802", "803", "804"]: msg = ret_json.get("resultMessage", "") elif result_code == "passwordError": msg = "密码设置级别太低" elif result_code in ("timeOut", "202"): msg = "操作超时" elif result_code == "mobileNameError": msg = "历史收货人姓名不能为手机号" else: msg = ret_json.get("resultMessage", "找回密码失败,未知错误") if succ: add_ajax_ok_json(ret_data) else: add_ajax_error_json(ret_data, msg) except Exception: add_ajax_error_json(ret_data, "找回密码第三步:更新密码失败") return JsonResponse(ret_data)
def ask_qrcode_status(request): """ 获取扫描二维码状态 :param request: :return: """ ret_data = {} succ = False need_refresh = False try: args = request.POST username = args["username"] account_type = args["account_type"] lg_token = args.get("lg_token", "") check_url_base = "https://qrlogin.taobao.com/qrcodelogin/qrcodeLoginCheck.do?" \ "lgToken={lgToken}&defaulturl=https%3A%2F%2Fwww.taobao.com%2F" check_url = check_url_base.format(lgToken=lg_token) res_json = get_response_by_requests(check_url, headers=DEFAULT_HEADERS).json() session = req_session() msg = "通过扫描二维码登录失败" code = res_json.get("code") if code == "10000": msg = "请先扫描二维码" elif code == "10001": msg = "扫描成功后,请确认登录" succ = True elif code == "10004": msg = "二维码已失效,请重试" need_refresh = True elif code == "10006": redirect_url = res_json.get("url") resp = session.get(redirect_url, headers=DEFAULT_HEADERS, verify=False) if resp.status_code == 200: msg = "登录成功" cookies = session.cookies.get_dict(domain='.taobao.com') cookies_str = json_dumps(cookies) # 将登录成功的cookies信息存入ssdb,供爬虫端使用 ssdb_connect = get_ssdb_conn() key = username + ACCOUNT_CRAWLING_QRCODE_COOKIES_SSDB_SUFFIX + account_type ssdb_connect.setx(key, cookies_str, DATA_EXPIRE_TIME) succ = True else: msg = res_json.get("msg", "通过扫描二维码登录失败") except Exception: msg = "获取扫描二维码状态出错" if succ: add_ajax_ok_json(ret_data) else: ret_data["need_refresh"] = need_refresh add_ajax_error_json(ret_data, msg) return JsonResponse(ret_data)
def xuexin_find_password_step2(request): """ 学信网找回密码第二步 https://account.chsi.com.cn/account/forgot/rtvbymphone.action post captch 88 mphone 15908143404 ctoken 9671bdc3552f4ebf96b21ef5fa9ffab0 xm 胡明星1 sfzh 510722198609271058 重置密码短信已发送至15908143404,登录用户名15908143404 :param request: :return: """ args = request.POST captch = args.get("captch", "") mphone = args.get("mphone", "") xm = args.get("xm", "") sfzh = args.get("sfzh", "") ctoken = args.get("ctoken", "") req_cookie = request.session.get("req_cookie") url = "https://account.chsi.com.cn/account/forgot/rtvbymphone.action" data = { "captch": captch, "mphone": mphone, "ctoken": ctoken, "xm": xm, "sfzh": sfzh } response = http_post(url, data=data, headers=HEADERS, verify=False, cookies=req_cookie) text = response.text result = dict() if "重置密码短信已发送至" in text: result["msg"] = "成功" add_ajax_ok_json(result) key = key_pattern.search(text) if key: key = key.group(1) result["key"] = key clst = clst_pattern.search(text) if clst: clst = clst.group(1) result["clst"] = clst else: err_msg = error_info_pattern.search(text) add_ajax_error_json(result, err_msg.group(1) if err_msg else "未知错误") return JsonResponse(result)
def _get_mobile_bills_sms_captcha(args): """移动发送账单短信验证码""" ret_data = {} username = args["username"].strip() form_data = {"callback": "jQuery1830" + str(randint(1E16, 1E17 - 1)) + "_" + get_js_time(), "_": get_js_time(), } url = "https://shop.10086.cn/i/v1/fee/detbillrandomcodejsonp/" + username + "?" + urlencode(form_data) key = username + ACCOUNT_CRAWLING_SMS_HEADERS_SSDB_SUFFIX + args["account_type"] try: ssdb_conn = get_ssdb_conn() headers = ssdb_conn.get(key) if headers is not None: sms_content = http_get(url, headers=eval(headers), verify=False).content.decode() if '"retCode":"000000"' in sms_content: # 成功 add_ajax_ok_json(ret_data) elif '"retCode":"570007"' in sms_content: # 系统繁忙! add_ajax_error_json(ret_data, "系统繁忙,请重试。") else: add_ajax_error_json(ret_data, sms_content) else: add_ajax_error_json(ret_data, "无法获取短信验证码,请刷新页面重试!") except Exception: add_ajax_error_json(ret_data, "获取短信验证码失败,请重试。") return JsonResponse(ret_data)
def _get_mobile_login_sms_captcha(args): """移动发送登录短信验证码""" ret_data = {} username = args["username"].strip() url = "https://login.10086.cn/sendRandomCodeAction.action" form_data = { "userName": username, "type": "01", "channelID": "12003" } key = username + ACCOUNT_CRAWLING_SMS_HEADERS_SSDB_SUFFIX + args["account_type"] try: ssdb_conn = get_ssdb_conn() headers = ssdb_conn.get(key) if headers is not None: sms_content = http_post(url, headers=eval(headers), data=form_data, verify=False).text if sms_content == '0': add_ajax_ok_json(ret_data) elif sms_content == '2': add_ajax_error_json(ret_data, "当日短信验证码已达上限,请明天再试!") else: add_ajax_error_json(ret_data, "短信验证码发送失败,请重试!") else: add_ajax_error_json(ret_data, "无法获取短信验证码,请刷新页面重试!") except Exception: add_ajax_error_json(ret_data, "无法获取短信验证码,请重试。") return JsonResponse(ret_data)
def xuexin_find_username(request): """ 学信网找回用户名 https://account.chsi.com.cn/account/password!rtvlgname.action post captch 88 xm 胡明星1 sfzh 510722198609271058 :param request: :return: """ args = request.POST captch = args.get("captch", "") xm = args.get("xm", "") sfzh = args.get("sfzh", "") req_cookie = request.session.get("req_cookie") url = "https://account.chsi.com.cn/account/password!rtvlgname.action" data = {"captch": captch, "xm": xm, "sfzh": sfzh} response = http_post(url, data=data, headers=HEADERS, verify=False, cookies=req_cookie) text = response.text result = dict() if "找回用户名操作完成" in text: add_ajax_ok_json(result) tree = etree.HTML(text) key = tree.xpath('//td') if key: msg = '恭喜你,找回用户名成功!您的用户名是: ' + key[0].text else: msg = '' result["msg"] = msg else: tree = etree.HTML(text) error_list = tree.xpath( '//ul[@id="user_retrivelgname_fm_error_info"]/li/span') add_ajax_error_json(result, error_list[0].text if error_list else "未知错误") return JsonResponse(result)
def _ask_send_ecommerce_sms_captcha(args): """告诉爬虫端 需要电商发送短信验证码""" username = args['username'].strip() account_type = args['account_type'].strip() ret_data = {} if not username: add_ajax_error_json(ret_data, "用户名为空") return JsonResponse(ret_data) ssbd_connect = get_ssdb_conn() ssbd_connect.setx( username + ACCOUNT_CRAWLING_ASK_SEND_SMS_SSDB_SUFFIX + account_type, True, DATA_EXPIRE_TIME) add_ajax_ok_json(ret_data) return JsonResponse(ret_data)
def recognize_captcha(request): args = request.POST file_type = args.get("file_type", ".jpg") website = args.get("website", "") # username = args.get("username", "") file = request.FILES['file'] uid = save_captcha(file, file_type, website) captcha = _get_captcha_result(uid) data = {"captcha": captcha} if captcha: add_ajax_ok_json(data) else: add_ajax_error_json(data) return JsonResponse(data)
def qq_get_qrcode_status(request): """ 检查qq登录二维码图片有效性 :param request: :return: """ ret_data = {} try: args = request.POST cookies = json_loads(args.get('cookies', {})) appid = args.get('appid', '522005705') daid = args.get('daid', '4') ptqrtoken = __hash_33(cookies.get('qrsig')) scan_url = "https://ssl.ptlogin2.qq.com/ptqrlogin?u1=https%3A%2F%2Fmail.qq.com%2Fcgi-bin%2Freadtemplate%3" \ "Fcheck%3Dfalse%26t%3Dloginpage_new_jump%26vt%3Dpassport%26vm%3Dwpt%26ft%3Dlogi" \ "npage%26target%3D&ptqrtoken={0}&ptredirect=0&h=1&t=1&g=1&from_ui=1&pt" \ "lang=2052&action=1-1-1513651703600&js_ver=10232&js_type=1&login_s" \ "ig=&pt_uistyle=25&aid={1}&daid={2}&".format(ptqrtoken, appid, daid) headers = QQ_GET_QRCODE_STATUS_HEADERS.copy() headers['Cookie'] = "qrsig=" + cookies.get('qrsig') scan_text = http_get(scan_url, headers=headers, cookies=cookies).text qr_result_list = qq_qr_result_list_pattern.search(scan_text).group( 1).split(',') qr_result_code = qq_qr_result_info_pattern.search( qr_result_list[0]).group(1) qr_result_url = qq_qr_result_info_pattern.search( qr_result_list[2]).group(1) qr_result_status = qq_qr_result_info_pattern.search( qr_result_list[4]).group(1) qr_result_nick_name = qq_qr_result_info_pattern.search( qr_result_list[5]).group(1) data = { 'qr_code': qr_result_code, 'qr_url': qr_result_url, 'qr_status': qr_result_status, 'qr_nick_name': qr_result_nick_name } ret_data["data"] = data add_ajax_ok_json(ret_data) except Exception: add_ajax_error_json(ret_data, "二维码失效") finally: return JsonResponse(ret_data)
def xuexin_update_password(request): """ 修改密码 https://account.chsi.com.cn/account/forgot/rstpwdbymphone.action post clst e64e5d78880648f79ca6d145b7653e79 password 489544240 key password1 489544240 vcode 111111 :param request: :return: """ args = request.POST password = args.get("password", "") password1 = args.get("password1", "") vcode = args.get("vcode", "") key = args.get("key", "") clst = args.get("clst", "") req_cookie = request.session.get("req_cookie") url = "https://account.chsi.com.cn/account/forgot/rstpwdbymphone.action" data = { "clst": clst, "password": password, "key": key, "password1": password1, "vcode": vcode } response = http_post(url, data=data, headers=HEADERS, verify=False, cookies=req_cookie) text = response.text result = dict() if "密码重置成功" in text: result["msg"] = "密码修改成功" add_ajax_ok_json(result) else: err_msg = error_info_pattern.search(text) add_ajax_error_json(result, err_msg.group(1) if err_msg else "未知错误") return JsonResponse(result)
def get_sms_captcha(request): """发送短信验证码""" args = request.POST username = args["username"].strip() if not username: ret_data = {} add_ajax_error_json(ret_data, "用户名为空") return JsonResponse(ret_data) phone_brand = check_phone_type(username) if "移动" == phone_brand: return _get_mobile_sms_captcha(args) elif "联通" == phone_brand: return _get_unicom_sms_captcha(args) elif "电信" == phone_brand: return _get_telecom_sms_captcha(args) return HttpResponseBadRequest()
def xuexin_find_password_step1(request): """ 学信网找回密码第一步 :param request: :return: """ args = request.POST captch = args.get("captch", "") mphone = args.get("mphone", "") url = "https://account.chsi.com.cn/account/password!retrive.action" data = {"loginName": mphone, "captch": captch} req_cookie = request.session.get("req_cookie") response = http_post(url, data=data, headers=HEADERS, verify=False, cookies=req_cookie) text = response.text error_msg = user_retrivePsd_error_pattern.search(text) result = {} if error_msg: add_ajax_error_json(result, error_msg.group(1)) else: result["msg"] = "成功" add_ajax_ok_json(result) # 进入找回密码的第二步 # 获取ctoken ctoken = ctoken_pattern.search(text) if ctoken: ctoken = ctoken.group(1) data = {"ctoken": ctoken} url = "https://account.chsi.com.cn/account/forgot/rtvbymphoneindex.action" response = http_post(url, data=data, headers=HEADERS, verify=False, cookies=req_cookie) result["ctoken"] = ctoken_pattern.search(response.text).group(1) return JsonResponse(result)
def check_communications(request): """检查号码所属运营商""" ret_data = {} username = request.POST["username"].strip() if not username: add_ajax_error_json(ret_data, "号码为空") return JsonResponse(ret_data) phone_brand = check_phone_type(username) if phone_brand: add_ajax_ok_json(ret_data) if phone_brand in ["移动", "联通", "电信"]: ret_data['brand'] = phone_brand else: ret_data['brand'] = "" else: add_ajax_error_json(ret_data, "无法获取号码信息") return JsonResponse(ret_data)
def _get_telecom_bills_sms_captcha(args): """电信发送一般短信验证码""" ret_data = {} username = args["username"].strip() dx_conver = DXConvertData() url = "http://cservice.client.189.cn:8004/map/clientXML?encrypted=true" key = username + ACCOUNT_CRAWLING_SMS_HEADERS_SSDB_SUFFIX + args["account_type"] try: ssdb_conn = get_ssdb_conn() headers = ssdb_conn.get(key) if headers is not None: token = json_loads(headers)["token"] form_data = { "Request": { "HeaderInfos": { "ClientType": "#6.2.1#channel8#Huawei DUK-AL20#", "Source": "110003", "SourcePassword": "******", "Token": token, "UserLoginName": username, "Code": "getRandomV2", "Timestamp": strftime("%Y%m%d%H%M%S"), }, "Content": { "Attach": "test", "FieldData": { "PhoneNbr": username, "SceneType": "7", "Imsi": {} } } } } form_str = dx_conver.convert_request_data(form_data) sms_text = http_post(url, headers=CSERVICE_HEADERS, data=form_str, verify=False).text sms_dict = dx_conver.convert_response_data(sms_text) sms_str = json_dumps(sms_dict, ensure_ascii=False) if '"ResultCode":{"value":"0000"}' in sms_str: add_ajax_ok_json(ret_data) elif "服务中断" in sms_text: add_ajax_error_json(ret_data, "电信服务中断,请稍后再试!") else: add_ajax_error_json(ret_data, "发送失败:" + sms_str) else: add_ajax_error_json(ret_data, "无法获取短信验证码,请刷新页面重试!") except Exception: add_ajax_error_json(ret_data, "无法获取短信验证码,请重试。") return JsonResponse(ret_data)
def back_chuck_username(request): """ 提交找回用户需要的信息 :param request: :return: """ args = request.POST user = args['name'] certNO = args['certNo'] certType = args['certType'] headers = HEADERS.copy() headers['Referer'] = 'https://ipcrs.pbccrc.org.cn/page/login/loginreg.jsp' url = "https://ipcrs.pbccrc.org.cn/findLoginName.do?method=init" req_ses = req_session() response = req_ses.get(url=url, headers=headers, verify=False) token = etree.HTML(response.text).xpath("//input[@name='org.apache.struts.taglib.html.TOKEN']/@value")[0] # 您无法使用该功能找回登录名,可能是因为您的安全等级为低、未注册或已销户,请重新注册 # 您的登录名已短信发送至平台预留的手机号码,请查收。 # 若您在5分钟内未收到短信或您的手机号码已修改,请使用“用户销户”功能先销户后再重新注册。 data = { 'org.apache.struts.taglib.html.TOKEN': token, 'method': 'findLoginName', 'name': user.encode('gb2312', 'replace'), 'certType': certType, 'certNo': certNO, '_@IMGRC@_': '', } error_msg1, error_msg2 = find_username(req_ses, data) result = {} while error_msg1: error_msg1, error_msg2 = find_username(req_ses, data) else: if error_msg2: add_ajax_error_json(result, error_msg2.group(1)) else: result['msg'] = '您的登录名已短信发送至平台预留的手机号码,请查收。' \ '<br/>若您在5分钟内未收到短信或您的手机号码已修改,' \ '请使用“用户销户”功能先销户后再重新注册。' add_ajax_ok_json(result) return JsonResponse(result)
def check_sms_timeout(request): """检测短信验证码是否超时""" ret_data = {} args = request.POST account_type = args["account_type"] username = args["username"].strip() if not username: add_ajax_error_json(ret_data, "用户名为空") return JsonResponse(ret_data) ssbd_connect = get_ssdb_conn() try: crawling_info = ssbd_connect.get(username + ACCOUNT_CRAWLING_INFO_SSDB_SUFFIX + account_type) ret_data.update(get_crawling_data(ssbd_connect, username, account_type, crawling_info)) except Exception: add_ajax_error_json(ret_data, "获取用户状态失败") else: add_ajax_ok_json(ret_data) return JsonResponse(ret_data)
def _handle_xuexin_crawling(args): """ 学信网爬虫处理 """ username = args["username"].strip() ret_data = {} if not username: add_ajax_error_json(ret_data) return JsonResponse(ret_data) spider_name = USERINFO_DICT['学信'] account_type = args["account_type"].strip() ssdb_data = _format_ssdb_data(args) push_data_2_ssbd(username, spider_name, account_type, ssdb_data) add_ajax_ok_json(ret_data) return JsonResponse(ret_data)
def get_img_captcha(request): """获取图片验证码""" ret_data = {} args = request.POST username = args["username"].strip() account_type = args["account_type"] url = "http://shop.10086.cn/i/authImg?t=" + str(rand_0_1()) if not username: add_ajax_error_json(ret_data, "用户名为空") return JsonResponse(ret_data) key = username + ACCOUNT_CRAWLING_IMG_HEADERS_SSDB_SUFFIX + account_type try: ssdb_conn = get_ssdb_conn() headers = ssdb_conn.get(key) if headers is not None: img_content = http_get(url, headers=eval(headers)).content ret_data["img_data"] = bytes.decode(b64encode(img_content)) else: add_ajax_error_json(ret_data, "无法获取图片验证码") except Exception: add_ajax_error_json(ret_data, "无法获取图片验证码") else: add_ajax_ok_json(ret_data) return JsonResponse(ret_data)
def get_sohu_img_captcha(request): """获取图片验证码""" ret_data = {} args = request.POST username = args["username"].strip() account_type = args["account_type"] if not username: add_ajax_error_json(ret_data, "用户名为空") return JsonResponse(ret_data) header_key = username + ACCOUNT_CRAWLING_IMG_HEADERS_SSDB_SUFFIX + account_type url_key = username + ACCOUNT_CRAWLING_IMG_URL_SSDB_SUFFIX + account_type try: ssdb_conn = get_ssdb_conn() cookies_dict = ssdb_conn.get(header_key) if cookies_dict: cookies_dict = eval(cookies_dict) captcha_url = ssdb_conn.get(url_key) img_content = http_get(captcha_url, cookies=cookies_dict).content ret_data["img_data"] = bytes.decode(b64encode(img_content)) else: add_ajax_error_json(ret_data, "无法获取图片验证码") except Exception: add_ajax_error_json(ret_data, "无法获取图片验证码") else: add_ajax_ok_json(ret_data) return JsonResponse(ret_data)
def get_img_captcha(request): """ 获取登录图片验证码 :param request: :return: """ ret_data = {} args = request.POST username = args["username"].strip() account_type = args["account_type"] if not username: add_ajax_error_json(ret_data, "用户名为空") return JsonResponse(ret_data) key = username + ACCOUNT_CRAWLING_IMG_HEADERS_SSDB_SUFFIX + account_type try: ssdb_conn = get_ssdb_conn() headers_data = ssdb_conn.get(key) if headers_data is not None: headers_data_dic = json_loads(headers_data) tmp_headers = headers_data_dic.get("headers") uuid = headers_data_dic.get("uuid") captcha_url = "https://authcode.jd.com/verify/image?a=1&acid={uuid}&" \ "yys={stime}".format(uuid=uuid, stime=get_js_time()) img_content = http_get(captcha_url, headers=tmp_headers, verify=False).content ret_data["img_data"] = bytes.decode(b64encode(img_content)) else: add_ajax_error_json(ret_data, "无法获取验证码") except Exception: add_ajax_error_json(ret_data, "无法获取验证码") else: add_ajax_ok_json(ret_data) return JsonResponse(ret_data)
def back_phone_vcode(req): """ 返回手机验证码 :param req: :return: """ passwd_cookies = req.session.get('passwd_cookies') headers = HEADERS.copy() headers['Referer'] = 'https://ipcrs.pbccrc.org.cn/resetPassword.do' url = 'https://ipcrs.pbccrc.org.cn/resetPassword.do?num=' + str(rand_0_1()) data = { 'method': 'getAcvitaveCode', 'counttime': '119', } response = http_post(url=url, data=data, headers=headers, cookies=passwd_cookies, verify=False) result = dict() if 'success' in response.text: add_ajax_ok_json(result) else: add_ajax_error_json(result) return JsonResponse(result)