コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
0
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)
コード例 #4
0
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)
コード例 #5
0
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)
コード例 #6
0
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)
コード例 #7
0
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)
コード例 #8
0
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)
コード例 #9
0
def crawl_account(request):
    args = request.POST
    account_type = args["account_type"]
    username = args["username"]

    ssdb_conn = get_ssdb_conn()
    status = ssdb_conn.get(username + ACCOUNT_CRAWLING_STATUS_SSDB_SUFFIX +
                           account_type)
    if status not in CHECK_STATUS_LIST:
        ret_data = {}
        add_ajax_ok_json(ret_data)
        return JsonResponse(ret_data)

    if "communications" == account_type:
        return _handle_communications_crawling(args)
    elif account_type in ["housefund", "shebao"]:
        return _handle_5xian1jin_crawling(args, account_type)
    elif "xuexin" == account_type:
        return _handle_xuexin_crawling(args)
    elif "bank" == account_type:
        return _handle_bank_crawling(args)
    elif "emailbill" == account_type:
        return _handle_emailbill_crawling(args)
    elif "zhengxin" == account_type:
        password = request.session['zhengxin_password']
        return _handle_zhengxin_crawling(args, password)
    elif account_type in ["jingdong", "alipay", "taobao", "yhd"]:
        return _handle_ecommerce_crawling(args)

    return HttpResponseBadRequest()
コード例 #10
0
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)
コード例 #11
0
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)
コード例 #12
0
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)
コード例 #13
0
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)
コード例 #14
0
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)
コード例 #15
0
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)
コード例 #16
0
def get_captcha_body(request):
    captcha_body = _get_captcha_body(request)
    ret_data = {}
    ret_data['img_src'] = bytes.decode(b64encode(captcha_body))
    add_ajax_ok_json(ret_data)

    return JsonResponse(ret_data)
コード例 #17
0
def _get_zhengxin_crawling_status(args):
    """
    征信数据爬虫状态
    """
    username = args["username"]
    account_type = args["account_type"]

    data = {}
    add_ajax_ok_json(data)

    ssbd_connect = get_ssdb_conn()

    # 需要识别图片验证码
    uid = ssbd_connect.get(username + ACCOUNT_CRAWLING_NEED_IMG_SSDB_SUFFIX +
                           account_type)
    if uid is not None:
        save_img_file_from_ssdb(uid)
        data["crawling_status"] = "img_captcha"
        data["username"] = username
        data["img_uid"] = uid
        data["img_src"] = static("/".join((CAPTCHA_DIR, uid)))
        return JsonResponse(data)

    # 返回爬取状态
    data.update(
        get_crawling_data(ssbd_connect, username, account_type, username))
    return JsonResponse(data)
コード例 #18
0
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)
コード例 #19
0
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)
コード例 #20
0
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)
コード例 #21
0
def fill_in_username(request):
    """
    找回密码第一步:填写账户名
    :param request:
    :return:
    """
    ret_data = {}
    ret_k = None
    try:
        args = request.POST
        session = request.session
        username = args["username"].strip()
        auth_code = args.get("captcha_code", "")
        cookies = session.get("req_cookie")
        other_name = session.get("request_data", {}).get("other_name")
        other_value = session.get("request_data", {}).get("other_value")
        uuid = session.get("request_data", {}).get("uuid")
        post_url = "{host}/findPwd/doIndex.action?&uuid={uuid}&sourceId={sourceId}&" \
                   "authCode={authCode}&username={username}&eid={eid}&fp={fp}&" \
                   "{o_name}={o_value}".format(host=host, uuid=uuid, sourceId=sourceId,
                                               authCode=auth_code, username=username, eid=eid,
                                               fp=fp, o_name=other_name, o_value=other_value)
        ret_json = http_get(post_url, headers=HEADERS, cookies=cookies, verify=False).json()
        result_code = ret_json.get("resultCode")
        if result_code == "ok":
            msg = "第一步成功"
            ret_k = ret_json.get("k")
        elif result_code == "authCodeFailure":
            msg = "验证码错误"
        elif result_code == "none":
            msg = "您输入的账户名不存在,请核对后重新输入"
        elif result_code == "usernameFailure":
            msg = "请输入用户名"
        else:
            msg = "网络连接超时,请重新修改登录密码"

        if ret_k:
            try:
                url = "https://safe.jd.com/findPwd/findPwd.action?k={ret_k}".format(ret_k=ret_k)
                page = http_get(url, headers=HEADERS, verify=False, timeout=timeout).text
                element = html.fromstring(page)
                nickname = element.xpath('//div[@id="mobileDiv"]/div[1]/div[1]/strong/text()')[0]
            except Exception:
                msg = "您的账户信息异常,暂时限制找回密码!"
                add_ajax_error_json(ret_data, msg)
            else:
                ret_data["ret_k"] = ret_k
                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)
コード例 #22
0
def upload_captcha(request):
    args = request.POST
    file_type = args.get("file_type", ".jpg")
    website = args.get("website", "")
    # username = args.get("username", "")

    file = request.FILES['file']
    data = {"uid": save_captcha(file, file_type, website)}

    add_ajax_ok_json(data)
    return JsonResponse(data)
