From 2aef916e508b4979acafcaa7fe8684951607f879 Mon Sep 17 00:00:00 2001 From: fancymax Date: Sat, 13 Jan 2018 20:56:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=B4=E6=97=B6=E5=A4=84=E7=90=86=20?= =?UTF-8?q?=E9=A2=91=E7=B9=81=E7=99=BB=E9=99=86=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 12306ForMac/Service/Service+Login.swift | 20 ++++++++++++++++---- 12306ForMac/Service/Service.swift | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/12306ForMac/Service/Service+Login.swift b/12306ForMac/Service/Service+Login.swift index 7a68d25..9d2f916 100644 --- a/12306ForMac/Service/Service+Login.swift +++ b/12306ForMac/Service/Service+Login.swift @@ -16,7 +16,15 @@ extension Service { // MARK: - Request Flow func preLoginFlow(success:@escaping (NSImage)->Void,failure:@escaping (NSError)->Void){ - loginInit().then{dynamicJs -> Promise in + ///RAIL_DEVICEID=Rbi2_kj_dkMqD3ySkogkRhJ1rIh7X9L6tTT1xuDjBHlCaCdG9nydyoZDWlpGkBhgnA1u8pvUXZTgGchGfGQxBbKnj6QDUWM1g8gJaWnMbKME25UD3WLfJNymGAPFyUExwCBaBkFDNzqpiUiD1lk3Y12oHBaed4Rt; + //RAIL_EXPIRATION=1516128139770; + + let cookie1 = HTTPCookie(properties: [.name:"RAIL_DEVICEID",.domain:"kyfw.12306.cn",.value:"Rbi2_kj_dkMqD3ySkogkRhJ1rIh7X9L6tTT1xuDjBHlCaCdG9nydyoZDWlpGkBhgnA1u8pvUXZTgGchGfGQxBbKnj6QDUWM1g8gJaWnMbKME25UD3WLfJNymGAPFyUExwCBaBkFDNzqpiUiD1lk3Y12oHBaed4Rt",.path:"/"]) + let cookie2 = HTTPCookie(properties: [.name:"RAIL_EXPIRATION",.domain:"kyfw.12306.cn",.value:"1516128139770",.path:"/"]) + Service.Manager.session.configuration.httpCookieStorage?.setCookie(cookie1!) + Service.Manager.session.configuration.httpCookieStorage?.setCookie(cookie2!) + + loginInit().then{(dynamicJs) -> Promise in return self.requestDynamicJs(dynamicJs, referHeader: ["refer": "https://kyfw.12306.cn/otn/login/init"]) }.then{_ -> Promise in return self.getPassCodeNewForLogin() @@ -184,7 +192,8 @@ extension Service { return Promise{ fulfill, reject in let url = passport_captcha_check let params = ["answer":randCodeStr,"login_site":"E","rand":"sjrand"] - let headers = ["refer": "https://kyfw.12306.cn/otn/login/init"] + let headers = ["Referer": "https://kyfw.12306.cn/otn/login/init", + "X-Requested-With":"XMLHttpRequest"] Service.Manager.request(url, method:.post, parameters: params, headers:headers).responseJSON(completionHandler:{response in switch (response.result){ case .failure(let error): @@ -204,9 +213,12 @@ extension Service { func loginUserWith(_ user:String, passWord:String, randCodeStr:String)->Promise{ return Promise{ fulfill, reject in let url = passport_login + let params = ["username":user,"password":passWord,"appid":passport_appId] - let headers = ["refer": "https://kyfw.12306.cn/otn/login/init"] - Service.Manager.request(url, method:.post, parameters: params, headers:headers).responseJSON(completionHandler:{response in + let headers = ["Referer": "https://kyfw.12306.cn/otn/login/init", + "Origin":"https://kyfw.12306.cn", + "X-Requested-With":"XMLHttpRequest"] + Service.Manager.request(url, method:.post, parameters: params,encoding: URLEncoding.default, headers:headers).responseJSON(completionHandler:{response in switch (response.result){ case .failure(let error): reject(error) diff --git a/12306ForMac/Service/Service.swift b/12306ForMac/Service/Service.swift index 4ed466d..172729a 100644 --- a/12306ForMac/Service/Service.swift +++ b/12306ForMac/Service/Service.swift @@ -24,7 +24,7 @@ class Service { let headers = [ "refer": "https://kyfw.12306.cn/otn/leftTicket/init", "Host": "kyfw.12306.cn", - "User-Agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:36.0) Gecko/20100101 Firefox/36.0", + "User-Agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Safari/604.1.38", "Connection" : "keep-alive"] let configuration = URLSessionConfiguration.default