| | |
| | | if progress {showHUD()} |
| | | |
| | | var headers = HTTPHeaders() |
| | | // if let token = UserViewModel.getToken(){ |
| | | // headers.add(name: "Authorization", value: "Bearer" + " " + token) |
| | | // LogInfo("USER_token:Bearer \(token)") |
| | | // } |
| | | if let token = UserViewModel.getLoginInfo()?.accessToken{ |
| | | headers.add(name: "Authorization", value: "Bearer" + " " + token) |
| | | LogInfo("USER_token:Bearer \(token)") |
| | | } |
| | | |
| | | if encoding is JSONEncoding { |
| | | headers.add(name: "Content-Type", value: "application/json;charset=UTF-8") |
| | |
| | | if encoding != nil { |
| | | newEncoding = encoding! |
| | | } else { |
| | | #if DEBUG |
| | | newEncoding = URLEncoding.queryString |
| | | #else |
| | | // #if DEBUG |
| | | // newEncoding = URLEncoding.queryString |
| | | // #else |
| | | newEncoding = method == .post ? URLEncoding.httpBody : URLEncoding.queryString |
| | | #endif |
| | | // #endif |
| | | } |
| | | |
| | | sharedSessionManager.request(params.url.absoluteString, method: method, parameters:params.done(), encoding: newEncoding, headers:headers).validate().responseData{response in |
| | |
| | | if let next = BaseResponse<T>.deserialize(from: jsonString){ |
| | | switch next.code{ |
| | | case 200:ob.onNext(next) |
| | | case 501: |
| | | // CommonAlertView.show(title: "提示", content: next.msg,isSingle: true) { _ in |
| | | // |
| | | // } |
| | | ob.onError(NetRequestError.InvaildSession) |
| | | case 600: |
| | | if !ignoreAlert{ |
| | | alertError(msg: "登录失效,请重新登录");ob.onError(NetRequestError.InvaildSession) |
| | | } |
| | | // app.needLogin() |
| | | case 401:ob.onError(NetRequestError.InvaildSession) |
| | | default: |
| | | if !ignoreAlert{ |
| | | alertError(msg: "\(next.msg)") |