Skip to content

Commit

Permalink
fix: 临时处理 频繁登陆失败的问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
fancymax committed Jan 13, 2018
1 parent 7327574 commit 2aef916
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions 12306ForMac/Service/Service+Login.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ extension Service {

// MARK: - Request Flow
func preLoginFlow(success:@escaping (NSImage)->Void,failure:@escaping (NSError)->Void){
loginInit().then{dynamicJs -> Promise<Void> 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<Void> in
return self.requestDynamicJs(dynamicJs, referHeader: ["refer": "https://kyfw.12306.cn/otn/login/init"])
}.then{_ -> Promise<NSImage> in
return self.getPassCodeNewForLogin()
Expand Down Expand Up @@ -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):
Expand All @@ -204,9 +213,12 @@ extension Service {
func loginUserWith(_ user:String, passWord:String, randCodeStr:String)->Promise<Void>{
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)
Expand Down
2 changes: 1 addition & 1 deletion 12306ForMac/Service/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2aef916

Please sign in to comment.