1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867 |
- import Cocoa
- enum KMMemberCenterErrorCodeType: Int, CaseIterable {
- case UNKNOWN = 0
- case SUCCESS = 200
- case EXCEPTION_MSG_TOKEN_IS_INVALID = 304
- case EXCEPTION_MSG_DEVICE_NUM_MAX = 305
- case EXCEPTION_MSG_USER_NOT_LOGIN = 306
- case EMAIL_VERIFY_CODE_KEY_ERROR = 309
- case EMAIL_REGISTER_ERROR = 310
- case EXCEPTION_MSG_PASSWORD_ERROR = 311
- case EXCEPTION_MSG_CODE_ACTION_ERROR = 312
- case EXCEPTION_MSG_CODE_SEND_ERROR = 313
- case EXCEPTION_MAIL_CODE_SEND_ERROR = 314
- case VERIFY_CODE_SEND_TOO_QUICKLY = 315
- 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
- case EXCEPTION_MSG_PASSWORD_SIZE_MAX = 322
- case EXCEPTION_MSG_PLEASE_ADD_AUTH_CONFIG = 323
- 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
- case EXCEPTION_MSG_APP_STORE_TICKET_VALIDATION_NEED_TO_RETRY = 333
- 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
- case EXCEPTION_MSG_ORDER_DOES_NOT_EXIST = 340
-
- case EXCEPTION_MSG_THE_ORDER_STATUS_IS_ABNORMAL = 341
- case EXCEPTION_MSG_TRANSACTION_ID_REPEAT = 342
- case EXCEPTION_TICKET_HAS_BEEN_BLOCKED = 343
- 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
- case USER_ALREADY_SUBSCRIBED_PACKAGE = 361
- 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
- case exe
- case macPro
- case iOSLite
- case iOSPro
- 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()
-
-
- func isConnectionAvailable() -> Bool {
- let reachability = Reachability(hostname: "www.apple.com")
- let state = reachability?.currentReachabilityStatus()
- if(state == NotReachable) {
- return false
- }
- return true
- }
-
-
- func constructURLString(baseURLString: String, parameters: [String: Any]) -> String? {
-
- guard var components = URLComponents(string: baseURLString) else {
- return nil
- }
-
-
- components.queryItems = parameters.map { key, value in
- URLQueryItem(name: key, value: "\(value)")
- }
-
-
- return components.url?.absoluteString
- }
-
-
-
-
- func resetPassword(email: String, verifyCode: String, password: String, _ complete: @escaping KMMemberCenterComplete) {
- let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/memberResetPassword"
- 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()
-
- }
-
-
- 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)
- }
- }
- }
-
-
- 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)
- }
- }
- }
-
-
- 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)
- }
- }
- }
-
- 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
- } 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
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- }
-
-
- 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)
- }
- }
- }
-
-
- 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)
- }
- }
- }
-
-
-
-
- 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)
- }
- }
- }
-
-
- 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: [String : Any] = result_dict["activeVIP"] as? [String : Any] ?? [:]
- let userInfoActiveVIP = KMMemberUserInfoActiveVIP(dict: activeVIP_dict)
- 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"
-
- userInfoActiveVIP.endDate = dayFormatter.string(from: date)
- }
- }
-
- let activeAI_dict: [String : Any] = result_dict["activeAI"] as? [String : Any] ?? [:]
- let userInfoActiveAI = KMMemberUserInfoActiveVIP(dict: activeAI_dict)
- 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
- }
- if let data = result_dict["isFreeAccount"] as? String {
- userInfo.isFreeAccount = data
- }
-
- let result = KMMemberCenterResult(code: code, msg: message, userInfo: userInfo)
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- }
-
-
- 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)
- }
- }
- }
-
-
- 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 {
- let userInfoActiveVIP = KMMemberUserInfoActiveVIP(dict: dict1 as? [String : Any] ?? [:])
- results.append(userInfoActiveVIP)
- }
- let result = KMMemberCenterResult(code: code, msg: message, activeVIPs: results)
- if code == 200 {
- complete(true, result)
- } else {
- complete(false, result)
- }
- }
- }
-
-
- 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)
- }
- }
- }
-
-
- 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)
- }
- }
- }
-
-
-
-
- func getListingProducts(isEducation: Int, discountCode: String, _ complete: @escaping KMMemberProductComplete) {
-
- let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getListingProducts"
- var platformId = "2"
- #if VERSION_FREE
-
- #if VERSION_DMG
-
- platformId = "2"
- #else
-
- #endif
- #else
-
- platformId = "5"
- #endif
- let params: [String: Any] = ["isEducation": NSNumber(value: Int32(isEducation)),
- "platformId": platformId,
- "code" : discountCode]
- 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)
-
- var priceString:String?
- var displayPriceString:String?
- var upgradePriceString:String?
- var cnyPriceString:String?
- var displayCnyPriceString:String?
- var upgradecnyPriceString:String?
-
- 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"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- priceString = string
- price = token
- }
-
- if let token = dict1["displayPrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- displayPriceString = string
- displayPrice = token
- }
-
- if let token = dict1["cnyUpgradePrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- upgradecnyPriceString = string
- }
-
- if let token = dict1["upgradePrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- upgradePriceString = string
- upgradePrice = token
- }
-
- if let token = dict1["cnyPrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- cnyPriceString = string
- cnyPrice = token
- }
-
- if let token = dict1["cnyDisplayPrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- displayCnyPriceString = string
- displayCnyPrice = token
- }
- let products = KMListingProductsModel(id: id, productName: productName, price: priceString, maxDeviceNum: maxDeviceNum, displayPrice: displayPriceString, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, cnyPrice: cnyPriceString, displayCnyPrice: displayCnyPriceString, upgradePrice: upgradePriceString, code: code)
- products.individualPriceString = priceString
- products.individualCnyPriceString = cnyPriceString
- products.cnyUpgradePriceString = upgradecnyPriceString
-
- if let data = dict1["displayAmount"] as? NSNumber {
- let string = KMFormatNSNumber(data, to: 2)
- products.displayAmount = string
- }
- if let data = dict1["cnyDisplayAmount"] as? NSNumber {
- let string = KMFormatNSNumber(data, to: 2)
- products.cnyDisplayAmount = string
- }
-
- 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)
- }
- }
-
-
- 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)
-
- var priceString:String?
- var displayPriceString:String?
- var upgradePriceString:String?
- var cnyPriceString:String?
- var displayCnyPriceString:String?
- var upgradecnyPriceString:String?
- 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"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- priceString = string
- price = token
- }
- if let token = dict1["displayPrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- displayPriceString = string
- displayPrice = token
- }
- if let token = dict1["upgradePrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- upgradePriceString = string
- upgradePrice = token
- }
- if let token = dict1["cnyPrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- cnyPriceString = string
- cnyPrice = token
- }
- if let token = dict1["cnyDisplayPrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- displayCnyPriceString = string
- displayCnyPrice = token
- }
-
- if let token = dict1["cnyUpgradePrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- upgradecnyPriceString = string
- }
- let products = KMListingProductsModel(id: id, productName: productName, price: priceString, maxDeviceNum: maxDeviceNum, displayPrice: displayPriceString, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, cnyPrice: cnyPriceString, displayCnyPrice: displayCnyPriceString, upgradePrice: upgradePriceString, code: code)
- products.cnyUpgradePriceString = upgradecnyPriceString
- products.individualPriceString = priceString
- products.individualCnyPriceString = cnyPriceString
- 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)
- }
-
- }
-
-
- 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")
- }
- }
-
-
- 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)
-
- var priceString:String?
- var displayPriceString:String?
- var upgradePriceString:String?
- var cnyPriceString:String?
- var displayCnyPriceString:String?
- var upgradecnyPriceString:String?
-
- if let token = result["id"] { id = token as? String ?? id }
- if let token = result["productName"] { productName = token as? String ?? productName }
-
- if let token = result["maxDeviceNum"] { maxDeviceNum = token as? Int ?? maxDeviceNum }
- if let token = result["levels"] { levels = token as? String ?? levels }
- if let token = result["platforms"] { platforms = token as? String ?? platforms }
- if let token = result["productLineId"] { productLineId = token as? Int ?? productLineId }
- if let token = result["paymentModel"] { paymentModel = token as? Int ?? paymentModel }
- if let token = result["cycle"] { cycle = token as? Int ?? cycle }
- if let token = result["code"] { code = token as? String ?? code }
-
- if let token = result["price"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- priceString = string
- price = token
- }
- if let token = result["displayPrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- displayPriceString = string
- displayPrice = token
- }
- if let token = result["upgradePrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- upgradePriceString = string
- upgradePrice = token
- }
- if let token = result["cnyPrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- cnyPriceString = string
- cnyPrice = token
- }
- if let token = result["cnyDisplayPrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- displayCnyPriceString = string
- displayCnyPrice = token
- }
-
- if let token = result["cnyUpgradePrice"] as? NSNumber {
- let string = KMFormatNSNumber(token, to: 2)
- upgradecnyPriceString = string
- }
- let products = KMCheckCouponModel(id: id, productName: productName, price: priceString, maxDeviceNum: maxDeviceNum, displayPrice: displayPriceString, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, cnyPrice: cnyPriceString, displayCnyPrice: displayCnyPriceString, upgradePrice: upgradePriceString, code: code)
- products.upgradecnyPriceString = upgradecnyPriceString
-
- 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)
- }
- }
-
-
- 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)
- }
- }
-
-
-
-
-
-
- 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)
- }
- }
-
-
- 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)
- }
- }
- }
-
-
- 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)
- }
- }
- }
-
- 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)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- } else {
- complete(false, nil)
- }
- }
-
-
- 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)
- }
- }
-
-
-
-
- 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()
- }
-
-
-
-
-
- static func checkIn(callback: @escaping ((_ success: Bool, _ resultModel: KMRequestResultModel?, _ error: NSError?)->Void)) {
- let uuid = GetHardwareUUID() ?? ""
- var model = "MAC_APP_STORE_FREE"
- if KMIsDMGVersion() {
- model = "DMG_DOWNLOAD"
- } else if KMIsAppStoreProVersion() {
- model = "MAC_APP_STORE_PAID"
- }
-
- let appVersion = KMTools.getAppVersion()
- let language = NSLocale.current.identifier
- let timeZone = NSTimeZone.local.localizedName(for: .shortDaylightSaving, locale: .current) ?? ""
-
- let params = ["uniqueSn" : uuid,
- "model" : model,
- "os" : "",
- "language" : language,
- "timeZone" : timeZone,
- "appVersion" : appVersion]
-
- KMRequestServer.Member_POST(url: kURLAPI_memberSystemWebsite_activity_signIn, params: params, callback: callback)
- }
-
-
- static func judgeTrailCancel(callback: @escaping ((_ success: Bool, _ resultModel: KMRequestResultModel?, _ error: NSError?)->Void)) {
- KMRequestServer.Member_GET(url: kURLAPI_memberSystemSSO_user_judgeTrailCancel, params: nil, callback: callback)
- }
-
-
-
-
-
-
-
- static func quickShowAlert(result: KMMemberProductResult?, callback: ((NSApplication.ModalResponse?, Any ...)->Void)?) {
- guard let data = result else {
- return
- }
- showAlert(code: .init(rawValue: data.code ?? 0), message: data.msg, callback: callback)
- }
-
- 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. Please sign up using the verification code directly."
- 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:
- result = "Ticket verification of AppStore failed."
- case .EXCEPTION_MSG_APP_STORE_TICKET_VALIDATION_NEED_TO_RETRY:
- 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:
- 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:
- result = "Transaction duplicate."
- case .EXCEPTION_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:
- 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:
- 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
- }
- }
|