コード例 #23
0
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)
コード例 #24
0
def _get_ecommerce_crawling_status(args):
    """
    电子商务数据爬虫状态
    """
    username = args["username"]
    account_type = args["account_type"]

    data = {}
    add_ajax_ok_json(data)

    ssbd_connect = get_ssdb_conn()

    # 需要识别图片验证码
    uid = ssbd_connect.get(username + ACCOUNT_CRAWLING_NEED_IMG_SSDB_SUFFIX +
                           account_type)
    if uid is not None:
        save_img_file_from_ssdb(uid)
        data["crawling_status"] = "img_captcha"
        data["username"] = username
        data["img_uid"] = uid
        data["img_src"] = static("/".join((CAPTCHA_DIR, uid)))
        return JsonResponse(data)

    # 需要短信验证码
    uid = ssbd_connect.get(username + ACCOUNT_CRAWLING_NEED_SMS_SSDB_SUFFIX +
                           account_type)
    if uid is not None:
        data["crawling_status"] = "sms_captcha"
        data["username"] = username
        data["sms_uid"] = uid
        return JsonResponse(data)

    # 需要扫描二维码
    uid = ssbd_connect.get(username +
                           ACCOUNT_CRAWLING_NEED_QRCODE_SSDB_SUFFIX +
                           account_type)
    if uid is not None:
        data["crawling_status"] = "scan_qrcode"
        data["username"] = username
        data["qrcode_uid"] = uid
        data["qrcode_pic"] = ssbd_connect.get(
            uid + ACCOUNT_CRAWLING_IMG_DATA_SSDB_SUFFIX)
        return JsonResponse(data)

    # 返回爬取状态
    data.update(
        get_crawling_data(ssbd_connect, username, account_type, username))
    return JsonResponse(data)
コード例 #25
0
def xuexin_get_pic_vcode(request):
    """
    获取图片验证码
    :param request:
    :return:
    """
    url = "https://account.chsi.com.cn/account/captchimagecreateaction.action?time=" \
          + str(int(time()))
    req_cookie = request.session.get("req_cookie")
    response = http_get(url, verify=False, cookies=req_cookie)
    pic_text = b64encode(response.content).decode("utf-8")

    result = dict()
    result["pic"] = pic_text
    add_ajax_ok_json(result)

    return JsonResponse(result)
コード例 #26
0
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)
コード例 #27
0
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)
コード例 #28
0
def send_sms_code(request):
    """
    登录发送短信验证码
    :param request:
    :return:
    """
    ret_data = {}
    try:
        args = request.POST
        session = request.session
        if args.get("is_first", False) == "true":
            username = args["username"].strip()
            account_type = args["account_type"]
            key = username + ACCOUNT_CRAWLING_SMS_HEADERS_SSDB_SUFFIX + account_type
            ssdb_conn = get_ssdb_conn()
            headers_data = ssdb_conn.get(key)
            if not headers_data:
                add_ajax_error_json(ret_data, "获取短信验证码失败")
                return JsonResponse(ret_data)

            headers_dict = json_loads(headers_data)
            send_url = headers_dict.get("url", "")
            session["send_url"] = send_url
            session["last_send_time"] = time()

            # 第一次会自动发送,默认为发送成功
            res_json = {"stat": "ok", "info": {"sent": True}}
        else:
            last_send_time = session.get("last_send_time", 0)
            need_sleep_time = max(last_send_time + SMS_SLEEP_TIME + 2 -
                                  time(), 0) if last_send_time else 0
            sleep(need_sleep_time)

            send_url = session.get("send_url")
            res_json = get_response_by_requests(
                send_url, headers=DEFAULT_HEADERS).json()
        if res_json.get("stat") == "ok" and res_json.get("info",
                                                         {}).get("sent"):
            add_ajax_ok_json(ret_data)
        else:
            error_msg = res_json.get("info", {}).get("errorMessage")
            add_ajax_error_json(ret_data, error_msg or "发送短信验证码失败")
    except Exception:
        add_ajax_error_json(ret_data, "发送短信验证码出错")

    return JsonResponse(ret_data)
コード例 #29
0
def zhengxin_reg2_request(request):
    """
       执行注册第二步
    """
    args = request.POST
    data = {"method": "saveUser",
            "userInfoVO.smsrcvtimeflag": "2",
            "userInfoVO.email": args["email"],
            "org.apache.struts.taglib.html.TOKEN": args["org.apache.struts.taglib.html.TOKEN"],
            "userInfoVO.loginName": args["loginName"],
            "userInfoVO.password": args["password"],
            "userInfoVO.confirmpassword": args["confirmpassword"],
            "userInfoVO.mobileTel": args["mobileTel"],
            "userInfoVO.verifyCode": args["verifyCode"],
            "tcId": args["tcId"],
            }
    params = urlencode(data, encoding="gb2312")

    headers = DEFAULT_REQUEST_HEADERS.copy()
    headers['User-Agent'] = USER_AGENT
    headers["Referer"] = "https://ipcrs.pbccrc.org.cn/userReg.do"
    kwargs = {"timeout": 6,
              "verify": False,
              "headers": headers,
              "cookies": request.session.get("req_cookie"),
              "params": params,
              }

    resp = http_post("https://ipcrs.pbccrc.org.cn/userReg.do", **kwargs)

    # TODO 容错
    ret_data = {}
    if resp.status_code == 200:
        text = resp.text
        error_msg = pattern_error_user.search(text)
        if error_msg:
            add_ajax_error_json(ret_data, error_msg.group(1))
        elif '注册成功' in text:
            add_ajax_ok_json(ret_data)
        else:
            add_ajax_error_json(ret_data, "注册失败")
    else:
        add_ajax_error_json(ret_data)

    return JsonResponse(ret_data)
コード例 #30
0
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)