From b4c6c4f85888eb3ef1eb205b087037183fd24489 Mon Sep 17 00:00:00 2001 From: wenxianping <931128603@qq.com> Date: Mon, 1 Apr 2019 21:29:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A0=E9=9C=80=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/urlConf.py | 102 +++++++++++++++++++++++++++++++++----- init/login.py | 31 ++++++++---- inter/LoginAysnSuggest.py | 20 ++++++++ inter/LoginConf.py | 22 ++++++++ 4 files changed, 151 insertions(+), 24 deletions(-) create mode 100644 inter/LoginAysnSuggest.py create mode 100644 inter/LoginConf.py diff --git a/config/urlConf.py b/config/urlConf.py index 20b812e..1ec985d 100755 --- a/config/urlConf.py +++ b/config/urlConf.py @@ -337,18 +337,6 @@ urls = { "is_logger": True, "is_json": True, }, - "loginAysnSuggest": { # 快速订单排队 - "req_url": "/otn/login/loginAysnSuggest", - "req_type": "post", - "Referer": "https://kyfw.12306.cn/otn/leftTicket/init", - "Content-Type": 1, - "Host": "kyfw.12306.cn", - "re_try": 10, - "re_time": 0.01, - "s_time": 0.1, - "is_logger": True, - "is_json": True, - }, "Pushbear": { # push通知 "req_url": "/sub", "req_type": "post", @@ -368,5 +356,93 @@ urls = { "cdn_list": { "req_url": "http://ping.chinaz.com/iframe.ashx?t=ping&callback=jQuery111304824429956769827_{}".format(int(round(time.time() * 1000))), "req_type": "post" - } + }, + + "TPLINK": { # TPLINK请求地址 + "req_url": "/", + "req_type": "post", + "Referer": "", + "Content-Type": 1, + "Host": "192.168.0.1", + "re_try": 10, + "re_time": 0.01, + "s_time": 0.1, + "is_logger": False, + "is_json": True, + "httpType": "http" + }, + "TPds": { # TPLINK路由器内部切换地址 + "req_url": "/stok={}/ds", + "req_type": "post", + "Referer": "", + "Content-Type": 1, + "Host": "192.168.0.1", + "re_try": 10, + "re_time": 0.01, + "s_time": 0.1, + "is_logger": False, + "is_json": True, + "httpType": "http" + }, + "xiaomiHome": { # 小米路由器登录 + "req_url": "/cgi-bin/luci/web", + "req_type": "get", + "Referer": "", + "Content-Type": 1, + "Host": "192.168.31.1", + "re_try": 10, + "re_time": 0.01, + "s_time": 0.1, + "is_logger": False, + "is_json": False, + "httpType": "http" + }, + "xiaomi": { # 小米路由器登录 + "req_url": "/cgi-bin/luci/api/xqsystem/login", + "req_type": "post", + "Referer": "", + "Content-Type": 1, + "Host": "192.168.31.1", + "re_try": 10, + "re_time": 0.01, + "s_time": 0.1, + "is_logger": False, + "is_json": True, + "httpType": "http" + }, + "loginHtml": { # 登录接口2 + "req_url": "/otn/resources/login.html", + "req_type": "get", + "Referer": "https://kyfw.12306.cn/otn/leftTicket/init", + "Host": "kyfw.12306.cn", + "re_try": 10, + "re_time": 0.3, + "s_time": 0.1, + "is_logger": True, + "is_json": True, + }, + "loginConf": { # 登录接口2 + "req_url": "/otn/login/conf", + "req_type": "post", + "Referer": "https://kyfw.12306.cn/otn/leftTicket/init", + "Host": "kyfw.12306.cn", + "re_try": 10, + "re_time": 0.3, + "s_time": 0.1, + "is_logger": True, + "is_json": True, + }, + "loginAysnSuggest": { # 登录接口2 + "req_url": "/otn/login/loginAysnSuggest", + "req_type": "post", + "Referer": "https://kyfw.12306.cn/otn/leftTicket/init", + "Host": "kyfw.12306.cn", + "re_try": 10, + "re_time": 0.3, + "s_time": 0.1, + "is_logger": True, + "is_json": True, + }, + + } \ No newline at end of file diff --git a/init/login.py b/init/login.py index 11913e4..eef5967 100755 --- a/init/login.py +++ b/init/login.py @@ -4,6 +4,8 @@ from time import sleep from config.ticketConf import _get_yaml from inter.GetPassCodeNewOrderAndLogin import getPassCodeNewOrderAndLogin from inter.GetRandCode import getRandCode +from inter.LoginAysnSuggest import loginAysnSuggest +from inter.LoginConf import loginConf from myException.UserPasswordException import UserPasswordException from myException.balanceException import balanceException @@ -113,17 +115,24 @@ class GoLogin: raise UserPasswordException(u"温馨提示: 用户名或者密码为空,请仔细检查") login_num = 0 while True: - result = getPassCodeNewOrderAndLogin(session=self.session, imgType="login") - if not result: - continue - self.randCode = getRandCode(self.is_auto_code, self.auto_code_type, result) - login_num += 1 - self.auth() - if self.codeCheck(): - uamtk = self.baseLogin(user, passwd) - if uamtk: - self.getUserName(uamtk) - break + if loginConf(self.session): + result = getPassCodeNewOrderAndLogin(session=self.session, imgType="login") + if not result: + continue + self.randCode = getRandCode(self.is_auto_code, self.auto_code_type, result) + login_num += 1 + self.auth() + if self.codeCheck(): + uamtk = self.baseLogin(user, passwd) + if uamtk: + self.getUserName(uamtk) + break + else: + loginAysnSuggest(self.session, username=user, password=passwd) + login_num += 1 + break + + # if __name__ == "__main__": # # main() diff --git a/inter/LoginAysnSuggest.py b/inter/LoginAysnSuggest.py new file mode 100644 index 0000000..e58d7a9 --- /dev/null +++ b/inter/LoginAysnSuggest.py @@ -0,0 +1,20 @@ +# coding=utf-8 +from config.urlConf import urls + + +def loginAysnSuggest(session, username, password): + """ + 登录接口 + ps: 不需要验证码 + :return: + """ + loginAysnSuggestUrls = urls.get("loginAysnSuggest") + data = { + "loginUserDTO.user_name": username, + "userDTO.password": password + } + loginAysnSuggestRsp = session.httpClint.send(urls=loginAysnSuggestUrls, data=data) + if loginAysnSuggestRsp and loginAysnSuggestRsp.get("httpstatus") is 200 and loginAysnSuggestRsp.get("data", {}).get("loginCheck") == "Y": + print(u"登录成功") + else: + print(u"登录失败, {0} {1}".format("".join(loginAysnSuggestRsp.get("messages")), loginAysnSuggestRsp.get("validateMessages"))) diff --git a/inter/LoginConf.py b/inter/LoginConf.py new file mode 100644 index 0000000..7138aac --- /dev/null +++ b/inter/LoginConf.py @@ -0,0 +1,22 @@ +# coding=utf-8 +from config.urlConf import urls + + +def loginConf(session): + """ + 判断登录是否需要验证码 + :param session: + :return: + """ + loginConfUrl = urls.get("loginConf") + loginConfRsp = session.httpClint.send(urls=loginConfUrl, data={}) + if loginConfRsp and loginConfRsp.get("data", {}).get("is_login_passCode") == "N": + print(u"不需要验证码") + return False + else: + print(u"需要验证码") + return True + + +if __name__ == '__main__': + pass \ No newline at end of file