Exemple #1
0
    def _captchaCheck(self, results):
        data = {
            'answer': results,
            'login_site': 'E',
            'rand': 'sjrand',
        }
        result = EasyHttp.send(loginUrls['normal']['captchaCheck'], data=data)
        Log.v('验证码校验结果:%s' % result.get('result_message'))

        return result.get('result_code') == '4'
Exemple #2
0
    def _uamtk(self):
        jsonRet = EasyHttp.send(self._urlInfo['uamtk'], data={'appid': 'otn'})

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

        return isSuccess(jsonRet), \
               jsonRet['result_message'] if jsonRet and 'result_message' in jsonRet else 'no result_message', \
               jsonRet['newapptk'] if jsonRet and 'newapptk' in jsonRet else 'no newapptk'
Exemple #3
0
    def _uamauthclient(self, apptk):
        jsonRet = EasyHttp.send(self._urlInfo['uamauthclient'], data={'tk': apptk})

        # print(jsonRet)

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

        return isSuccess(jsonRet), '%s:%s' % (jsonRet['username'], jsonRet['result_message']) if jsonRet \
            else 'uamauthclient failed'
Exemple #4
0
    def _captchaCheck(self, results):
        data = {"answer": results, "login_site": "E", "rand": "sjrand"}
        jsonRet = EasyHttp.send(loginUrls["normal"]["captchaCheck"], data=data)
        print("captchaCheck: %s" % jsonRet)

        def verify(response):
            return (Captcha.__REPONSE_NORMAL_CDOE_SUCCESSFUL
                    == response["result_code"]
                    if "result_code" in response else False)

        return verify(jsonRet)
Exemple #5
0
    def getCaptcha(self):
        Log.v('正在获取验证码...')
        urlInfo = loginUrls['normal']['loginCaptchaCode']

        response = EasyHttp.send(urlInfo)
        if response and response['result_code'] != '0':
            Log.v('获取验证码失败')
            return None

        img_base64 = base64.b64decode(response['image'])
        return img_base64
Exemple #6
0
    def _queryOrderWaitTime(self):
        params = {
            'random': '%d' % (time.time() * 1000),
            'tourFlag': self.__ticket.ticketInfoForPassengerForm['tour_flag'] or 'dc',
            '_json_att': '',
            'REPEAT_SUBMIT_TOKEN': self.__ticket.repeatSubmitToken,
        }
        jsonRet = EasyHttp.send(self._urlInfo['queryOrderWaitTime'], params=params)

        return jsonRet['status'], jsonRet['messages'], jsonRet['data']['waitTime'], jsonRet['data']['orderId'], \
               jsonRet['data']['msg'] if 'msg' in jsonRet['data'] else None
Exemple #7
0
 def _resultOrderForDcOrWcQueue(self, orderSequenceNo):
     formData = {
         "orderSequence_no": orderSequenceNo,
         "_json_att": "",
         "REPEAT_SUBMIT_TOKEN": self.__ticket.repeatSubmitToken,
     }
     jsonRet = EasyHttp.send(self._urlInfo["resultOrderForQueue"],
                             data=formData)
     print("resultOrderForDcOrWcQueue", jsonRet)
     return jsonRet["status"], jsonRet["messages"], jsonRet["data"][
         "submitStatus"]
Exemple #8
0
 def _resultOrderForDcOrWcQueue(self, orderSequenceNo):
     formData = {
         'orderSequence_no': orderSequenceNo,
         '_json_att': '',
         'REPEAT_SUBMIT_TOKEN': self.__ticket.repeatSubmitToken,
     }
     jsonRet = EasyHttp.send(self._urlInfo['resultOrderForQueue'],
                             data=formData)
     # print('resultOrderForDcOrWcQueue', jsonRet)
     return jsonRet['status'], jsonRet['messages'], jsonRet['data'][
         'submitStatus']
Exemple #9
0
 def _queryMyOrderNoComplete(self):
     formData = {
         '_json_att': '',
     }
     jsonRet = EasyHttp.send(self._urlInfo['queryMyOrderNoComplete'], data=formData)
     try:
         status = jsonRet['status']
         messages = jsonRet['messages']
         datas = jsonRet['data']
     except Exception as e:
         return False,None,None
     return status, messages, datas
