Ejemplo n.º 1
0
    def _loginNormal(self, userName, userPwd, autoCheck=2):
        self._init()
        self._uamtk()
        if autoCheck == CAPTCHA_CHECK_METHOD_THREE:
            results, verify = Captcha().verifyCodeAuto()
        elif autoCheck == CAPTCHA_CHECK_METHOD_HAND:
            results, verify = Captcha().verifyCaptchaByHand()
        else:
            results, verify = Captcha().verifyCodeAutoByMyself()

        if not verify:
            return False, '验证码识别错误!'
        Log.v('验证码识别成功')
        payload = {
            'username': userName,
            'password': userPwd,
            'appid': 'otn',
            'answer': results
        }
        jsonRet = EasyHttp.send(self._urlInfo['login'], data=payload)

        def isLoginSuccess(responseJson):
            return 0 == responseJson['result_code'] if responseJson and 'result_code' in responseJson else False, \
                   responseJson[
                       'result_message'] if responseJson and 'result_message' in responseJson else '登录失败'

        result, msg = isLoginSuccess(jsonRet)
        if not result:
            return False, msg
        # self._userLogin()
        self._passportRedirect()
        result, msg, apptk = self._uamtk()
        if not Utils.check(result, msg):
            return False, 'uamtk failed'
        return self._uamauthclient(apptk)
Ejemplo n.º 2
0
    def _loginNormal(self, userName, userPwd, autoCheck=2):
        if autoCheck == CAPTCHA_CHECK_METHOD_THREE:
            results, verify = Captcha().verifyCodeAuto()
        elif autoCheck == CAPTCHA_CHECK_METHOD_HAND:
            results, verify = Captcha().verifyCaptchaByHand()
        else:
            results, verify = Captcha().verifyCodeAutoByMyself()

        if not verify:
            return False, '验证码识别错误!'
        Log.v('验证码识别成功')
        payload = OrderedDict()
        payload['username'] = userName
        payload['password'] = userPwd
        payload['appid'] = 'otn'
        payload['answer'] = results

        response = EasyHttp.post_custom(self._urlInfo['login'], data=payload)

        def isLoginSuccess(responseJson):
            return 0 == responseJson['result_code'] if responseJson and 'result_code' in responseJson else False, \
                   responseJson[
                       'result_message'] if responseJson and 'result_message' in responseJson else '登录失败'

        if response.status_code != requests.codes.ok:
            return False, "登录请求被强制重定向,准备重试..."
        result, msg = isLoginSuccess(response.json())
        if not result:
            return False, msg
        self._userLogin()
        self._passportRedirect()
        result, msg, apptk = self._uamtk()
        if not Utils.check(result, msg):
            return False, 'uamtk failed'
        return self._uamauthclient(apptk)
Ejemplo n.º 3
0
    def _loginAsyncSuggest(self, userName, userPwd, autoCheck=2):
        self._init()
        if autoCheck == CAPTCHA_CHECK_METHOD_THREE:
            results, verify = Captcha().verifyCodeAuto()
        elif autoCheck == CAPTCHA_CHECK_METHOD_HAND:
            results, verify = Captcha().verifyCaptchaByHand()
        else:
            results, verify = Captcha().verifyCodeAutoByMyself()
        if not verify:
            return False, '验证码识别错误!'
        Log.v('验证码识别成功')
        formData = {
            'loginUserDTO.user_name': userName,
            'userDTO.password': userPwd,
            'randCode': results,
        }
        jsonRet = EasyHttp.send(self._urlInfo['login'], data=formData)
        # print('loginAsyncSuggest: %s' % jsonRet)

        def isSuccess(response):
            return response['status'] and response['data'].get('loginCheck') == 'Y' if 'data' in response else False, \
                   response['data'].get('otherMsg') if 'data' in response else response['messages']

        loginSuccess, otherMsg = isSuccess(jsonRet)
        return loginSuccess, '%s:%s' % (userName, '登录成功' if loginSuccess else '登录失败')
