|
@@ -265,24 +265,14 @@ class KMMemberCenterManager: NSObject {
|
|
|
var token_type = ""
|
|
|
var expires_in = ""
|
|
|
var scope = ""
|
|
|
- if let token = result_dict["refresh_token"] {
|
|
|
- refresh_token = token as! String
|
|
|
- }
|
|
|
- if let token = result_dict["access_token"] {
|
|
|
- access_token = token as! String
|
|
|
- }
|
|
|
- if let token = result_dict["token_type"] {
|
|
|
- token_type = token as! String
|
|
|
- }
|
|
|
- if let token = result_dict["expires_in"] {
|
|
|
- expires_in = token as! String
|
|
|
- }
|
|
|
- if let token = result_dict["scope"] {
|
|
|
- scope = token as! String
|
|
|
- }
|
|
|
+ if let token = result_dict["refresh_token"] { refresh_token = token as! String }
|
|
|
+ if let token = result_dict["access_token"] { access_token = token as! String }
|
|
|
+ if let token = result_dict["token_type"] { token_type = token as! String }
|
|
|
+ if let token = result_dict["expires_in"] { expires_in = token as! String }
|
|
|
+ if let token = result_dict["scope"] { scope = token as! String }
|
|
|
let loginResult = KMMemberLoginResult(refreshToken: refresh_token, accessToken: access_token, tokenType: token_type, expiresIn: expires_in, scope: scope)
|
|
|
|
|
|
- var result = KMMemberCenterResult(loginResult: loginResult)
|
|
|
+ let result = KMMemberCenterResult(loginResult: loginResult)
|
|
|
result.code = code
|
|
|
result.msg = message
|
|
|
// let error = NSError(domain: message, code: code)
|
|
@@ -331,18 +321,10 @@ class KMMemberCenterManager: NSObject {
|
|
|
var productId = ""
|
|
|
var uniqueSn = ""
|
|
|
var deviceName = ""
|
|
|
- if let token = dict["device_id"] {
|
|
|
- device_id = token as! String
|
|
|
- }
|
|
|
- if let token = dict["productId"] {
|
|
|
- productId = token as! String
|
|
|
- }
|
|
|
- if let token = dict["uniqueSn"] {
|
|
|
- uniqueSn = token as! String
|
|
|
- }
|
|
|
- if let token = dict["deviceName"] {
|
|
|
- deviceName = token as! String
|
|
|
- }
|
|
|
+ if let token = dict["device_id"] { device_id = token as! String }
|
|
|
+ if let token = dict["productId"] { productId = token as! String }
|
|
|
+ if let token = dict["uniqueSn"] { uniqueSn = token as! String }
|
|
|
+ if let token = dict["deviceName"] { deviceName = token as! String }
|
|
|
let list = KMMemberDeviceList(deviceId: device_id, productId: productId, uniqueSn: uniqueSn, appId: deviceName)
|
|
|
deviceLists.append(list)
|
|
|
}
|
|
@@ -398,7 +380,330 @@ class KMMemberCenterManager: NSObject {
|
|
|
|
|
|
// MARK: 个人信息模块
|
|
|
|
|
|
+ /**
|
|
|
+ @abstract 获取老带新已邀请人数
|
|
|
+ @param complete 回调
|
|
|
+ */
|
|
|
+ func getInviteNum(complete: @escaping KMMemberCenterComplete) {
|
|
|
+ let token: String = KMMemberInfo.defaultManager.access_token
|
|
|
+ if token == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let urlString = configuration.activityBaseURL() + "/member-system-sso/user/getInviteNum"
|
|
|
+ KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
|
|
|
+ requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
|
|
|
+ } completion: { [weak self] (task, responseObject, error) in
|
|
|
+ var dic: NSDictionary = [:]
|
|
|
+ if error == nil, let responseObject = responseObject as? NSDictionary {
|
|
|
+ dic = responseObject
|
|
|
+ } else {
|
|
|
+ var info = responseObject
|
|
|
+ if let error = error {
|
|
|
+ if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
|
|
|
+ info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dic = (info as? NSDictionary) ?? [:]
|
|
|
+ }
|
|
|
+
|
|
|
+ let code: Int = dic["code"] as? Int ?? 0
|
|
|
+ let resultInt: Int = dic["result"] as? Int ?? 0
|
|
|
+ let message: String = dic["msg"] as? String ?? ""
|
|
|
+
|
|
|
+ let result = KMMemberCenterResult(code: code, msg: message, resultInt: resultInt)
|
|
|
+ if code == 200 {
|
|
|
+ complete(true, result)
|
|
|
+ } else {
|
|
|
+ complete(false, result)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ @abstract 获取用户个人信息
|
|
|
+ @param complete 回调
|
|
|
+ */
|
|
|
+ func userInfo(complete: @escaping KMMemberCenterComplete) {
|
|
|
+ let token: String = KMMemberInfo.defaultManager.access_token
|
|
|
+ if token == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let urlString = configuration.activityBaseURL() + "/member-system-sso/user/info"
|
|
|
+ KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
|
|
|
+ requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
|
|
|
+ } completion: { [weak self] (task, responseObject, error) in
|
|
|
+ var dic: NSDictionary = [:]
|
|
|
+ if error == nil, let responseObject = responseObject as? NSDictionary {
|
|
|
+ dic = responseObject
|
|
|
+ } else {
|
|
|
+ var info = responseObject
|
|
|
+ if let error = error {
|
|
|
+ if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
|
|
|
+ info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dic = (info as? NSDictionary) ?? [:]
|
|
|
+ }
|
|
|
+
|
|
|
+ let code: Int = dic["code"] as? Int ?? 0
|
|
|
+ let result_dict: NSDictionary = dic["result"] as? NSDictionary ?? [:]
|
|
|
+ let message: String = dic["msg"] as? String ?? ""
|
|
|
+
|
|
|
+ var userId = ""
|
|
|
+ var email = ""
|
|
|
+ var fullName = ""
|
|
|
+ var activeVIP = KMMemberUserInfo()
|
|
|
+ var aiPoint = 0
|
|
|
+ var validFlag = ""
|
|
|
+ var isHavePwd = ""
|
|
|
+ var isHaveAIDiscount = ""
|
|
|
+ var canTrail = ""
|
|
|
+ if let token = result_dict["id"] { userId = token as! String }
|
|
|
+ if let token = result_dict["email"] { email = token as! String }
|
|
|
+ if let token = result_dict["fullName"] { fullName = token as! String }
|
|
|
+
|
|
|
+ let activeVIP_dict: NSDictionary = result_dict["activeVIP"] as? NSDictionary ?? [:]
|
|
|
+ var activeVIP_id = ""
|
|
|
+ var activeVIP_userId = ""
|
|
|
+ var activeVIP_status = 0
|
|
|
+ var activeVIP_endDate = ""
|
|
|
+ var activeVIP_payType = 0
|
|
|
+ var activeVIP_productName = ""
|
|
|
+ var activeVIP_levels = ""
|
|
|
+ var activeVIP_platforms = ""
|
|
|
+ var activeVIP_point = 0
|
|
|
+ var activeVIP_maxDeviceNum = 0
|
|
|
+ var activeVIP_paymentModel = ""
|
|
|
+ var activeVIP_isAi = ""
|
|
|
+ if let token = activeVIP_dict["id"] { activeVIP_id = token as! String }
|
|
|
+ if let token = activeVIP_dict["userId"] { activeVIP_userId = token as! String }
|
|
|
+ if let token = activeVIP_dict["status"] { activeVIP_status = token as! Int }
|
|
|
+ if let token = activeVIP_dict["endDate"] { activeVIP_endDate = token as! String }
|
|
|
+ if let token = activeVIP_dict["payType"] { activeVIP_payType = token as! Int }
|
|
|
+ if let token = activeVIP_dict["productName"] { activeVIP_productName = token as! String }
|
|
|
+ if let token = activeVIP_dict["levels"] { activeVIP_levels = token as! String }
|
|
|
+ if let token = activeVIP_dict["platforms"] { activeVIP_platforms = token as! String }
|
|
|
+ if let token = activeVIP_dict["point"] { activeVIP_point = token as! Int }
|
|
|
+ if let token = activeVIP_dict["maxDeviceNum"] { activeVIP_maxDeviceNum = token as! Int }
|
|
|
+ if let token = activeVIP_dict["paymentModel"] { activeVIP_paymentModel = token as! String }
|
|
|
+ if let token = activeVIP_dict["isAi"] { activeVIP_isAi = token as! String }
|
|
|
+ let userInfoActiveVIP = KMMemberUserInfoActiveVIP(id: activeVIP_id, userId: activeVIP_userId, status: activeVIP_status, endDate: activeVIP_endDate, payType: activeVIP_payType, productName: activeVIP_productName, levels: activeVIP_levels, platforms: activeVIP_platforms, point: activeVIP_point, maxDeviceNum: activeVIP_maxDeviceNum, paymentModel: activeVIP_paymentModel, isAi: activeVIP_isAi)
|
|
|
+
|
|
|
+ if let token = result_dict["aiPoint"] { aiPoint = token as! Int }
|
|
|
+ if let token = result_dict["validFlag"] { validFlag = token as! String }
|
|
|
+ if let token = result_dict["isHavePwd"] { isHavePwd = token as! String }
|
|
|
+ if let token = result_dict["isHaveAIDiscount"] { isHaveAIDiscount = token as! String }
|
|
|
+ if let token = result_dict["canTrail"] { canTrail = token as! String }
|
|
|
+
|
|
|
+ let userInfo = KMMemberUserInfo(id: userId, email: email, fullName: fullName, activeVIP: [userInfoActiveVIP], aiPoint: aiPoint, validFlag: validFlag, isHavePwd: isHavePwd, isHaveAIDiscount: isHaveAIDiscount, canTrail: canTrail)
|
|
|
+
|
|
|
+ let result = KMMemberCenterResult(code: code, msg: message, userInfo: userInfo)
|
|
|
+// let error = NSError(domain: message, code: code)
|
|
|
+ if code == 200 {
|
|
|
+ complete(true, result)
|
|
|
+ } else {
|
|
|
+ complete(false, result)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ @abstract 退出登录
|
|
|
+ @param complete 回调
|
|
|
+ */
|
|
|
+ func userLogout(complete: @escaping KMMemberCenterComplete) {
|
|
|
+ let token: String = KMMemberInfo.defaultManager.access_token
|
|
|
+ if token == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let urlString = configuration.activityBaseURL() + "/member-system-sso/user/logout"
|
|
|
+ KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
|
|
|
+ requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
|
|
|
+ } completion: { [weak self] (task, responseObject, error) in
|
|
|
+ var dic: NSDictionary = [:]
|
|
|
+ if error == nil, let responseObject = responseObject as? NSDictionary {
|
|
|
+ dic = responseObject
|
|
|
+ } else {
|
|
|
+ var info = responseObject
|
|
|
+ if let error = error {
|
|
|
+ if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
|
|
|
+ info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dic = (info as? NSDictionary) ?? [:]
|
|
|
+ }
|
|
|
+ let code: Int = dic["code"] as? Int ?? 0
|
|
|
+ let result_bool: Bool = dic["result"] as? Bool ?? false
|
|
|
+ let message: String = dic["msg"] as? String ?? ""
|
|
|
+
|
|
|
+ let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
|
|
|
+ if code == 200 {
|
|
|
+ complete(true, result)
|
|
|
+ } else {
|
|
|
+ complete(false, result)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ @abstract 获取用户当前会员情况
|
|
|
+ @param complete 回调
|
|
|
+ */
|
|
|
+ func userRightList(complete: @escaping KMMemberCenterComplete) {
|
|
|
+ let token: String = KMMemberInfo.defaultManager.access_token
|
|
|
+ if token == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let urlString = configuration.activityBaseURL() + "/member-system-sso//user/rightList"
|
|
|
+ KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
|
|
|
+ requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
|
|
|
+ } completion: { [weak self] (task, responseObject, error) in
|
|
|
+ var dic: NSDictionary = [:]
|
|
|
+ if error == nil, let responseObject = responseObject as? NSDictionary {
|
|
|
+ dic = responseObject
|
|
|
+ } else {
|
|
|
+ var info = responseObject
|
|
|
+ if let error = error {
|
|
|
+ if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
|
|
|
+ info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dic = (info as? NSDictionary) ?? [:]
|
|
|
+ }
|
|
|
+ let code: Int = dic["code"] as? Int ?? 0
|
|
|
+ let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
|
|
|
+ let message: String = dic["msg"] as? String ?? ""
|
|
|
+
|
|
|
+ var results: [KMMemberUserInfoActiveVIP] = []
|
|
|
+ for dict1 in result_Array {
|
|
|
+ var activeVIP_id = ""
|
|
|
+ var activeVIP_userId = ""
|
|
|
+ var activeVIP_status = 0
|
|
|
+ var activeVIP_endDate = ""
|
|
|
+ var activeVIP_payType = 0
|
|
|
+ var activeVIP_productName = ""
|
|
|
+ var activeVIP_levels = ""
|
|
|
+ var activeVIP_platforms = ""
|
|
|
+ var activeVIP_point = 0
|
|
|
+ var activeVIP_maxDeviceNum = 0
|
|
|
+ var activeVIP_paymentModel = ""
|
|
|
+ var activeVIP_isAi = ""
|
|
|
+ if let token = dict1["id"] { activeVIP_id = token as! String }
|
|
|
+ if let token = dict1["userId"] { activeVIP_userId = token as! String }
|
|
|
+ if let token = dict1["status"] { activeVIP_status = token as! Int }
|
|
|
+ if let token = dict1["endDate"] { activeVIP_endDate = token as! String }
|
|
|
+ if let token = dict1["payType"] { activeVIP_payType = token as! Int }
|
|
|
+ if let token = dict1["productName"] { activeVIP_productName = token as! String }
|
|
|
+ if let token = dict1["levels"] { activeVIP_levels = token as! String }
|
|
|
+ if let token = dict1["platforms"] { activeVIP_platforms = token as! String }
|
|
|
+ if let token = dict1["point"] { activeVIP_point = token as! Int }
|
|
|
+ if let token = dict1["maxDeviceNum"] { activeVIP_maxDeviceNum = token as! Int }
|
|
|
+ if let token = dict1["paymentModel"] { activeVIP_paymentModel = token as! String }
|
|
|
+ if let token = dict1["isAi"] { activeVIP_isAi = token as! String }
|
|
|
+ let userInfoActiveVIP = KMMemberUserInfoActiveVIP(id: activeVIP_id, userId: activeVIP_userId, status: activeVIP_status, endDate: activeVIP_endDate, payType: activeVIP_payType, productName: activeVIP_productName, levels: activeVIP_levels, platforms: activeVIP_platforms, point: activeVIP_point, maxDeviceNum: activeVIP_maxDeviceNum, paymentModel: activeVIP_paymentModel, isAi: activeVIP_isAi)
|
|
|
+ results.append(userInfoActiveVIP)
|
|
|
+ }
|
|
|
+
|
|
|
+ let result = KMMemberCenterResult(code: code, msg: message, activeVIPs: results)
|
|
|
+ if code == 200 {
|
|
|
+ complete(true, result)
|
|
|
+ } else {
|
|
|
+ complete(false, result)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ @abstract 用户手动注销
|
|
|
+ @param code 邮箱验证码
|
|
|
+ @param complete 回调
|
|
|
+ */
|
|
|
+ func userLogOffForUser(code: String, complete: @escaping KMMemberCenterComplete) {
|
|
|
+ let token: String = KMMemberInfo.defaultManager.access_token
|
|
|
+ if token == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let urlString = configuration.activityBaseURL() + "/member-system-sso/user/logOffForUser"
|
|
|
+ let params: [String: Any] = ["code": code,
|
|
|
+ "appId": "1"]
|
|
|
+ KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
|
|
|
+ requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
|
|
|
+ } completion: { [weak self] (task, responseObject, error) in
|
|
|
+ var dic: NSDictionary = [:]
|
|
|
+ if error == nil, let responseObject = responseObject as? NSDictionary {
|
|
|
+ dic = responseObject
|
|
|
+ } else {
|
|
|
+ var info = responseObject
|
|
|
+ if let error = error {
|
|
|
+ if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
|
|
|
+ info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dic = (info as? NSDictionary) ?? [:]
|
|
|
+ }
|
|
|
+ let code: Int = dic["code"] as? Int ?? 0
|
|
|
+ let message: String = dic["msg"] as? String ?? ""
|
|
|
+ let result_dict: NSDictionary = dic["result"] as? NSDictionary ?? [:]
|
|
|
+
|
|
|
+ var currentTime = ""
|
|
|
+ var logOffTime = ""
|
|
|
+ if let token = result_dict["currentTime"] { currentTime = token as! String }
|
|
|
+ if let token = result_dict["logOffTime"] { logOffTime = token as! String }
|
|
|
+ let logOff = KMMemberLogOff(currentTime: currentTime, logOffTime: logOffTime)
|
|
|
+
|
|
|
+ let result = KMMemberCenterResult(code: code, msg: message, logOff: logOff)
|
|
|
+ if code == 200 {
|
|
|
+ complete(true, result)
|
|
|
+ } else {
|
|
|
+ complete(false, result)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ @abstract 撤销注销申请
|
|
|
+ @param complete 回调
|
|
|
+ */
|
|
|
+ func userRevokeCancel(_ complete: @escaping KMMemberCenterComplete) {
|
|
|
+ let token: String = KMMemberInfo.defaultManager.access_token
|
|
|
+ if token == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let urlString = configuration.activityBaseURL() + "/member-system-sso/user/revokeCancel"
|
|
|
+ KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
|
|
|
+ requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
|
|
|
+ } completion: { [weak self] (task, responseObject, error) in
|
|
|
+ var dic: NSDictionary = [:]
|
|
|
+ if error == nil, let responseObject = responseObject as? NSDictionary {
|
|
|
+ dic = responseObject
|
|
|
+ } else {
|
|
|
+ var info = responseObject
|
|
|
+ if let error = error {
|
|
|
+ if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
|
|
|
+ info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dic = (info as? NSDictionary) ?? [:]
|
|
|
+ }
|
|
|
+ let code: Int = dic["code"] as? Int ?? 0
|
|
|
+ let message: String = dic["msg"] as? String ?? ""
|
|
|
+ let result_Bool: Bool = dic["result"] as? Bool ?? false
|
|
|
+
|
|
|
+ let result = KMMemberCenterResult(code: code, msg: message, result: result_Bool)
|
|
|
+ if code == 200 {
|
|
|
+ complete(true, result)
|
|
|
+ } else {
|
|
|
+ complete(false, result)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// MARK: 商品模块
|
|
|
|