Exemple #10
0
    def _checkRandCodeAnsyn(self, results):
        formData = {
            'randCode': results,
            'rand': 'sjrand',
        }
        jsonRet = EasyHttp.send(loginUrls['other']['captchaCheck'], data=formData)
        print('checkRandCodeAnsyn: %s' % jsonRet)

        def verify(response):
            return response['status'] and Captcha.__REPONSE_OHTER_CDOE_SUCCESSFUL == response['data']['result']

        return verify(jsonRet)
Exemple #11
0
 def _getPassengerDTOs(self):
     if not self._getExtraInfo():
         return False, '获取乘客信息失败', None
     formData = {
         '_json_att': '',
         'REPEAT_SUBMIT_TOKEN': self.__ticket.repeatSubmitToken,
     }
     jsonRet = EasyHttp.send(self._urlInfo['getPassengerDTOs'], data=formData)
     passengersList = jsonRet['data']['normal_passengers']
     return jsonRet['status'] if 'status' in jsonRet else False, \
            jsonRet['messages'] if jsonRet and 'messages' in jsonRet else '无法获取乘客信息,请先进行添加!', \
            self.__getPassengerInfo(passengersList)
Exemple #12
0
 def _login_init(self):
     url_info = copy.deepcopy(self._urlInfo["getDevicesId"])
     url_info['url'] = self._urlInfo["getDevicesId"]['url'] + str(
         int(time.time() * 1000))
     devices_id_rsp = EasyHttp.get_custom(url_info)
     if devices_id_rsp:
         callback = devices_id_rsp.text.replace("callbackFunction('",
                                                '').replace("')", '')
         try:
             text = json.loads(callback)
             devices_id = text.get('dfp')
             exp = text.get('exp')
         except Exception as e:
             print(e)
             return False, '获取设备指纹失败,请查询12306设备Id获取url是否需要更新'
         EasyHttp.setCookies(RAIL_DEVICEID=devices_id, RAIL_EXPIRATION=exp)
         # Log.d('设备Id:%s'%devices_id)
         return True, '获取设备指纹成功'
     EasyHttp.send(self._urlInfo['index'])
     EasyHttp.send(self._urlInfo['loginInit'])
     return False, '获取设备指纹失败,请查询12306设备Id获取url是否需要更新'
Exemple #13
0
    def _checkRandCodeAnsyn(self, results):
        formData = {"randCode": results, "rand": "sjrand"}
        jsonRet = EasyHttp.send(loginUrls["other"]["captchaCheck"],
                                data=formData)
        print("checkRandCodeAnsyn: %s" % jsonRet)

        def verify(response):
            return (response["status"]
                    and Captcha.__REPONSE_OHTER_CDOE_SUCCESSFUL
                    == response["data"]["result"])

        return verify(jsonRet)
Exemple #14
0
    def _uamtk(self):
        jsonRet = EasyHttp.send(self._urlInfo["uamtk"], data={"appid": "otn"})

        def isSuccess(response):
            return response[
                "result_code"] == 0 if "result_code" in response else False

        return (
            isSuccess(jsonRet),
            jsonRet["result_message"]
            if "result_message" in jsonRet else "no result_message",
            jsonRet["newapptk"] if "newapptk" in jsonRet else "no newapptk",
        )
Exemple #15
0
 def query(trainDate, fromStation, toStation, passengerType=PASSENGER_TYPE_ADULT):
     params = {
         r'leftTicketDTO.train_date': trainDate,
         r'leftTicketDTO.from_station': city2code(fromStation),
         r'leftTicketDTO.to_station': city2code(toStation),
         r'purpose_codes': passengerType
     }
     jsonRet = EasyHttp.send(queryUrls['query'], params=params)
     try:
         if jsonRet:
             return Query.__decode(jsonRet['data']['result'], passengerType)
     except Exception as e:
         Log.e(e)
     return []
