12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784 |
- //
- // 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 // 密码不能包含空格
-
- case EXCEPTION_MSG_CREATE_ORDER_PARAMETER = 328 // 支付方式异常
-
- case EXCEPTION_MSG_EVENT_IS_CURRENTLY_NOT_SUPPORTED = 329 // 当前事件暂不支持
- case EXCEPTION_MSG_THE_ACCOUNT_IS_ALREADY_LOGGED_IN_ON_OTHER_DEVICES = 330 // 账号已在其他设备登录
- case EXCEPTION_MSG_ABNORMAL_USER_STATUS = 331 // 当前邮箱已被停用或者处于注销中状态
- case EXCEPTION_MSG_APP_STORE_TICKET_VALIDATION_FAILED = 332 // Appstore票据验证失败"
- case EXCEPTION_MSG_APP_STORE_TICKET_VALIDATION_NEED_TO_RETRY = 333 //Appstore票据验证需要重试
- case EXCEPTION_MSG_REPEAT_SUBSCRIPTION = 334 // 用户已订阅该产品
- case EXCEPTION_MSG_RESTORING_PURCHASES_IS_NOT_CURRENTLY_SUPPORTED = 335 // 恢复购买暂不支持
- case EXCEPTION_MSG_USER_TRANSACTION_CANCELED_OR_FAILED = 336 // 用户交易取消或失败
- case EXCEPTION_MSG_CURRENT_ORDER_NOT_RECORDED = 337 // 当前订单末记录,请稍后重试
- case EXCEPTION_MSG_THE_SAME_USER = 338 //同一用户,无需处理
- case EXCEPTION_MSG_THIRD_PAY_ID_ILLEGAL = 339 //thirdPayld非法
- case EXCEPTION_MSG_ORDER_DOES_NOT_EXIST = 340 //订单不存在
-
- case EXCEPTION_MSG_THE_ORDER_STATUS_IS_ABNORMAL = 341 // 订单状态异常
- case EXCEPTION_MSG_TRANSACTION_ID_REPEAT = 342 // transactionld重复
- case EXCEPTION_TICKET_HAS_BEEN_BLOCKED = 343 // The ticket has been blocked
- case EXCEPTION_TICKET_HAS_BEEN_CREATED = 344 // 当前票据已创建订单
- case EXCEPTION_USER_IS_NOT_EDUCATION_USER = 345 // 用户不是教育用户
- case EXCEPTION_USER_HAS_EDUCATION = 346 // 用户近一年有教育购买订单
- case EXCEPTION_USER_CANNOT_BUY_PREMIUM = 347 // 用户已有标准版订阅,无法购买高级版
- case EXCEPTION_USER_CANNOT_BUY_VIP = 348 // 用户已有高级版订阅,无法购买标准版
- case EXCEPTION_USER_CANNOT_UPGRADE_VIP = 349 // 买断用户无法升级为标准版
- case EXCEPTION_COUPON_NOT_EXISTS = 350 // 优惠券不存在
- case EXCEPTION_COUPONTYPE_ERROR = 351 // 优惠券类型错误
- case EXCEPTION_COUPON_PRODUCT_ERROR = 352 // 优惠券关联产品错误
- case EXCEPTION_COUPON_INVALID = 353 // 优惠券已失效
- case EXCEPTION_PRODUCT_NOT_EXIST = 354 // 产品不存在
- case EXCEPTION_MSG_CONTACT_US = 355 //请联系我们获取最新折扣
- case EXCEPTION_MSG_APP_STORE_TRANSACTION_ID_VALIDATION_FAILED = 356 // 验证苹果交易失败
- case EXCEPTION_MSG_GOOGLE_STORE_TRANSACTION_ID_VALIDATION_FAILED = 357 // 验证谷歌交易失败
- case EXCEPTION_PRICE_ERROR = 358 // 价格错误
- case EXCEPTION_MSG_ORDER_CREATE_FAILED = 359 // 订单创建失败
- case USER_ALREADY_SUBSCRIBED_PLAN = 360 // 该用户已经是PDF Reader Pro订阅版会员,确定再赠送吗
- case USER_ALREADY_SUBSCRIBED_PACKAGE = 361 // 该用户已经是PDF Reader Pro永久版会员,无需再赠送哦
- case EXCEPTION_MSG_USER_NOT_EXIST = 400 //用户不存在
- case EXCEPTION_USER_ALREADY_LOTTERY = 364 // 用户已经抽过奖啦
- }
- @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: 拼接URL(为Get类型)
- func constructURLString(baseURLString: String, parameters: [String: Any]) -> String? {
- // Ensure the base URL is valid
- guard var components = URLComponents(string: baseURLString) else {
- return nil
- }
-
- // Convert parameters to query items
- components.queryItems = parameters.map { key, value in
- URLQueryItem(name: key, value: "\(value)")
- }
-
- // Return the complete URL as a string
- return components.url?.absoluteString
- }
-
- // 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 = ""
- var model = ""
- 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["model"] {
- model = token as? String ?? ""
- }
-
- if let token = dict["id"] {
- id = token as? String ?? ""
- }
-
- let list = KMMemberDeviceList(deviceId: device_id, productId: productId, uniqueSn: uniqueSn, appId: "", device_model:model, 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 {
-
- // 创建一个日期格式化器
- let dateFormatter = DateFormatter()
- dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
- // 将字符串转换为日期对象
- if let date = dateFormatter.date(from: token) {
- // 创建一个新的日期格式化器,用于只显示天
- let dayFormatter = DateFormatter()
- dayFormatter.dateFormat = "yyyy-MM-dd" // 只保留年月日部分
-
- activeVIP_endDate = dayFormatter.string(from: date)
- }
- }
- 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)
- if let data = result_dict["avatarUrl"] as? String {
- userInfo.avatarUrl = data
- }
-
- 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 = "2"
- #else
- // AppStore 免费版本
- #endif
- #else
- // AppStore 付费版
- platformId = "5"
- #endif
- let params: [String: Any] = ["isEducation": NSNumber(value: Int32(isEducation)),
- "platformId": platformId]
- if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
- KMRequestServer.requestServer.request(urlString: urlNewString, 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 requestCode: 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 maxDeviceNum = 0
- var levels = ""
- var platforms = ""
- var productLineId = 0
- var paymentModel = 0
- var cycle = 0
- var code = ""
-
- var price = NSNumber(value: 0.0)
- var displayPrice = NSNumber(value: 0.0)
- var upgradePrice = NSNumber(value: 0.0)
- var cnyPrice = NSNumber(value: 0.0)
- var displayCnyPrice = 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["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["price"] { price = token as? NSNumber ?? price }
- if let token = dict1["displayPrice"] { displayPrice = token as? NSNumber ?? displayPrice }
- if let token = dict1["upgradePrice"] { upgradePrice = token as? NSNumber ?? upgradePrice }
- if let token = dict1["cnyPrice"] { cnyPrice = token as? NSNumber ?? cnyPrice }
- if let token = dict1["displayCnyPrice"] { displayCnyPrice = token as? NSNumber ?? displayCnyPrice }
- let products = KMListingProductsModel(id: id, productName: productName, price: price, maxDeviceNum: maxDeviceNum, displayPrice: displayPrice, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, cnyPrice: cnyPrice, displayCnyPrice: displayCnyPrice, upgradePrice: upgradePrice, code: code)
-
- results.append(products)
- }
- let result = KMMemberProductResult(code: requestCode, msg: message, listingProducts: results)
- if requestCode == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- } else {
- print("Invalid URL")
- complete(false, nil)
- }
- }
-
- /**
- @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]
- if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
- KMRequestServer.requestServer.request(urlString: urlNewString, 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 requestCode: 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 maxDeviceNum = 0
- var levels = ""
- var platforms = ""
- var productLineId = 0
- var paymentModel = 0
- var cycle = 0
- var code = ""
-
- var price = NSNumber(value: 0.0)
- var displayPrice = NSNumber(value: 0.0)
- var upgradePrice = NSNumber(value: 0.0)
- var cnyPrice = NSNumber(value: 0.0)
- var displayCnyPrice = 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["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["price"] { price = token as? NSNumber ?? price }
- if let token = dict1["displayPrice"] { displayPrice = token as? NSNumber ?? displayPrice }
- if let token = dict1["upgradePrice"] { upgradePrice = token as? NSNumber ?? upgradePrice }
- if let token = dict1["cnyPrice"] { cnyPrice = token as? NSNumber ?? cnyPrice }
- if let token = dict1["displayCnyPrice"] { displayCnyPrice = token as? NSNumber ?? displayCnyPrice }
- let products = KMListingProductsModel(id: id, productName: productName, price: price, maxDeviceNum: maxDeviceNum, displayPrice: displayPrice, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, cnyPrice: cnyPrice, displayCnyPrice: displayCnyPrice, upgradePrice: upgradePrice, code: code)
- results.append(products)
- }
- let result = KMMemberProductResult(code: requestCode, msg: message, listingProducts: results)
- if requestCode == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- } else {
- print("Invalid URL")
- complete(false, nil)
- }
-
- }
-
- /**
- @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": NSNumber(value: Int32(num))]
- if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
- KMRequestServer.requestServer.request(urlString: urlNewString, 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 requestCode: 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 ?? productId}
- if let token = result["totalPrice"] { totalPrice = token as? String ?? totalPrice}
- if let token = result["price"] { price = token as? String ?? price}
- if let token = result["batchPrice"] { batchPrice = token as? String ?? batchPrice}
- if let token = result["cnyPrice"] { cnyPrice = token as? String ?? cnyPrice}
- if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as? String ?? cnyBatchPrice}
- if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as? String ?? cnyTotalPrice}
- let products = KMBatchProductPriceModel(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
- let result1 = KMMemberProductResult(code: requestCode, msg: message, batchProductPrice: products)
- if requestCode == 200 {
- complete(true, result1)
- } else {
- complete(false, result1)
- }
- }
- } else {
- print("Invalid URL")
- }
- }
-
- /**
- @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]
- if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
- KMRequestServer.requestServer.request(urlString: urlNewString, 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 requestCode: 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 maxDeviceNum = 0
- var levels = ""
- var platforms = ""
- var productLineId = 0
- var paymentModel = 0
- var cycle = 0
- var code = ""
-
- var price = NSNumber(value: 0.0)
- var displayPrice = NSNumber(value: 0.0)
- var upgradePrice = NSNumber(value: 0.0)
- var cnyPrice = NSNumber(value: 0.0)
- var displayCnyPrice = NSNumber(value: 0.0)
-
-
- if let token = dic["id"] { id = token as? String ?? id }
- if let token = dic["productName"] { productName = token as? String ?? productName }
-
- if let token = dic["maxDeviceNum"] { maxDeviceNum = token as? Int ?? maxDeviceNum }
- if let token = dic["levels"] { levels = token as? String ?? levels }
- if let token = dic["platforms"] { platforms = token as? String ?? platforms }
- if let token = dic["productLineId"] { productLineId = token as? Int ?? productLineId }
- if let token = dic["paymentModel"] { paymentModel = token as? Int ?? paymentModel }
- if let token = dic["cycle"] { cycle = token as? Int ?? cycle }
- if let token = dic["code"] { code = token as? String ?? code }
-
- if let token = dic["price"] { price = token as? NSNumber ?? price }
- if let token = dic["displayPrice"] { displayPrice = token as? NSNumber ?? displayPrice }
- if let token = dic["upgradePrice"] { upgradePrice = token as? NSNumber ?? upgradePrice }
- if let token = dic["cnyPrice"] { cnyPrice = token as? NSNumber ?? cnyPrice }
- if let token = dic["displayCnyPrice"] { displayCnyPrice = token as? NSNumber ?? displayCnyPrice }
- 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, upgradePrice: upgradePrice, code: code)
- let result1 = KMMemberProductResult(code: requestCode, msg: message, checkCoupon: products)
- if requestCode == 200 {
- complete(true, result1)
- } else {
- complete(false, result1)
- }
- }
- } else {
- print("Invalid URL")
- complete(false, nil)
- }
- }
-
- /**
- @abstract 检查邮箱教育优惠资格
- @param email 邮箱
- @param complete 回调
- */
- func checkEducation(email: String, _ complete: @escaping KMMemberProductComplete) {
-
- let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkEducation"
- let params: [String: Any] = ["email": email]
- if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
- KMRequestServer.requestServer.request(urlString: urlNewString, 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 requestCode: 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 ?? productId}
- if let token = result["totalPrice"] { totalPrice = token as? String ?? totalPrice}
- if let token = result["price"] { price = token as? String ?? price}
- if let token = result["batchPrice"] { batchPrice = token as? String ?? batchPrice}
- if let token = result["cnyPrice"] { cnyPrice = token as? String ?? cnyPrice}
- if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as? String ?? cnyBatchPrice}
- if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as? String ?? cnyTotalPrice}
- let products = KMBatchProductPriceModel(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
- let result1 = KMMemberProductResult(code: requestCode, msg: message, batchProductPrice: products)
- if requestCode == 200 {
- complete(true, result1)
- } else {
- complete(false, result1)
- }
- }
- } else {
- print("Invalid URL")
- complete(false, nil)
- }
- }
-
- // 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"
- let params: [String: Any] = ["orderId": orderId]
- if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
- KMRequestServer.requestServer.request(urlString: urlNewString, 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 requestCode: Int = dic["code"] as? Int ?? 0
- let requestDic: NSDictionary = dic["result"] as? NSDictionary ?? [:]
- let status:String = requestDic["status"] as? String ?? ""
- if requestCode == 200{
- complete(true, dic)
- } else {
- complete(false, dic)
- }
- }
- } else {
- print("Invalid URL")
- complete(false, nil)
- }
- }
-
- /**
- @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 requestCode: 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 = ""
- var qrCode = ""
- if requestCode == 200 {
- if let token = result["thirdOrderNo"] { thirdOrderNo = token as? String ?? thirdOrderNo}
- if let token = result["orderId"] { orderId = token as? String ?? orderId}
- if let token = result["payHref"] { payHref = token as? String ?? payHref}
- if let token = result["qrcode"] { qrCode = token as? String ?? qrCode}
- let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref, qrCode: qrCode)
- let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: products)
- complete(true, result1)
- } else {
- let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref, qrCode: qrCode))
- 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/createSubscription"
- 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 requestCode: 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 = ""
- var qrCode = ""
- if requestCode == 200 {
- if let token = result["thirdOrderNo"] { thirdOrderNo = token as? String ?? thirdOrderNo}
- if let token = result["orderId"] { orderId = token as? String ?? orderId}
- if let token = result["payHref"] { payHref = token as? String ?? payHref}
- if let token = result["qrcode"] { qrCode = token as? String ?? qrCode}
- let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref, qrCode: qrCode)
- let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: products)
- complete(true, result1)
- } else {
- let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref, qrCode: qrCode))
- complete(false, result1)
- }
- }
- }
- /**
- @abstract 获取订单列表
- @param orderStatus 0全部1待支付
- @param complete 回调
- */
- func getOrderListByStatus(orderStatus: Int, _ complete: @escaping KMMemberRequestInfoComplete) {
- 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]
- if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
- KMRequestServer.requestServer.request(urlString: urlNewString, 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 requestCode: Int = dic["code"] as? Int ?? 0
- if requestCode == 200 {
- complete(true, dic)
- } else {
- complete(false, dic)
- }
- // 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)
- // }
- }
- } else {
- complete(false, nil)
- }
- }
-
- /**
- @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"
- let params: [String: Any] = ["orderId": orderId]
- if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
- KMRequestServer.requestServer.request(urlString: urlNewString, 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 requestCode: Int = dic["code"] as? Int ?? 0
- if requestCode == 200 {
- complete(true, dic)
- } else {
- complete(false, dic)
- }
- }
- } else {
- complete(false, nil)
- }
- }
-
- // MARK: 苹果支付
-
- /**
- @abstract APPstore 权益校验
- @param applePayProductId
- @param transactionId
- @param productCode
- @param complete 回调
- */
- func appStoreEquityVerification(applePayProductId: String, transactionId: String, productCode: String, _ 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 bundleID = Bundle.main.object(forInfoDictionaryKey: "CFBundleIdentifier") ?? ""
- let params: [String: Any] = ["appBundleId": bundleID,
- "applePayProductId": applePayProductId,
- "transactionId": transactionId,
- "productCode": productCode]
- let postData = try! JSONSerialization.data(withJSONObject: params)
-
- var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
- request.addValue("Bearer " + token, forHTTPHeaderField: "Authorization")
- 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: NSDictionary = jsonObject!["result"] as? NSDictionary ?? [:]
- let message: String = jsonObject!["msg"] as? String ?? ""
- let result1 = KMMemberProductResult(code: code, msg: message, result: "")
- if code == 200 {
- complete(true, result1)
- } else {
- complete(false, result1)
- }
- } else {
- complete(false, KMMemberProductResult(code: 0, msg: "", result: ""))
- }
- }
- task.resume()
- }
- // MARK: 评估模块
- // MARK: 活动模块
- // MARK: 翻译模块
-
- // MARK: AI模块
- // MARK: 会员赠送模块
-
- // MARK: Error Code
-
- static func showAlert(code: KMMemberCenterErrorCodeType?, message: String?, callback: ((NSApplication.ModalResponse?, Any ...)->Void)?) {
- let string = self.getCodeMessage(code: code, message: message)
- KMMainThreadExecute {
- let alert = NSAlert()
- alert.messageText = NSLocalizedString(string, tableName: "MemberCenterLocalizable", comment: "")
- let resp = alert.runModal()
- callback?(resp)
- }
- }
-
- static func getCodeMessage(code: KMMemberCenterErrorCodeType?, message: String?) -> String {
- var string = self.typeOfMessage(type: code)
- if string.isEmpty {
- string = message ?? ""
- }
- return string
- }
-
- static func typeOfMessage(type: KMMemberCenterErrorCodeType?) -> String {
- var result: String = ""
- switch type {
- case .EXCEPTION_MSG_TOKEN_IS_INVALID:
- result = "Invalid token or token has expired."
- break;
- case .EXCEPTION_MSG_DEVICE_NUM_MAX:
- result = "Your device logged-in has been limited. Please log out from other devices first."
- break;
- case .EXCEPTION_MSG_USER_NOT_LOGIN:
- result = "The user has not logged in. Please login before accessing."
- 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 = "The password is wrong, you can check the case status."
- 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 = "This email is already associated with an account. please log in."
- break;
- case .EXCEPTION_MSG_EMAIL_NOT_REGISTER:
- result = "The current account is not registered. Click Next and we will register an account for you."
- break;
- case .EXCEPTION_MSG_EMAIL_LOGOUT_ING:
- result = "The account is being removed and unable to log in. If you have any questions, please get in touch with customer service."
- break;
- case .EXCEPTION_MSG_EMAIL_INVALID:
- result = "Please enter the correct email format."
- break;
- case .EXCEPTION_MSG_PASSWORD_NOT_INCONSISTENT:
- result = "Password is inconsistent, please re-enter."
- break;
- case .EXCEPTION_MSG_PASSWORD_SIZE_MIN:
- result = "The password must contain 6 to 24 characters."
- break;
- case .EXCEPTION_MSG_PASSWORD_SIZE_MAX:
- result = "The password must contain 6 to 24 characters."
- break;
- case .EXCEPTION_MSG_PLEASE_ADD_AUTH_CONFIG:
- result = "Please add auth config"
- break;
- case .EXCEPTION_MSG_USER_SUBSCRIPTION_IN_PROGRESS:
- result = "You are still subscribing and cannot remove your account at the moment. Please wait until the subscription period is over."
- break;
- case .EXCEPTION_TIME_TRANSFER_ERROR:
- result = "Time conversion failed."
- break;
- case .EXCEPTION_MSG_PASSWORD_CONTAIN_EMPTY:
- result = "Password cannot contain spaces."
- break;
- case .EXCEPTION_MSG_CREATE_ORDER_PARAMETER: // 支付方式异常
- result = "Abnormal payment method."
- case .EXCEPTION_MSG_EVENT_IS_CURRENTLY_NOT_SUPPORTED: // 当前事件暂不支持
- result = "The current event is not supported yet."
- case .EXCEPTION_MSG_THE_ACCOUNT_IS_ALREADY_LOGGED_IN_ON_OTHER_DEVICES: // 账号已在其他设备登录
- result = "This account has been logged in on other devices."
- case .EXCEPTION_MSG_ABNORMAL_USER_STATUS: // 当前邮箱已被停用或者处于注销中状态
- result = "The current email address has been deactivated or is in the account cancellation state."
- case .EXCEPTION_MSG_APP_STORE_TICKET_VALIDATION_FAILED: // Appstore票据验证失败"
- result = "Ticket verification of AppStore failed."
- case .EXCEPTION_MSG_APP_STORE_TICKET_VALIDATION_NEED_TO_RETRY: //Appstore票据验证需要重试
- result = "Ticket verification of AppStore needs to be retried."
- case .EXCEPTION_MSG_REPEAT_SUBSCRIPTION: // 用户已订阅该产品
- result = "The user has subscribed to this product."
- case .EXCEPTION_MSG_RESTORING_PURCHASES_IS_NOT_CURRENTLY_SUPPORTED: // 恢复购买暂不支持
- result = "Restoring purchases is not supported yet."
- case .EXCEPTION_MSG_USER_TRANSACTION_CANCELED_OR_FAILED: // 用户交易取消或失败
- result = "The user's transaction is canceled or failed."
- case .EXCEPTION_MSG_CURRENT_ORDER_NOT_RECORDED: // 当前订单末记录,请稍后重试
- result = "The current order is not recorded, please try again later."
- case .EXCEPTION_MSG_THE_SAME_USER: //同一用户,无需处理
- result = "Same user, no need to process."
- case .EXCEPTION_MSG_THIRD_PAY_ID_ILLEGAL: //thirdPayld非法
- result = "Third-party payment is illegal."
- case .EXCEPTION_MSG_ORDER_DOES_NOT_EXIST: //订单不存在
- result = "Order does not exist."
- case .EXCEPTION_MSG_THE_ORDER_STATUS_IS_ABNORMAL: // 订单状态异常
- result = "Order status abnormal."
- case .EXCEPTION_MSG_TRANSACTION_ID_REPEAT: // transactionld重复
- result = "Transaction duplicate."
- case .EXCEPTION_TICKET_HAS_BEEN_BLOCKED: // The ticket has been blocked
- result = "The ticket has been blocked."
- case .EXCEPTION_TICKET_HAS_BEEN_CREATED: // 当前票据已创建订单
- result = "The current ticket has created an order."
- case .EXCEPTION_USER_IS_NOT_EDUCATION_USER: // 用户不是教育用户
- result = "The user is not an educational user."
- case .EXCEPTION_USER_HAS_EDUCATION: // 用户近一年有教育购买订单
- result = "The user has education purchase orders in the past year."
- case .EXCEPTION_USER_CANNOT_BUY_PREMIUM: // 用户已有标准版订阅,无法购买高级版
- result = "The user already has a PDF Reader Pro Standard Plan and cannot purchase the Advance Plan."
- case .EXCEPTION_USER_CANNOT_BUY_VIP: // 用户已有高级版订阅,无法购买标准版
- result = "The user already has a PDF Reader Pro Advance Plan and cannot purchase the Standard Plan."
- case .EXCEPTION_USER_CANNOT_UPGRADE_VIP: // 买断用户无法升级为标准版
- result = "The Permanent Plan user cannot upgrade to the Standard Plan."
- case .EXCEPTION_COUPON_NOT_EXISTS: // 优惠券不存在
- result = "The coupon code does not exist."
- case .EXCEPTION_COUPONTYPE_ERROR: // 优惠券类型错误
- result = "Wrong coupon code type."
- case .EXCEPTION_COUPON_PRODUCT_ERROR: // 优惠券关联产品错误
- result = "Coupon-associated product error."
- case .EXCEPTION_COUPON_INVALID: // 优惠券已失效
- result = "The coupon code has expired."
- case .EXCEPTION_PRODUCT_NOT_EXIST: // 产品不存在
- result = "The product does not exist."
- case .EXCEPTION_MSG_CONTACT_US: //请联系我们获取最新折扣
- result = "Please get in touch with us for the latest discounts."
- case .EXCEPTION_MSG_APP_STORE_TRANSACTION_ID_VALIDATION_FAILED: // 验证苹果交易失败
- result = "Verification of Apple's Transaction failed."
- case .EXCEPTION_MSG_GOOGLE_STORE_TRANSACTION_ID_VALIDATION_FAILED: // 验证谷歌交易失败
- result = "Verification of Google's Transaction failed."
- case .EXCEPTION_PRICE_ERROR: // 价格错误
- result = "Price error."
- case .EXCEPTION_MSG_ORDER_CREATE_FAILED: // 订单创建失败
- result = "Order creation failed."
- case .USER_ALREADY_SUBSCRIBED_PLAN: // 该用户已经是PDF Reader Pro订阅版会员,确定再赠送吗
- result = "This user is already a subscription member of PDF Reader Pro. Are you sure you want to share benefits?"
- case .USER_ALREADY_SUBSCRIBED_PACKAGE: // 该用户已经是PDF Reader Pro永久版会员,无需再赠送哦
- result = "This user is already a permanent member of PDF Reader Pro. You don't need to share benefits anymore."
- case .EXCEPTION_MSG_USER_NOT_EXIST: //用户不存在
- result = "User does not exist."
- case .EXCEPTION_USER_ALREADY_LOTTERY: // 用户已经抽过奖啦
- result = "The user already has a prize draw!"
- case .UNKNOWN:
- result = "UNKNOWN"
- break;
- case .SUCCESS:
- result = "SUCCESS"
- break;
- default:
- result = "Network error"
- }
- return result
- }
- }
|