1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531 |
- //
- // 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
- typealias KMMemberProductComplete = (_ success: Bool, _ result: KMMemberProductResult?) -> Void
- typealias KMMemberRequestInfoComplete = (_ success: Bool, _ info: NSDictionary?) -> Void
- class KMMemberCenterManager: NSObject {
- static let manager = KMMemberCenterManager()
- private let configuration: KMMemberCenterConfig = KMMemberCenterConfig()
-
- // MARK: 判断有无网络
- func isConnectionAvailable() -> Bool {
- let reachability = Reachability(hostname: "www.apple.com")
- let state = reachability?.currentReachabilityStatus()
- if(state == NotReachable) {
- return false
- }
- return true
- }
-
- // 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"
- // var escapedString = q
- // escapedString = String(data: escapedString.data(using: .utf8)!, encoding: .utf8)!
- let paraDict: [String: Any] = ["email": email,
- "verifyCode": verifyCode,
- "appId": "1",
- "password": password]
- let postData = try! JSONSerialization.data(withJSONObject: paraDict)
- var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
- request.addValue("application/json", forHTTPHeaderField: "Content-Type")
- request.httpMethod = "POST"
- request.httpBody = postData
- let task = URLSession.shared.dataTask(with: request) { data, response, error in
- guard let data = data else {
- print(String(describing: error))
- return
- }
- let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:]
- if jsonObject != nil {
- let code: Int = jsonObject!["code"] as? Int ?? 0
- let result_bool: Bool = jsonObject!["result"] as? Bool ?? false
- let message: String = jsonObject!["msg"] as? String ?? ""
- let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- } else {
- complete(false, KMMemberCenterResult(code: 0, msg: "unknown error", result: false))
- }
- }
- task.resume()
-
- // 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 = String(format: "%@/member-system-sso/auth/validEmail?email=%@", configuration.activityBaseURL(), email)
- KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
-
- } completion: { (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 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 = "member_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: { (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 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: .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)
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- }
- /**
- @abstract 邮箱验证码登录 & 密码登录
- @param email 邮箱
- @param code 验证码/密码
- @param type 密码类型(验证码?密码?)
- @param complete 回调
- */
- func emailLogin(email: String, code: String, type: KMSignUpState, _ complete: @escaping KMMemberCenterComplete) {
- let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/memberLogin"
- let uuid: String = GetHardwareUUID() ?? ""
- var params: [String: Any] = [:]
- if type == .verificationCode {
- params = ["email": email,
- "code": code,
- "appId": "1",
- "deviceSign": uuid,
- "deviceName": NSFullUserName(),
- "model": "mac"]
- } else {
- params = ["email": email,
- "password": 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?email=\(email)&appId=1"
- KMRequestServer.requestServer.request(urlString: urlString, method: .post, 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 = ""
- var id = ""
- 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["id"] {
- id = token as? String ?? ""
- }
-
- let list = KMMemberDeviceList(deviceId: device_id, productId: productId, uniqueSn: uniqueSn, appId: "", deviceName: deviceName)
- list.id = id
- 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?deviceId=\(deviceId)"
- KMRequestServer.requestServer.request(urlString: urlString, method: .post, 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 == "" {
- complete(false, nil)
- 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 == "" {
- complete(false, nil)
- 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 = ""
- var activeVIP_cycle = 0
- if let token = activeVIP_dict["id"] as? String { activeVIP_id = token }
- if let token = activeVIP_dict["userId"] as? String { activeVIP_userId = token }
- if let token = activeVIP_dict["status"] as? Int { activeVIP_status = token }
- if let token = activeVIP_dict["endDate"] as? String { activeVIP_endDate = token }
- if let token = activeVIP_dict["payType"] as? Int { activeVIP_payType = token }
- if let token = activeVIP_dict["productName"] as? String { activeVIP_productName = token }
- if let token = activeVIP_dict["levels"] as? String { activeVIP_levels = token }
- if let token = activeVIP_dict["platforms"] as? String { activeVIP_platforms = token }
- if let token = activeVIP_dict["point"] as? Int { activeVIP_point = token }
- if let token = activeVIP_dict["maxDeviceNum"] as? Int { activeVIP_maxDeviceNum = token }
- if let token = activeVIP_dict["paymentModel"] as? String { activeVIP_paymentModel = token }
- if let token = activeVIP_dict["isAi"] as? String { activeVIP_isAi = token }
- if let token = activeVIP_dict["cycle"] as? Int { activeVIP_cycle = token }
- 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, cycle: activeVIP_cycle)
- let activeAI_dict: NSDictionary = result_dict["activeAI"] as? NSDictionary ?? [:]
- var activeAI_id = ""
- var activeAI_userId = ""
- var activeAI_status = 0
- var activeAI_endDate = ""
- var activeAI_payType = 0
- var activeAI_productName = ""
- var activeAI_levels = ""
- var activeAI_platforms = ""
- var activeAI_point = 0
- var activeAI_maxDeviceNum = 0
- var activeAI_paymentModel = ""
- var activeAI_isAi = ""
- var activeAI_cycle = 0
- if let token = activeAI_dict["id"] as? String { activeAI_id = token }
- if let token = activeAI_dict["userId"] as? String { activeAI_userId = token }
- if let token = activeAI_dict["status"] as? Int { activeAI_status = token }
- if let token = activeAI_dict["endDate"] as? String { activeAI_endDate = token }
- if let token = activeAI_dict["payType"] as? Int { activeAI_payType = token }
- if let token = activeAI_dict["productName"] as? String { activeAI_productName = token }
- if let token = activeAI_dict["levels"] as? String { activeAI_levels = token }
- if let token = activeAI_dict["platforms"] as? String { activeAI_platforms = token }
- if let token = activeAI_dict["point"] as? Int { activeAI_point = token }
- if let token = activeAI_dict["maxDeviceNum"] as? Int { activeAI_maxDeviceNum = token }
- if let token = activeAI_dict["paymentModel"] as? String { activeAI_paymentModel = token }
- if let token = activeAI_dict["isAi"] as? String { activeAI_isAi = token }
- if let token = activeAI_dict["cycle"] as? Int { activeAI_cycle = token }
- let userInfoActiveAI = KMMemberUserInfoActiveVIP(id: activeAI_id, userId: activeAI_userId, status: activeAI_status, endDate: activeAI_endDate, payType: activeAI_payType, productName: activeAI_productName, levels: activeAI_levels, platforms: activeAI_platforms, point: activeAI_point, maxDeviceNum: activeAI_maxDeviceNum, paymentModel: activeAI_paymentModel, isAi: activeAI_isAi, cycle: activeAI_cycle)
- 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], activeAI: [userInfoActiveAI], aiPoint: aiPoint, validFlag: validFlag, isHaveAIDiscount: isHaveAIDiscount, canTrail: canTrail)
-
- let result = KMMemberCenterResult(code: code, msg: message, userInfo: userInfo)
- 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 == "" {
- complete(false, nil)
- return
- }
- let uuid: String = GetHardwareUUID() ?? ""
- let urlString = String(format: "%@/member-system-sso/user/logout?deviceSign=%@&appId=1", configuration.activityBaseURL(),uuid)
- 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 == "" {
- complete(false, nil)
- 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 == "" {
- complete(false, nil)
- return
- }
-
- let urlString = String(format: "%@/member-system-sso/user/logOffForUser?code=%@&appId=1", configuration.activityBaseURL(), code)
- 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_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 == "" {
- complete(false, nil)
- 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 isEducation 是否教育优惠
- @param complete 回调
- */
- func getListingProducts(isEducation: Int, _ complete: @escaping KMMemberProductComplete) {
-
- let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getListingProducts"
- var platformId = "2"
- #if VERSION_FREE
-
- #if VERSION_DMG
- // DMG
- platformId = "1"
- #else
- // AppStore 免费版本
- #endif
- #else
- // AppStore 付费版
- platformId = "5"
- #endif
- let params: [String: Any] = ["isEducation": isEducation,
- "platformId": platformId]
- 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_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
- let message: String = dic["msg"] as? String ?? ""
-
- var results: [KMListingProductsModel] = []
- for dict1 in result_Array {
- var id = ""
- var productName = ""
- var price = NSNumber(value: 0.0)
- var maxDeviceNum = 0
- var levels = ""
- var platforms = ""
- var productLineId = 0
- var paymentModel = 0
- var cycle = 0
- var code = ""
- var cnyPrice = NSNumber(value: 0.0)
-
- if let token = dict1["id"] { id = token as? String ?? id }
- if let token = dict1["productName"] { productName = token as? String ?? productName }
- if let token = dict1["price"] { price = token as? NSNumber ?? price }
- if let token = dict1["maxDeviceNum"] { maxDeviceNum = token as? Int ?? maxDeviceNum }
- if let token = dict1["levels"] { levels = token as? String ?? levels }
- if let token = dict1["platforms"] { platforms = token as? String ?? platforms }
- if let token = dict1["productLineId"] { productLineId = token as? Int ?? productLineId }
- if let token = dict1["paymentModel"] { paymentModel = token as? Int ?? paymentModel }
- if let token = dict1["cycle"] { cycle = token as? Int ?? cycle }
- if let token = dict1["code"] { code = token as? String ?? code }
- if let token = dict1["cnyPrice"] { cnyPrice = token as? NSNumber ?? cnyPrice }
- let products = KMListingProductsModel(id: id, productName: productName, price: price, maxDeviceNum: maxDeviceNum, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, code: code, cnyPrice: cnyPrice)
- results.append(products)
- }
- let result = KMMemberProductResult(code: code, msg: message, listingProducts: results)
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- }
-
- /**
- @abstract 获取已登录用户购买商品价格
- @param productId 购买的产品id
- @param isEducation 是否教育优惠
- @param complete 回调
- */
- func getProductPriceForBuy(productId: String, isEducation: Int, userId: String, _ complete: @escaping KMMemberProductComplete) {
-
- let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getProductPriceForBuy"
- let params: [String: Any] = ["productId": productId,
- "isEducation": isEducation,
- "userId": userId]
- 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_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
- let message: String = dic["msg"] as? String ?? ""
-
- var results: [KMListingProductsModel] = []
- for dict1 in result_Array {
- var id = ""
- var productName = ""
- var price = NSNumber(value: 0.0)
- var maxDeviceNum = 0
- var levels = ""
- var platforms = ""
- var productLineId = 0
- var paymentModel = 0
- var cycle = 0
- var code = ""
- var cnyPrice = NSNumber(value: 0.0)
- if let token = dict1["id"] { id = token as! String }
- if let token = dict1["productName"] { productName = token as! String }
- if let token = dict1["price"] { price = token as! NSNumber }
- if let token = dict1["maxDeviceNum"] { maxDeviceNum = token as! Int }
- if let token = dict1["levels"] { levels = token as! String }
- if let token = dict1["platforms"] { platforms = token as! String }
- if let token = dict1["productLineId"] { productLineId = token as! Int }
- if let token = dict1["paymentModel"] { paymentModel = token as! Int }
- if let token = dict1["cycle"] { cycle = token as! Int }
- if let token = dict1["code"] { code = token as! String }
- if let token = dict1["cnyPrice"] { cnyPrice = token as! NSNumber }
- let products = KMListingProductsModel(id: id, productName: productName, price: price, maxDeviceNum: maxDeviceNum, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, code: code, cnyPrice: cnyPrice)
- results.append(products)
- }
- let result = KMMemberProductResult(code: code, msg: message, listingProducts: results)
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- }
-
- /**
- @abstract 获取批量阶段购买价格
- @param productId 购买的产品id
- @param num 批量个数
- @param complete 回调
- */
- func getBatchProductPrice(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
-
- let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getBatchProductPrice"
- let params: [String: Any] = ["productId": productId,
- "num": num]
- 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: NSDictionary = dic["result"] as? NSDictionary ?? [:]
- let message: String = dic["msg"] as? String ?? ""
-
- var productId = ""
- var totalPrice = ""
- var price = ""
- var batchPrice = ""
- var cnyPrice = ""
- var cnyBatchPrice = ""
- var cnyTotalPrice = ""
- if let token = result["productId"] { productId = token as! String }
- if let token = result["totalPrice"] { totalPrice = token as! String }
- if let token = result["price"] { price = token as! String }
- if let token = result["batchPrice"] { batchPrice = token as! String }
- if let token = result["cnyPrice"] { cnyPrice = token as! String }
- if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as! String }
- if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as! String }
- let products = KMBatchProductPriceModel(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
- let result1 = KMMemberProductResult(code: code, msg: message, batchProductPrice: products)
- if code == 200 {
- complete(true, result1)
- } else {
- complete(false, result1)
- }
- }
- }
-
- /**
- @abstract 验证商品优惠券,返回商品优惠后价格
- @param productId 购买的产品id
- @param userId 用户ID
- @param code 优惠券
- @param complete 回调
- */
- func checkCoupon(productId: String, userId: String, code: String, _ complete: @escaping KMMemberProductComplete) {
- let token: String = KMMemberInfo.shared.access_token
- if token == "" {
- complete(false, nil)
- return
- }
- let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkCoupon"
- let params: [String: Any] = ["productId": productId,
- "userId": userId,
- "code": code]
- KMRequestServer.requestServer.request(urlString: urlString, method: .get, 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 result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
- let message: String = dic["msg"] as? String ?? ""
-
- var id = ""
- var productName = ""
- var price = ""
- var maxDeviceNum = 0
- var displayPrice = ""
- var levels = ""
- var platforms = ""
- var productLineId = 0
- var paymentModel = 0
- var cycle = 0
- var cnyPrice = ""
- var displayCnyPrice = ""
- if let token = result["id"] { id = token as! String }
- if let token = result["productName"] { productName = token as! String }
- if let token = result["price"] { price = token as! String }
- if let token = result["maxDeviceNum"] { maxDeviceNum = token as! Int }
- if let token = result["displayPrice"] { displayPrice = token as! String }
- if let token = result["levels"] { levels = token as! String }
- if let token = result["platforms"] { platforms = token as! String }
- if let token = result["productLineId"] { productLineId = token as! Int }
- if let token = result["paymentModel"] { paymentModel = token as! Int }
- if let token = result["cycle"] { cycle = token as! Int }
- if let token = result["cnyPrice"] { cnyPrice = token as! String }
- if let token = result["displayCnyPrice"] { displayCnyPrice = token as! String }
- let products = KMCheckCouponModel(id: id, productName: productName, price: price, maxDeviceNum: maxDeviceNum, displayPrice: displayPrice, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, cnyPrice: cnyPrice, displayCnyPrice: displayCnyPrice)
- let result1 = KMMemberProductResult(code: code, msg: message, checkCoupon: products)
- if code == 200 {
- complete(true, result1)
- } else {
- complete(false, result1)
- }
- }
- }
-
- /**
- @abstract 获取批量阶段购买价格
- @param productId 购买的产品id
- @param isEducation 是否教育优惠
- @param complete 回调
- */
- func checkEducation(email: String, _ complete: @escaping KMMemberProductComplete) {
-
- let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkEducation"
- let params: [String: Any] = ["email": email]
- 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: NSDictionary = dic["result"] as? NSDictionary ?? [:]
- let message: String = dic["msg"] as? String ?? ""
-
- var productId = ""
- var totalPrice = ""
- var price = ""
- var batchPrice = ""
- var cnyPrice = ""
- var cnyBatchPrice = ""
- var cnyTotalPrice = ""
- if let token = result["productId"] { productId = token as! String }
- if let token = result["totalPrice"] { totalPrice = token as! String }
- if let token = result["price"] { price = token as! String }
- if let token = result["batchPrice"] { batchPrice = token as! String }
- if let token = result["cnyPrice"] { cnyPrice = token as! String }
- if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as! String }
- if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as! String }
- let products = KMBatchProductPriceModel(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
- let result1 = KMMemberProductResult(code: code, msg: message, batchProductPrice: products)
- if code == 200 {
- complete(true, result1)
- } else {
- complete(false, result1)
- }
- }
- }
-
- // MARK: 个人中心模块
-
- // MARK: 订单模块
-
- /**
- @abstract 支付后查询订单状态
- @param orderId 订单id
- @param complete 回调
- */
- func getStateByOrderId(orderId: String, _ complete: @escaping KMMemberRequestInfoComplete) {
- let token: String = KMMemberInfo.shared.access_token
- if token == "" {
- complete(false, nil)
- return
- }
- let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getStateByOrderId"
- 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
- if code == 200 {
- complete(true, dic)
- } else {
- complete(false, dic)
- }
- }
- }
-
- /**
- @abstract 创建订单(买断)
- @param productId 产品id
- @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
- @param price 价格
- @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
- @param couponCode 优惠卷
- @param num 批量购买数量
- @param complete 回调
- */
- func createOrder(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
- let token: String = KMMemberInfo.shared.access_token
- if token == "" {
- complete(false, nil)
- return
- }
- let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/createOrder"
- let params: [String: Any] = ["productId": productId,
- "paymentMethod": paymentMethod,
- "price": price,
- "discountFlag": discountFlag,
- "couponCode": couponCode,
- "num": num]
- 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 result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
- let message: String = dic["msg"] as? String ?? ""
-
- var thirdOrderNo = ""
- var orderId = ""
- var payHref = ""
- if code == 200 {
- if let token = result["thirdOrderNo"] { thirdOrderNo = token as! String }
- if let token = result["orderId"] { orderId = token as! String }
- if let token = result["payHref"] { payHref = token as! String }
- let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
- let result1 = KMMemberProductResult(code: code, msg: message, createOrder: products)
- complete(true, result1)
- } else {
- let result1 = KMMemberProductResult(code: code, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
- complete(false, result1)
- }
- }
- }
-
- /**
- @abstract 创建订单(订阅)
- @param productId 产品id
- @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
- @param price 价格
- @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
- @param couponCode 优惠卷
- @param num 批量购买数量
- @param complete 回调
- */
- func createSubscriber(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
- let token: String = KMMemberInfo.shared.access_token
- if token == "" {
- complete(false, nil)
- return
- }
- let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/createOrder"
- let params: [String: Any] = ["productId": productId,
- "paymentMethod": paymentMethod,
- "price": price,
- "discountFlag": discountFlag,
- "couponCode": couponCode,
- "num": num]
- 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 result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
- let message: String = dic["msg"] as? String ?? ""
-
- var thirdOrderNo = ""
- var orderId = ""
- var payHref = ""
- if code == 200 {
- if let token = result["thirdOrderNo"] { thirdOrderNo = token as! String }
- if let token = result["orderId"] { orderId = token as! String }
- if let token = result["payHref"] { payHref = token as! String }
- let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
- let result1 = KMMemberProductResult(code: code, msg: message, createOrder: products)
- complete(true, result1)
- } else {
- let result1 = KMMemberProductResult(code: code, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
- complete(false, result1)
- }
- }
- }
- /**
- @abstract 获取订单列表
- @param orderStatus 0全部1待支付
- @param complete 回调
- */
- func getOrderListByStatus(orderStatus: Int, _ complete: @escaping KMMemberProductComplete) {
- let token: String = KMMemberInfo.shared.access_token
- if token == "" {
- complete(false, nil)
- return
- }
- let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getOrderListByStatus"
- let params: [String: Any] = ["orderStatus": orderStatus]
- KMRequestServer.requestServer.request(urlString: urlString, method: .get, 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 result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
- let message: String = dic["msg"] as? String ?? ""
-
- // var thirdOrderNo = ""
- // var orderId = ""
- // var payHref = ""
- // if code == 200 {
- // if let token = result["thirdOrderNo"] { thirdOrderNo = token as! String }
- // if let token = result["orderId"] { orderId = token as! String }
- // if let token = result["payHref"] { payHref = token as! String }
- // let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
- // let result1 = KMMemberProductResult(code: code, msg: message, createOrder: products)
- // complete(true, result1)
- // } else {
- // let result1 = KMMemberProductResult(code: code, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
- // complete(false, result1)
- // }
- }
- }
-
- /**
- @abstract 关闭订单
- @param orderId 订单id
- @param complete 回调
- */
- func closeByOrderId(orderId: String, _ complete: @escaping KMMemberRequestInfoComplete) {
- let token: String = KMMemberInfo.shared.access_token
- if token == "" {
- complete(false, nil)
- return
- }
- let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/closeOrder"
- 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
- if code == 200 {
- complete(true, dic)
- } else {
- complete(false, dic)
- }
- }
- }
-
- // MARK: 苹果支付
-
- /**
- @abstract APPstore 权益校验
- @param orderStatus 0全部1待支付
- @param complete 回调
- */
- func appStoreEquityVerification(orderStatus: Int, _ complete: @escaping KMMemberProductComplete) {
- let token: String = KMMemberInfo.shared.access_token
- if token == "" {
- complete(false, nil)
- return
- }
- let urlString = configuration.activityBaseURL() + "/member-system-website/applePay/appStoreEquityVerification"
- let params: [String: Any] = ["userId": "",
- "applePayProductId": "",
- "transactionId": "",
- "productCode": ""]
- KMRequestServer.requestServer.request(urlString: urlString, method: .get, 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 result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
- let message: String = dic["msg"] as? String ?? ""
- let result1 = KMMemberProductResult(code: code, msg: message, result: "")
- if code == 200 {
- complete(true, result1)
- } else {
- complete(false, result1)
- }
- }
- }
- // 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 = NSLocalizedString("Password error.", tableName: "MemberCenterLocalizable", comment: "")
- 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 = NSLocalizedString("This email has not been registered, please log in through the account verification code, we will automatically register an account for you.", tableName: "MemberCenterLocalizable", comment: "")
- break;
- case .EXCEPTION_MSG_EMAIL_LOGOUT_ING:
- result = "注销中,无法登录,若有问题可联系客服"
- break;
- case .EXCEPTION_MSG_EMAIL_INVALID:
- result = NSLocalizedString("Email format error. Please enter the correct email.", tableName: "MemberCenterLocalizable", comment: "")
- 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
- }
- }
|