Exemple #16
0
    def _captchaAutoCheck(self, results):
        params = {
            'answer': results,
            'login_site': 'E',
            'rand': 'sjrand',
            '_':int(time.time() * 1000)
        }
        jsonRet = EasyHttp.send(autoVerifyUrls['check_url'],params=params)

        # Log.d('验证码识别结果: %s' % jsonRet if jsonRet else 'None')
        def verify(response):
            return Captcha.__REPONSE_NORMAL_CDOE_SUCCESSFUL == response['result_code'] if response and 'result_code' in response else False

        return verify(jsonRet)
Exemple #17
0
    def _uamauthclient(self, apptk):
        jsonRet = EasyHttp.send(self._urlInfo["uamauthclient"],
                                data={"tk": apptk})
        print(jsonRet)

        def isSuccess(response):
            return (response["result_code"] == 0
                    if response and "result_code" in response else False)

        return (
            isSuccess(jsonRet),
            "%s:%s" % (jsonRet["username"], jsonRet["result_message"])
            if jsonRet else "uamauthclient failed",
        )
Exemple #18
0
    def _captchaCheck(self, results):
        data = {
            'answer': results,
            'login_site': 'E',
            'rand': 'sjrand',
        }
        jsonRet = EasyHttp.send(loginUrls['normal']['captchaCheck'], data=data)
        print('captchaCheck: %s' % jsonRet)

        def verify(response):
            return Captcha.__REPONSE_NORMAL_CDOE_SUCCESSFUL == response[
                'result_code'] if 'result_code' in response else False

        return verify(jsonRet)
Exemple #19
0
    def _login_init(self):
        #死方法来手动每次更新deviceid url
        url_info = copy.deepcopy(self._urlInfo["getDevicesId"])
        url_info['url'] = self._urlInfo["getDevicesId"]['url'] + str(int(time.time()*1000))
        devices_id_rsp = EasyHttp.get_custom(url_info)

        # params = {"algID": request_alg_id(self._urlInfo['getJS']), "timestamp": int(time.time() * 1000)}
        # params = dict(params, **get_hash_code_params())
        # devices_id_rsp = EasyHttp.send(self._urlInfo["getDevicesId"],params=params)
        if devices_id_rsp:
            callback = devices_id_rsp.text[18:-2]
            # callback = devices_id_rsp.replace("callbackFunction('", '').replace("')", '')
            try:
                text = json.loads(callback)
                devices_id = text.get('dfp')
                exp = text.get('exp')
            except Exception as e:
                return False,'获取设备指纹失败'
            EasyHttp.setCookies(RAIL_DEVICEID=devices_id, RAIL_EXPIRATION=exp)
            # Log.d('设备Id:%s'%devices_id)
            return True, '获取设备指纹成功'
        EasyHttp.send(self._urlInfo['index'])
        EasyHttp.send(self._urlInfo['loginInit'])
        return False,'获取设备指纹失败'
Exemple #20
0
    def _captchaAutoCheck(self, results):

        params = {
            'answer': results,
            'login_site': 'E',
            'rand': 'sjrand',
        }
        jsonRet = EasyHttp.send(autoVerifyUrls['check_url'], params=params)

        # print('captchaCheck: %s' % jsonRet)

        def verify(response):
            return Captcha.__REPONSE_NORMAL_CDOE_SUCCESSFUL == response[
                'result_code'] if 'result_code' in response else False

        return verify(jsonRet)
Exemple #21
0
 def _submitOrderRequest(self, tourFlag='dc'):
     formData = {
         'secretStr': TrainUtils.undecodeSecretStr(self.__ticket.secretStr),
         # 'secretStr': self.__ticket.secretStr,
         # 'secretStr': urllib.parse.unquote(self.__ticket.secretStr),
         'train_date': Utils.formatDate(self.__ticket.startDate),  # 2018-01-04
         'back_train_date': time.strftime("%Y-%m-%d", time.localtime()),  # query date:2017-12-31
         'tour_flag': tourFlag,
         'purpose_codes': self.__ticket.passengerType,
         'query_from_station_name': self.__ticket.fromStation,
         'query_to_station_name': self.__ticket.toStation,
         'undefined': '',
     }
     jsonRet = EasyHttp.send(self._urlInfo['submitOrderRequest'], data=formData)
     # print('submitOrderRequest %s' % jsonRet)
     return jsonRet['status'], jsonRet['messages']