Ejemplo n.º 4
0
    def _loginAsyncSuggest(self, userName, userPwd):
        captcha = Captcha(self.__session)
        results, verify = captcha.verifyCaptchaByHand(
            type=TYPE_LOGIN_OTHER_WAY)
        if not verify:
            return False, '验证码识别错误!'
        url = r'https://kyfw.12306.cn/otn/login/loginAysnSuggest'
        formData = {
            'loginUserDTO.user_name': userName,
            'userDTO.password': userPwd,
            'randCode': results,
        }
        headers = {
            'User-Agent': FIREFOX_USER_AGENT,
            'Referer': r'https://kyfw.12306.cn/otn/login/init',
            'Connection': 'keep-alive',
            'Content-Type':
            r'application/x-www-form-urlencoded; charset=UTF-8',
        }
        response = NetUtils.post(self.__session,
                                 url,
                                 data=formData,
                                 headers=headers)
        print('loginAsyncSuggest: %s' % response.text)
        response = response.json()

        def isSuccess(response):
            return response['status'] and response['data'][
                'loginCheck'] == 'Y', response['data']['otherMsg']

        loginSuccess, otherMsg = isSuccess(response)
        return loginSuccess, '%s:%s' % (userName, otherMsg or '登录成功!')
Ejemplo n.º 5
0
    def _loginNormal(self, userName, userPwd, autoCheck=True):
        self._init()
        self._uamtk()
        if autoCheck:
            if not Captcha().VerifyCodeAuto()[1]:
                return False, '验证码识别错误!'
        else:
            if not Captcha().verifyCaptchaByHand()[1]:
                return False, '验证码识别错误!'
        payload = {
            'username': userName,
            'password': userPwd,
            'appid': 'otn',
        }
        jsonRet = EasyHttp.send(self._urlInfo['login'], data=payload)

        def isLoginSuccess(responseJson):
            return 0 == responseJson['result_code'] if responseJson and 'result_code' in responseJson else False, \
                   responseJson[
                       'result_message'] if responseJson and 'result_message' in responseJson else 'login failed'

        result, msg = isLoginSuccess(jsonRet)
        if not result:
            return False, msg
        # self._userLogin()
        self._passportRedirect()
        result, msg, apptk = self._uamtk()
        if not Utils.check(result, msg):
            return False, 'uamtk failed'
        return self._uamauthclient(apptk)
Ejemplo n.º 6
0
    def _loginNormal(self, userName, userPwd):
        self._init()
        self._uamtk()
        if not Captcha().verifyCaptchaByHand()[1]:
            return False, "验证码识别错误!"
        payload = {"username": userName, "password": userPwd, "appid": "otn"}
        jsonRet = EasyHttp.send(self._urlInfo["login"], data=payload)

        def isLoginSuccess(responseJson):
            return (
                0 == responseJson["result_code"]
                if responseJson and "result_code" in responseJson else False,
                responseJson["result_message"] if responseJson
                and "result_message" in responseJson else "login failed",
            )

        result, msg = isLoginSuccess(jsonRet)
        if not result:
            return False, msg
        # self._userLogin()
        self._passportRedirect()
        result, msg, apptk = self._uamtk()
        if not Utils.check(result, msg):
            return False, "uamtk failed"
        return self._uamauthclient(apptk)
Ejemplo n.º 7
0
    def _loginNormal(self,
                     userName,
                     userPwd,
                     autoCheck=2,
                     type=TYPE_LOGIN_NORMAL_WAY):
        status, msg = self._login_init()
        if not status:
            return status, msg
        self._uamtk_static()
        if autoCheck == CAPTCHA_CHECK_METHOD_THREE:
            results, verify = Captcha().verifyCodeAuto()
        elif autoCheck == CAPTCHA_CHECK_METHOD_HAND:
            results, verify = Captcha().verifyCaptchaByHand(type=type)
        elif autoCheck == CAPTCHA_CHECK_METHOD_AUTO:
            results, verify = Captcha().verifyCaptchaByAuto(type=type)
        else:
            results, verify = Captcha().verifyCodeAutoByMyself(type=type)

        if not verify:
            return False, '验证码识别错误!'
        Log.v('验证码识别成功')
        payload = OrderedDict()
        payload['username'] = userName
        payload['password'] = userPwd
        payload['appid'] = 'otn'
        payload['answer'] = results

        response = EasyHttp.post_custom(self._urlInfo['login'], data=payload)

        def isLoginSuccess(responseJson):
            return 0 == responseJson['result_code'] if responseJson and 'result_code' in responseJson else False, \
                   responseJson[
                       'result_message'] if responseJson and 'result_message' in responseJson else '登录失败'

        result, msg = isLoginSuccess(response.json())
        if not result:
            return False, msg
        self._userLogin()
        self._passportRedirect()
        result, msg, apptk = self._uamtk()
        if not Utils.check(result, msg):
            return False, 'uamtk failed'
        return self._uamauthclient(apptk)
