Beispiel #1
0
    def login(self):
        """携带各个加密参数登录"""
        form_data = {
            'appId': app_id,
            'loginName': self.login_name,
            'loginPwd': self.login_pwd,
            'geetest_challenge': self.challenge,
            'geetest_validate': self.validate,
            'geetest_seccode': self.sec_code,
            'deviceId': self.device_id,
            'deviceIp': self.device_ip,
            'deviceType': device_type,
            'jtSafeKey': self.jt_safe_key,
            'token': self.token,
            'fcmmRedirectFlag': redirect_flag,
            'signtype': sign_type
        }

        resp = fetch(self.session,
                     url=acc_login_url,
                     method='post',
                     headers=common_login_headers,
                     data=form_data)
        if resp is None:
            self.res = Resp.TIMEOUT
            return False
        res = resp.json()
        if res['returnCode'] != '0':
            if res['returnCode'] == 'BIZ_ERROR_018' and '账户名或密码错误' in res[
                    'returnMsg']:
                self.res = Resp.WRONG_NAME_OR_PWD
            if res['returnCode'] == 'COMMON_ERROR_022':
                self.res = Resp.ILLEGAL_ERR
            return False

        result_token = resp.json()['data']['resultToken']
        form_data = {
            'appId': app_id,
            'assert': '',
            'assertSign': '',
            'des3Assert': '',
            'des3AssertSign': '',
            'resultToken': result_token,
            'ptag': ''
        }

        resp = fetch(self.session,
                     url=login_success_handler_url,
                     method='post',
                     headers=common_login_headers,
                     data=form_data)
        return resp is not None
Beispiel #2
0
    def get_slide_images(self):
        """获取验证码图片的地址"""
        params = {
            'is_next': 'true',
            'type': 'slide3',
            'gt': self.gt,
            'challenge': self.challenge,
            'lang': 'zh-cn',
            'https': 'true',
            'protocol': 'https://',
            'offline': 'false',
            'product': 'popup',
            'api_server': 'captcha-api.pingan.com',
            'width': '100%',
            'callback': 'geetest_' + now_str()
        }
        resp = fetch(self.session,
                     url=get_php_url,
                     headers=common_login_headers,
                     params=params)
        if resp is None:
            self.res = Resp.TIMEOUT
            return False
        res = json.loads(re.search(r'\((.*?)\)', resp.text, re.S).group(1))

        # 获得滑动验证码图片的URL(带缺口+不带缺口)
        self.bg_url = prefix_url + res['data']['bg']
        self.full_bg_url = prefix_url + res['data']['fullbg']

        # 更新gt/challenge
        self.gt = res['data']['gt']
        self.challenge = res['data']['challenge']
        return True
Beispiel #3
0
 def ajax_php(self, step=1, params=None):
     """
     step=1:发送请求,校验参数w
     step=2:滑动滑块
     """
     if step == 1:
         params = {
             'gt': self.gt,
             'challenge': self.challenge,
             'lang': 'zh-cn',
             'w': get_full_page_w2(self.gt, self.challenge, self.s) + '1',
             'callback': 'geetest_' + now_str()
         }
     resp = fetch(self.session,
                  url=ajax_php_url,
                  headers=common_login_headers,
                  params=params)
     if resp is None:
         self.res = Resp.TIMEOUT
         return False
     if step != 1:
         res = json.loads(re.search(r'\((.*?)\)', resp.text, re.S).group(1))
         if res['data']['result'] != 'success':
             self.res = Resp.SLIDE_ERR
             return False
         self.validate = res['data']['validate']
         self.sec_code = self.validate + '|jordan'
     return True
Beispiel #4
0
def get_token(session, phone, device_id, device_ip):
    """获取token参数"""
    form_data = {
        'appId': app_id,
        'deviceType': device_type,
        'loginName': str(phone),
        'loginType': login_type,
        'deviceId': device_id,
        'deviceIp': device_ip
    }
    resp = fetch(session=session, url=token_url, method='post', data=form_data)
    return '' if resp is None else resp.json()['data']['token']
Beispiel #5
0
 def set_gt_challenge(self) -> bool:
     """发送网络请求,拿到gt和challenge"""
     params = dict(t=now_str())
     resp = fetch(self.session,
                  url=gt_register_url,
                  headers=common_login_headers,
                  params=params)
     if resp is None:
         self.res = Resp.TIMEOUT
         return False
     res = resp.json()
     self.gt, self.challenge = res['gt'], res['challenge']
     return True
Beispiel #6
0
    def get_track(self):
        """获取滑动轨迹"""
        resp1 = fetch(self.session,
                      url=self.bg_url,
                      headers=common_login_headers)
        resp2 = fetch(self.session,
                      url=self.full_bg_url,
                      headers=common_login_headers)
        if not (resp1 and resp2):
            self.res = Resp.TIMEOUT
            return False
        img1 = Image.open(BytesIO(resp1.content))
        img2 = Image.open(BytesIO(resp2.content))

        # 计算偏移量
        self.offset = calculate_offset(img1, img2)

        # 根据偏移量获取轨迹
        self.track = get_track(self.offset)
        if self.track is None:
            self.res = Resp.TRACK_ERR
        return self.track is not None
Beispiel #7
0
 def get_php(self):
     """注册参数s:s经过多层加密拼接成w"""
     params = {
         'gt': self.gt,
         'challenge': self.challenge,
         'lang': 'zh-cn',
         'w': get_full_page_w1(self.gt, self.challenge, self.s),
         'callback': 'geetest_' + now_str()
     }
     resp = fetch(self.session,
                  url=get_php_url,
                  headers=common_login_headers,
                  params=params)
     if resp is None:
         self.res = Resp.TIMEOUT
     return resp is not None
Beispiel #8
0
def get_captcha_image(session, image_url) -> Image:
    """获取验证码图片Image对象"""
    resp = fetch(session, url=image_url, headers=common_login_headers)
    return None if resp is None else Image.open(BytesIO(resp.content))