Exemple #22
0
 def _getPassengerDTOs(self):
     if not self._getExtraInfo():
         return False, "获取乘客信息失败", None
     formData = {
         "_json_att": "",
         "REPEAT_SUBMIT_TOKEN": self.__ticket.repeatSubmitToken,
     }
     jsonRet = EasyHttp.send(self._urlInfo["getPassengerDTOs"],
                             data=formData)
     passengersList = jsonRet["data"]["normal_passengers"]
     return (
         jsonRet["status"] if "status" in jsonRet else False,
         jsonRet["messages"]
         if "messages" in jsonRet else "无法获取乘客信息,请先进行添加!",
         self.__getPassengerInfo(passengersList),
     )
Exemple #23
0
    def _getExtraInfo(self):
        def getRepeatSubmitToken(html):
            repeatSubmitToken = re.findall(r"var globalRepeatSubmitToken = '(.*)'", html)[0]
            # print('RepeatSubmitToken = %s' % repeatSubmitToken)
            return repeatSubmitToken

        html = EasyHttp.send(self._urlInfo['getExtraInfo'])
        if not Utils.check(html, 'getExtraInfoUrl: failed to visit %s' % self._urlInfo['getExtraInfo']['url']):
            return False
        self.__ticket.repeatSubmitToken = getRepeatSubmitToken(html)

        def decodeTicketInfoForPassengerForm(html):
            ticketInfoForPassengerForm = re.findall(r'var ticketInfoForPassengerForm=(.*);', html)[0]
            return json.loads(ticketInfoForPassengerForm.replace("'", "\""))
        # print('=======================')
        self.__ticket.ticketInfoForPassengerForm = decodeTicketInfoForPassengerForm(html)
        return True
Exemple #24
0
 def query(trainDate,
           fromStation,
           toStation,
           passengerType=PASSENGER_TYPE_ADULT):
     params = {
         r"leftTicketDTO.train_date": trainDate,
         r"leftTicketDTO.from_station": city2code(fromStation),
         r"leftTicketDTO.to_station": city2code(toStation),
         r"purpose_codes": passengerType,
     }
     jsonRet = EasyHttp.send(queryUrls["query"], params=params)
     try:
         if jsonRet:
             return Query.__decode(jsonRet["data"]["result"], passengerType)
     except Exception as e:
         Log.e(e)
     return []
Exemple #25
0
    def _captchaCheck(self, results):
        data = {
            'answer': results,
            'login_site': 'E',
            'rand': 'sjrand',
            '_': int(time.time() * 1000)
        }
        jsonRet = EasyHttp.send(loginUrls['normal']['captchaCheck'],
                                params=data)
        if not jsonRet:
            return False

        def verify(response):
            return Captcha.__REPONSE_NORMAL_CDOE_SUCCESSFUL == response[
                'result_code'] if 'result_code' in response else False

        return verify(jsonRet)
Exemple #26
0
 def _queryOrderWaitTime(self):
     params = {
         "random": "%10d" % (time.time() * 1000),
         "tourFlag": self.__ticket.ticketInfoForPassengerForm["tour_flag"]
         or "dc",
         "_json_att": "",
         "REPEAT_SUBMIT_TOKEN": self.__ticket.repeatSubmitToken,
     }
     jsonRet = EasyHttp.send(self._urlInfo["queryOrderWaitTime"],
                             params=params)
     print("queryOrderWaitTime: %s" % jsonRet)
     return (
         jsonRet["status"],
         jsonRet["messages"],
         jsonRet["data"]["waitTime"],
         jsonRet["data"]["orderId"],
         jsonRet["data"]["msg"] if "msg" in jsonRet["data"] else None,
     )
