Ejemplo 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 '登录成功!')
Ejemplo n.º 2
0
 def isLogin(self):
     url = r'https://kyfw.12306.cn/otn/login/checkUser'
     headers = {
         'User-Agent': FIREFOX_USER_AGENT,
         'Referer': r'https://kyfw.12306.cn/otn/leftTicket/init',
         'Connection': 'keep-alive',
     }
     formData = {'_json_att': ''}
     response = NetUtils.post(self.__session,
                              url,
                              formData,
                              headers=headers)
     response = response.json() if response else None
     return response['data'][
         'flag'] if response and 'data' in response and 'flag' in response[
             'data'] else False