Ejemplo n.º 8
0
    def _loginAsyncSuggest(self, userName, userPwd, autoCheck=True):
        self._init()
        if autoCheck:
            results, verify = Captcha().VerifyCodeAuto(type=TYPE_LOGIN_OTHER_WAY)
        else:
            results, verify = Captcha().verifyCaptchaByHand(type=TYPE_LOGIN_OTHER_WAY)
        if not verify:
            return False, '验证码识别错误!'
        formData = {
            'loginUserDTO.user_name': userName,
            'userDTO.password': userPwd,
            'randCode': results,
        }
        jsonRet = EasyHttp.send(self._urlInfo['login'], data=formData)
        print('loginAsyncSuggest: %s' % jsonRet)

        def isSuccess(response):
            return response['status'] and response['data']['loginCheck'] == 'Y' if 'data' in response else False, \
                   response['data']['otherMsg'] if 'data' in response else response['messages']

        loginSuccess, otherMsg = isSuccess(jsonRet)
        return loginSuccess, '%s:%s' % (userName, otherMsg or '登录成功!')
Ejemplo n.º 9
0
    def _loginNormal(self, userName, userPwd):
        url = r'https://kyfw.12306.cn/passport/web/login'
        captcha = Captcha(self.__session)
        if not captcha.verifyCaptchaByHand()[1]:
            return False, '验证码识别错误!'
        headers = {
            'Referer': r'https://kyfw.12306.cn/otn/login/init',
            'User-Agent': FIREFOX_USER_AGENT,
            'Connection': 'keep-alive',
            'Content-Type':
            r'application/x-www-form-urlencoded; charset=UTF-8',
        }
        payload = {
            'username': userName,
            'password': userPwd,
            'appid': 'otn',
        }
        response = NetUtils.post(self.__session,
                                 url,
                                 data=payload,
                                 headers=headers)
        response = response.json() if response else None
        Log.v('loginResponse: %s' % response)

        def isLoginSuccess(responseJson):
            return 0 == responseJson[
                'result_code'] if responseJson and 'result_code' in responseJson else False

        if not isLoginSuccess(response):
            return False
        self._passportRedirect()
        self._userLogin()
        result, msg, apptk = self._uamtk()
        if not Utils.check(result, msg):
            return False
        return self._uamauthclient(apptk)
Ejemplo n.º 10
0
    def _loginAsyncSuggest(self, userName, userPwd):
        self._init()
        results, verify = Captcha().verifyCaptchaByHand(
            type=TYPE_LOGIN_OTHER_WAY)
        if not verify:
            return False, "验证码识别错误!"
        formData = {
            "loginUserDTO.user_name": userName,
            "userDTO.password": userPwd,
            "randCode": results,
        }
        jsonRet = EasyHttp.send(self._urlInfo["login"], data=formData)
        print("loginAsyncSuggest: %s" % jsonRet)

        def isSuccess(response):
            return (
                response["status"] and response["data"]["loginCheck"] == "Y"
                if "data" in response else False,
                response["data"]["otherMsg"]
                if "data" in response else response["messages"],
            )

        loginSuccess, otherMsg = isSuccess(jsonRet)
        return loginSuccess, "%s:%s" % (userName, otherMsg or "登录成功!")