123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849 |
- //
- // KMMemberCenterManager.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2024/10/21.
- //
- import Cocoa
- enum KMMemberCenterErrorCodeType: Int, CaseIterable {
- case UNKNOWN = 0 //未知
- case SUCCESS = 200 //正确
- case EXCEPTION_MSG_TOKEN_IS_INVALID = 304 // 无效的token或者token已过期
- case EXCEPTION_MSG_DEVICE_NUM_MAX = 305 // 您的登录设备已达上限,请退出其他设备重新登录
- case EXCEPTION_MSG_USER_NOT_LOGIN = 306 // 用户没有登录,请登录后再访问
- case EMAIL_VERIFY_CODE_KEY_ERROR = 309 // email code error!
- case EMAIL_REGISTER_ERROR = 310 // Register error!
- case EXCEPTION_MSG_PASSWORD_ERROR = 311 // 密码错误,您可以检查大小写状态
- case EXCEPTION_MSG_CODE_ACTION_ERROR = 312 // code action error
- case EXCEPTION_MSG_CODE_SEND_ERROR = 313 // code send error
- case EXCEPTION_MAIL_CODE_SEND_ERROR = 314 // mail send error
- case VERIFY_CODE_SEND_TOO_QUICKLY = 315 // code send too quickly
- case EXCEPTION_MSG_EMAIL_EXIST = 316 // 该邮箱已有账号,请前往登录
- case EXCEPTION_MSG_EMAIL_NOT_REGISTER = 317 // 当前账号未注册,点击下一步我们将为您注册账号
- case EXCEPTION_MSG_EMAIL_LOGOUT_ING = 318 // 注销中,无法登录,若有问题可联系客服
- case EXCEPTION_MSG_EMAIL_INVALID = 319 // 请输入正确的邮箱格式
- case EXCEPTION_MSG_PASSWORD_NOT_INCONSISTENT = 320 // 密码不一致,请重新输入
- case EXCEPTION_MSG_PASSWORD_SIZE_MIN = 321 // 密码请包含6~24个字符
- case EXCEPTION_MSG_PASSWORD_SIZE_MAX = 322 // 密码请包含6~24个字符
- case EXCEPTION_MSG_PLEASE_ADD_AUTH_CONFIG = 323 // please add auth config
- case EXCEPTION_MSG_USER_SUBSCRIPTION_IN_PROGRESS = 324 // 您目前还在订阅期内,暂时无法注销,请订阅期结束后再点击注销账号
- case EXCEPTION_TIME_TRANSFER_ERROR = 326 // 时间转换失败
- case EXCEPTION_MSG_PASSWORD_CONTAIN_EMPTY = 327 // 密码不能包含空格
- }
- @objc enum KMVerificationCodeType : Int {
- case login = 0 // 登录验证码
- case reset // 重置密码验证码
- case logout // 注销验证码
- }
- @objc enum KMBuyPlatformType : Int {
- case web = 0 // 官网
- case dmg // 重置密码验证码
- case macLite // Mac store免费版
- case exe
- case macPro // Mac store付费版
- case iOSLite // iOS免费版
- case iOSPro // iOS付费版
- case Android
- }
- typealias KMMemberCenterComplete = (_ success: Bool, _ result: KMMemberCenterResult?) -> Void
- class KMMemberCenterManager: NSObject {
- static let manager = KMMemberCenterManager()
- private let configuration: KMMemberCenterConfig = KMMemberCenterConfig()
-
- // MARK: 登录模块
-
- /**
- @abstract 新会员系统重置密码
- @param email 邮箱
- @param verifyCode 验证码
- @param password 密码
- @param complete 回调
- */
- func resetPassword(email: String, verifyCode: String, password: String, _ complete: @escaping KMMemberCenterComplete) {
- let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/memberResetPassword"
- let params: [String: Any] = ["email": email,
- "verifyCode": verifyCode,
- "appId": "1",
- "password": password]
- KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
-
- } 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)
- // let error = NSError(domain: message, code: code)
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- }
-
- /**
- @abstract 验证邮箱(重置密码输入邮箱点击下一步时校验邮箱是否注册)
- @param email 邮箱
- @param complete 回调
- */
- func emailVerification(email: String, _ complete: @escaping KMMemberCenterComplete) {
- let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/validEmail"
- let params: [String: Any] = ["email": email]
- KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
-
- } 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)
- // let error = NSError(domain: message, code: code)
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- }
-
- /**
- @abstract 获取邮箱验证码
- @param action 验证码用途
- @param receiver 邮箱号
- @param complete 回调
- */
- func getVerificationCode(action: KMVerificationCodeType, receiver: String, _ complete: @escaping KMMemberCenterComplete) {
- let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/getVerifyCode"
- var actionType = "member_login"
- if action == .reset {
- actionType = "member_reset_password"
- } else if action == .logout {
- actionType = "user_log_off"
- }
- let params: [String: Any] = ["action": actionType,
- "type": 0,
- "receiver": receiver,
- "appId": "1"]
- KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
-
- } 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)
- // let error = NSError(domain: message, code: code)
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- }
-
- /**
- @abstract 实时检查邮件验证码
- @param type 验证码用途
- @param account 账户
- @param code 验证码
- @param complete 回调
- */
- func checkVerificationCode(type: KMVerificationCodeType, account: String, code: String, _ complete: @escaping KMMemberCenterComplete) {
- let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/isEmailCodeValid"
- var actionType = "member_login"
- if type == .reset {
- actionType = "member_reset_password"
- } else if type == .logout {
- actionType = "user_log_off"
- }
- let params: [String: Any] = ["type": actionType,
- "account": account,
- "code": code,
- "appId": "1"]
- KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
-
- } 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)
- // let error = NSError(domain: message, code: code)
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- }
- /**
- @abstract 邮箱验证码登录 & 密码登录
- @param email 邮箱
- @param code 验证码/密码
- @param complete 回调
- */
- func emailLogin(email: String, code: String, _ complete: @escaping KMMemberCenterComplete) {
- let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/memberLogin"
- let uuid: String = GetHardwareUUID() ?? ""
- let params: [String: Any] = ["email": email,
- "code": code,
- "appId": "1",
- "deviceSign": uuid,
- "deviceName": NSFullUserName(),
- "model": "mac"]
- KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
- // requestSerializer.setValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
- } 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 refresh_token = ""
- var access_token = ""
- 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 }
- let loginResult = KMMemberLoginResult(refreshToken: refresh_token, accessToken: access_token, tokenType: token_type, expiresIn: expires_in)
-
- let result = KMMemberCenterResult(loginResult: loginResult)
- result.code = code
- result.msg = message
- // let error = NSError(domain: message, code: code)
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- }
-
- /**
- @abstract 获取用户登录设备列表
- @param email 邮箱
- @param complete 回调
- */
- func getUserDeviceList(email: String, _ complete: @escaping KMMemberCenterComplete) {
- let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/getLoginDeviceList"
- let params: [String: Any] = ["email": email,
- "appId": "1"]
- KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
-
- } 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: Dictionary = dic["result"] as? Dictionary ?? [:]
- let message: String = dic["msg"] as? String ?? ""
-
- let deviceList: [Dictionary] = result_dict["deviceList"] as? [Dictionary] ?? [[:]]
- var deviceLists: [KMMemberDeviceList] = []
-
- for dict in deviceList {
- var device_id = ""
- 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 }
- let list = KMMemberDeviceList(deviceId: device_id, productId: productId, uniqueSn: uniqueSn, appId: deviceName)
- deviceLists.append(list)
- }
- var maxDeviceNum = 0
- if let token = result_dict["maxDeviceNum"] {
- maxDeviceNum = token as! Int
- }
- let result = KMMemberCenterResult(deviceListResult: deviceLists, maxDeviceNum: maxDeviceNum)
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- }
-
- /**
- @abstract 登出用户的指定设备
- @param deviceId 设备记录ID
- @param complete 回调
- */
- func logoutDevice(deviceId: String, complete: @escaping KMMemberCenterComplete) {
- let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/logoutDevice"
- let params: [String: Any] = ["deviceId": deviceId]
- KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
-
- } 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 resultStr: String = dic["result"] as? String ?? ""
- let message: String = dic["msg"] as? String ?? ""
-
- let result = KMMemberCenterResult(code: code, msg: message, resultStr: resultStr)
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- }
-
- // MARK: 个人信息模块
-
- /**
- @abstract 获取老带新已邀请人数
- @param complete 回调
- */
- func getInviteNum(_ complete: @escaping KMMemberCenterComplete) {
- let token: String = KMMemberInfo.shared.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.shared.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 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["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, 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.shared.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.shared.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.shared.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.shared.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: 商品模块
-
- // /**
- // @abstract 获取上架中的产品
- // @param complete 回调
- // */
- // func getListingProducts(_ complete: @escaping KMMemberCenterComplete) {
- //
- // let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getListingProducts"
- // let params: [String: Any] = ["isEducation": actionType,
- // "platformId": 0]
- // KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
- //
- // } 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: 个人中心模块
-
- // MARK: 订单模块
- // MARK: 评估模块
- // MARK: 活动模块
- // MARK: 翻译模块
-
- // MARK: AI模块
- // MARK: 会员赠送模块
-
- // MARK: Error Code
-
- static func typeOfMessage(type: KMMemberCenterErrorCodeType?) -> String {
- var result: String = ""
- switch type {
- case .EXCEPTION_MSG_TOKEN_IS_INVALID:
- result = "无效的token或者token已过期"
- break;
- case .EXCEPTION_MSG_DEVICE_NUM_MAX:
- result = "您的登录设备已达上限,请退出其他设备重新登录"
- break;
- case .EXCEPTION_MSG_USER_NOT_LOGIN:
- result = "用户没有登录,请登录后再访问"
- break;
- case .EMAIL_VERIFY_CODE_KEY_ERROR:
- result = "email code error!"
- break;
- case .EMAIL_REGISTER_ERROR:
- result = "Register error!"
- break;
- case .EXCEPTION_MSG_PASSWORD_ERROR:
- result = "密码错误,您可以检查大小写状态"
- break;
- case .EXCEPTION_MSG_CODE_ACTION_ERROR:
- result = "code action error"
- break;
- case .EXCEPTION_MSG_CODE_SEND_ERROR:
- result = "code send error"
- break;
- case .EXCEPTION_MAIL_CODE_SEND_ERROR:
- result = "mail send error"
- break;
- case .VERIFY_CODE_SEND_TOO_QUICKLY:
- result = "code send too quickly"
- break;
- case .EXCEPTION_MSG_EMAIL_EXIST:
- result = "该邮箱已有账号,请前往登录"
- break;
- case .EXCEPTION_MSG_EMAIL_NOT_REGISTER:
- result = "当前账号未注册,点击下一步我们将为您注册账号"
- break;
- case .EXCEPTION_MSG_EMAIL_LOGOUT_ING:
- result = "注销中,无法登录,若有问题可联系客服"
- break;
- case .EXCEPTION_MSG_EMAIL_INVALID:
- result = "请输入正确的邮箱格式"
- break;
- case .EXCEPTION_MSG_PASSWORD_NOT_INCONSISTENT:
- result = "密码不一致,请重新输入"
- break;
- case .EXCEPTION_MSG_PASSWORD_SIZE_MIN:
- result = "密码请包含6~24个字符"
- break;
- case .EXCEPTION_MSG_PASSWORD_SIZE_MAX:
- result = "密码请包含6~24个字符"
- break;
- case .EXCEPTION_MSG_PLEASE_ADD_AUTH_CONFIG:
- result = "please add auth config"
- break;
- case .EXCEPTION_MSG_USER_SUBSCRIPTION_IN_PROGRESS:
- result = "您目前还在订阅期内,暂时无法注销,请订阅期结束后再点击注销账号"
- break;
- case .EXCEPTION_TIME_TRANSFER_ERROR:
- result = "时间转换失败"
- break;
- case .EXCEPTION_MSG_PASSWORD_CONTAIN_EMPTY:
- result = "密码不能包含空格"
- break;
- case .UNKNOWN:
- result = "UNKNOWN"
- break;
- case .SUCCESS:
- result = "SUCCESS"
- break;
- default:
- result = "Network error"
- }
- return result
- }
- }
|