Exemple #27
0
 def _getQueueCount(self):
     formData = {
         # Thu+Jan+04+2018+00:00:00+GMT+0800
         # 'train_date': datetime.strptime(
         #     self.__ticket.ticketInfoForPassengerForm['queryLeftTicketRequestDTO']['train_date'], '%Y%m%d').strftime(
         #     '%b+%a+%d+%Y+00:00:00+GMT+0800'),
         # Mon Jan 08 2018 00:00:00 GMT+0800 (中国标准时间)
         "train_date":
         datetime.strptime(
             self.__ticket.ticketInfoForPassengerForm[
                 "queryLeftTicketRequestDTO"]["train_date"],
             "%Y%m%d",
         ).strftime("%b %a %d %Y 00:00:00 GMT+0800") + " (中国标准时间)",
         "train_no":
         self.__ticket.ticketInfoForPassengerForm[
             "queryLeftTicketRequestDTO"]["train_no"],
         "stationTrainCode":
         self.__ticket.trainNo,
         "seatType":
         self.__ticket.seatType,
         "fromStationTelecode":
         self.__ticket.fromStationCode,
         "toStationTelecode":
         self.__ticket.toStationCode,
         "leftTicket":
         self.__ticket.ticketInfoForPassengerForm["leftTicketStr"],
         "purpose_codes":
         self.__ticket.ticketInfoForPassengerForm["purpose_codes"],
         "train_location":
         self.__ticket.ticketInfoForPassengerForm["train_location"],
         "_json_att":
         "",
         "REPEAT_SUBMIT_TOKEN":
         self.__ticket.repeatSubmitToken,
     }
     jsonRet = EasyHttp.send(self._urlInfo["getQueueCount"], data=formData)
     return (
         jsonRet["status"],
         jsonRet["messages"],
         jsonRet["data"]["ticket"]
         if "data" in jsonRet and "ticket" in jsonRet["data"] else -1,
         jsonRet["data"]["count"]
         if "data" in jsonRet and "count" in jsonRet["data"] else -1,
     )
Exemple #28
0
 def _submitOrderRequest(self, tourFlag="dc"):
     formData = {
         "secretStr": TrainUtils.undecodeSecretStr(self.__ticket.secretStr),
         # 'secretStr': self.__ticket.secretStr,
         # 'secretStr': urllib.parse.unquote(self.__ticket.secretStr),
         "train_date":
         Utils.formatDate(self.__ticket.startDate),  # 2018-01-04
         "back_train_date":
         time.strftime("%Y-%m-%d",
                       time.localtime()),  # query date:2017-12-31
         "tour_flag": tourFlag,
         "purpose_codes": self.__ticket.passengerType,
         "query_from_station_name": self.__ticket.fromStation,
         "query_to_station_name": self.__ticket.toStation,
         "undefined": "",
     }
     jsonRet = EasyHttp.send(self._urlInfo["submitOrderRequest"],
                             data=formData)
     print("submitOrderRequest %s" % jsonRet)
     return jsonRet["status"], jsonRet["messages"]
Exemple #29
0
 def _checkOrderInfo(self, passengersDetails, seatType, ticketTypeCodes=1):
     formData = {
         'cancel_flag': self.__ticket.ticketInfoForPassengerForm['orderRequestDTO']['cancel_flag'] or '2',
         'bed_level_order_num': self.__ticket.ticketInfoForPassengerForm['orderRequestDTO'][
                                    'bed_level_order_num'] or '000000000000000000000000000000',
         'passengerTicketStr': TrainUtils.passengerTicketStrs(seatType, passengersDetails, ticketTypeCodes),
         'oldPassengerStr': TrainUtils.oldPassengerStrs(passengersDetails),
         'tour_flag': self.__ticket.ticketInfoForPassengerForm['tour_flag'] or 'dc',
         'randCode': '',
         'whatsSelect': '1',
         '_json_att': '',
         'REPEAT_SUBMIT_TOKEN': self.__ticket.repeatSubmitToken,
     }
     jsonRet = EasyHttp.send(self._urlInfo['checkOrderInfo'], data=formData)
     submitStatus = ''
     errMsg = ''
     if jsonRet['data']:
         submitStatus = jsonRet['data']['submitStatus']
         errMsg = jsonRet['data']['errMsg'] if 'errMsg' in jsonRet['data'] else 'submit falied'
     return jsonRet['status'], jsonRet['messages'], submitStatus, errMsg
    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 '登录成功!')