Exemplo n.º 1
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 '登录成功!')
Exemplo n.º 2
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)