KMMemberCenterManager.swift 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  1. //
  2. // KMMemberCenterManager.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2024/10/21.
  6. //
  7. import Cocoa
  8. enum KMMemberCenterErrorCodeType: Int, CaseIterable {
  9. case UNKNOWN = 0 //未知
  10. case SUCCESS = 200 //正确
  11. case EXCEPTION_MSG_TOKEN_IS_INVALID = 304 // 无效的token或者token已过期
  12. case EXCEPTION_MSG_DEVICE_NUM_MAX = 305 // 您的登录设备已达上限,请退出其他设备重新登录
  13. case EXCEPTION_MSG_USER_NOT_LOGIN = 306 // 用户没有登录,请登录后再访问
  14. case EMAIL_VERIFY_CODE_KEY_ERROR = 309 // email code error!
  15. case EMAIL_REGISTER_ERROR = 310 // Register error!
  16. case EXCEPTION_MSG_PASSWORD_ERROR = 311 // 密码错误,您可以检查大小写状态
  17. case EXCEPTION_MSG_CODE_ACTION_ERROR = 312 // code action error
  18. case EXCEPTION_MSG_CODE_SEND_ERROR = 313 // code send error
  19. case EXCEPTION_MAIL_CODE_SEND_ERROR = 314 // mail send error
  20. case VERIFY_CODE_SEND_TOO_QUICKLY = 315 // code send too quickly
  21. case EXCEPTION_MSG_EMAIL_EXIST = 316 // 该邮箱已有账号,请前往登录
  22. case EXCEPTION_MSG_EMAIL_NOT_REGISTER = 317 // 当前账号未注册,点击下一步我们将为您注册账号
  23. case EXCEPTION_MSG_EMAIL_LOGOUT_ING = 318 // 注销中,无法登录,若有问题可联系客服
  24. case EXCEPTION_MSG_EMAIL_INVALID = 319 // 请输入正确的邮箱格式
  25. case EXCEPTION_MSG_PASSWORD_NOT_INCONSISTENT = 320 // 密码不一致,请重新输入
  26. case EXCEPTION_MSG_PASSWORD_SIZE_MIN = 321 // 密码请包含6~24个字符
  27. case EXCEPTION_MSG_PASSWORD_SIZE_MAX = 322 // 密码请包含6~24个字符
  28. case EXCEPTION_MSG_PLEASE_ADD_AUTH_CONFIG = 323 // please add auth config
  29. case EXCEPTION_MSG_USER_SUBSCRIPTION_IN_PROGRESS = 324 // 您目前还在订阅期内,暂时无法注销,请订阅期结束后再点击注销账号
  30. case EXCEPTION_TIME_TRANSFER_ERROR = 326 // 时间转换失败
  31. case EXCEPTION_MSG_PASSWORD_CONTAIN_EMPTY = 327 // 密码不能包含空格
  32. }
  33. @objc enum KMVerificationCodeType : Int {
  34. case login = 0 // 登录验证码
  35. case reset // 重置密码验证码
  36. case logout // 注销验证码
  37. }
  38. @objc enum KMBuyPlatformType : Int {
  39. case web = 0 // 官网
  40. case dmg // 重置密码验证码
  41. case macLite // Mac store免费版
  42. case exe
  43. case macPro // Mac store付费版
  44. case iOSLite // iOS免费版
  45. case iOSPro // iOS付费版
  46. case Android
  47. }
  48. typealias KMMemberCenterComplete = (_ success: Bool, _ result: KMMemberCenterResult?) -> Void
  49. typealias KMMemberProductComplete = (_ success: Bool, _ result: KMMemberProductResult?) -> Void
  50. class KMMemberCenterManager: NSObject {
  51. static let manager = KMMemberCenterManager()
  52. private let configuration: KMMemberCenterConfig = KMMemberCenterConfig()
  53. // MARK: 登录模块
  54. /**
  55. @abstract 新会员系统重置密码
  56. @param email 邮箱
  57. @param verifyCode 验证码
  58. @param password 密码
  59. @param complete 回调
  60. */
  61. func resetPassword(email: String, verifyCode: String, password: String, _ complete: @escaping KMMemberCenterComplete) {
  62. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/memberResetPassword"
  63. let params: [String: Any] = ["email": email,
  64. "verifyCode": verifyCode,
  65. "appId": "1",
  66. "password": password]
  67. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  68. } completion: { [weak self] (task, responseObject, error) in
  69. var dic: NSDictionary = [:]
  70. if error == nil, let responseObject = responseObject as? NSDictionary {
  71. dic = responseObject
  72. } else {
  73. var info = responseObject
  74. if let error = error {
  75. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  76. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  77. }
  78. }
  79. dic = (info as? NSDictionary) ?? [:]
  80. }
  81. let code: Int = dic["code"] as? Int ?? 0
  82. let result_bool: Bool = dic["result"] as? Bool ?? false
  83. let message: String = dic["msg"] as? String ?? ""
  84. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  85. // let error = NSError(domain: message, code: code)
  86. if code == 200 {
  87. complete(true, result)
  88. } else {
  89. complete(false, result)
  90. }
  91. }
  92. }
  93. /**
  94. @abstract 验证邮箱(重置密码输入邮箱点击下一步时校验邮箱是否注册)
  95. @param email 邮箱
  96. @param complete 回调
  97. */
  98. func emailVerification(email: String, _ complete: @escaping KMMemberCenterComplete) {
  99. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/validEmail"
  100. let params: [String: Any] = ["email": email]
  101. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  102. } completion: { [weak self] (task, responseObject, error) in
  103. var dic: NSDictionary = [:]
  104. if error == nil, let responseObject = responseObject as? NSDictionary {
  105. dic = responseObject
  106. } else {
  107. var info = responseObject
  108. if let error = error {
  109. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  110. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  111. }
  112. }
  113. dic = (info as? NSDictionary) ?? [:]
  114. }
  115. let code: Int = dic["code"] as? Int ?? 0
  116. let result_bool: Bool = dic["result"] as? Bool ?? false
  117. let message: String = dic["msg"] as? String ?? ""
  118. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  119. // let error = NSError(domain: message, code: code)
  120. if code == 200 {
  121. complete(true, result)
  122. } else {
  123. complete(false, result)
  124. }
  125. }
  126. }
  127. /**
  128. @abstract 获取邮箱验证码
  129. @param action 验证码用途
  130. @param receiver 邮箱号
  131. @param complete 回调
  132. */
  133. func getVerificationCode(action: KMVerificationCodeType, receiver: String, _ complete: @escaping KMMemberCenterComplete) {
  134. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/getVerifyCode"
  135. var actionType = "member_login"
  136. if action == .reset {
  137. actionType = "member_reset_password"
  138. } else if action == .logout {
  139. actionType = "user_log_off"
  140. }
  141. let params: [String: Any] = ["action": actionType,
  142. "type": 0,
  143. "receiver": receiver,
  144. "appId": "1"]
  145. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  146. } completion: { [weak self] (task, responseObject, error) in
  147. var dic: NSDictionary = [:]
  148. if error == nil, let responseObject = responseObject as? NSDictionary {
  149. dic = responseObject
  150. } else {
  151. var info = responseObject
  152. if let error = error {
  153. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  154. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  155. }
  156. }
  157. dic = (info as? NSDictionary) ?? [:]
  158. }
  159. let code: Int = dic["code"] as? Int ?? 0
  160. let result_bool: Bool = dic["result"] as? Bool ?? false
  161. let message: String = dic["msg"] as? String ?? ""
  162. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  163. // let error = NSError(domain: message, code: code)
  164. if code == 200 {
  165. complete(true, result)
  166. } else {
  167. complete(false, result)
  168. }
  169. }
  170. }
  171. /**
  172. @abstract 实时检查邮件验证码
  173. @param type 验证码用途
  174. @param account 账户
  175. @param code 验证码
  176. @param complete 回调
  177. */
  178. func checkVerificationCode(type: KMVerificationCodeType, account: String, code: String, _ complete: @escaping KMMemberCenterComplete) {
  179. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/isEmailCodeValid"
  180. var actionType = "member_login"
  181. if type == .reset {
  182. actionType = "member_reset_password"
  183. } else if type == .logout {
  184. actionType = "user_log_off"
  185. }
  186. let params: [String: Any] = ["type": actionType,
  187. "account": account,
  188. "code": code,
  189. "appId": "1"]
  190. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  191. } completion: { [weak self] (task, responseObject, error) in
  192. var dic: NSDictionary = [:]
  193. if error == nil, let responseObject = responseObject as? NSDictionary {
  194. dic = responseObject
  195. } else {
  196. var info = responseObject
  197. if let error = error {
  198. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  199. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  200. }
  201. }
  202. dic = (info as? NSDictionary) ?? [:]
  203. }
  204. let code: Int = dic["code"] as? Int ?? 0
  205. let result_bool: Bool = dic["result"] as? Bool ?? false
  206. let message: String = dic["msg"] as? String ?? ""
  207. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  208. // let error = NSError(domain: message, code: code)
  209. if code == 200 {
  210. complete(true, result)
  211. } else {
  212. complete(false, result)
  213. }
  214. }
  215. }
  216. /**
  217. @abstract 邮箱验证码登录 & 密码登录
  218. @param email 邮箱
  219. @param code 验证码/密码
  220. @param type 密码类型(验证码?密码?)
  221. @param complete 回调
  222. */
  223. func emailLogin(email: String, code: String, type: KMSignUpState, _ complete: @escaping KMMemberCenterComplete) {
  224. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/memberLogin"
  225. let uuid: String = GetHardwareUUID() ?? ""
  226. var params: [String: Any] = [:]
  227. if type == .verificationCode {
  228. params = ["email": email,
  229. "code": code,
  230. "appId": "1",
  231. "deviceSign": uuid,
  232. "deviceName": NSFullUserName(),
  233. "model": "mac"]
  234. } else {
  235. params = ["email": email,
  236. "password": code,
  237. "appId": "1",
  238. "deviceSign": uuid,
  239. "deviceName": NSFullUserName(),
  240. "model": "mac"]
  241. }
  242. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  243. // requestSerializer.setValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  244. } completion: { [weak self] (task, responseObject, error) in
  245. var dic: NSDictionary = [:]
  246. if error == nil, let responseObject = responseObject as? NSDictionary {
  247. dic = responseObject
  248. } else {
  249. var info = responseObject
  250. if let error = error {
  251. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  252. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  253. }
  254. }
  255. dic = (info as? NSDictionary) ?? [:]
  256. }
  257. let code: Int = dic["code"] as? Int ?? 0
  258. let result_dict: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  259. let message: String = dic["msg"] as? String ?? ""
  260. var refresh_token = ""
  261. var access_token = ""
  262. var token_type = ""
  263. var expires_in = ""
  264. var scope = ""
  265. if let token = result_dict["refresh_token"] { refresh_token = token as! String }
  266. if let token = result_dict["access_token"] { access_token = token as! String }
  267. if let token = result_dict["token_type"] { token_type = token as! String }
  268. if let token = result_dict["expires_in"] { expires_in = token as! String }
  269. let loginResult = KMMemberLoginResult(refreshToken: refresh_token, accessToken: access_token, tokenType: token_type, expiresIn: expires_in)
  270. let result = KMMemberCenterResult(loginResult: loginResult)
  271. result.code = code
  272. result.msg = message
  273. // let error = NSError(domain: message, code: code)
  274. if code == 200 {
  275. complete(true, result)
  276. } else {
  277. complete(false, result)
  278. }
  279. }
  280. }
  281. /**
  282. @abstract 获取用户登录设备列表
  283. @param email 邮箱
  284. @param complete 回调
  285. */
  286. func getUserDeviceList(email: String, _ complete: @escaping KMMemberCenterComplete) {
  287. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/getLoginDeviceList"
  288. let params: [String: Any] = ["email": email,
  289. "appId": "1"]
  290. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  291. } completion: { [weak self] (task, responseObject, error) in
  292. var dic: NSDictionary = [:]
  293. if error == nil, let responseObject = responseObject as? NSDictionary {
  294. dic = responseObject
  295. } else {
  296. var info = responseObject
  297. if let error = error {
  298. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  299. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  300. }
  301. }
  302. dic = (info as? NSDictionary) ?? [:]
  303. }
  304. let code: Int = dic["code"] as? Int ?? 0
  305. let result_dict: Dictionary = dic["result"] as? Dictionary ?? [:]
  306. let message: String = dic["msg"] as? String ?? ""
  307. let deviceList: [Dictionary] = result_dict["deviceList"] as? [Dictionary] ?? [[:]]
  308. var deviceLists: [KMMemberDeviceList] = []
  309. for dict in deviceList {
  310. var device_id = ""
  311. var productId = ""
  312. var uniqueSn = ""
  313. var deviceName = ""
  314. if let token = dict["device_id"] { device_id = token as! String }
  315. if let token = dict["productId"] { productId = token as! String }
  316. if let token = dict["uniqueSn"] { uniqueSn = token as! String }
  317. if let token = dict["deviceName"] { deviceName = token as! String }
  318. let list = KMMemberDeviceList(deviceId: device_id, productId: productId, uniqueSn: uniqueSn, appId: deviceName)
  319. deviceLists.append(list)
  320. }
  321. var maxDeviceNum = 0
  322. if let token = result_dict["maxDeviceNum"] {
  323. maxDeviceNum = token as! Int
  324. }
  325. let result = KMMemberCenterResult(deviceListResult: deviceLists, maxDeviceNum: maxDeviceNum)
  326. if code == 200 {
  327. complete(true, result)
  328. } else {
  329. complete(false, result)
  330. }
  331. }
  332. }
  333. /**
  334. @abstract 登出用户的指定设备
  335. @param deviceId 设备记录ID
  336. @param complete 回调
  337. */
  338. func logoutDevice(deviceId: String, complete: @escaping KMMemberCenterComplete) {
  339. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/logoutDevice"
  340. let params: [String: Any] = ["deviceId": deviceId]
  341. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  342. } completion: { [weak self] (task, responseObject, error) in
  343. var dic: NSDictionary = [:]
  344. if error == nil, let responseObject = responseObject as? NSDictionary {
  345. dic = responseObject
  346. } else {
  347. var info = responseObject
  348. if let error = error {
  349. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  350. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  351. }
  352. }
  353. dic = (info as? NSDictionary) ?? [:]
  354. }
  355. let code: Int = dic["code"] as? Int ?? 0
  356. let resultStr: String = dic["result"] as? String ?? ""
  357. let message: String = dic["msg"] as? String ?? ""
  358. let result = KMMemberCenterResult(code: code, msg: message, resultStr: resultStr)
  359. if code == 200 {
  360. complete(true, result)
  361. } else {
  362. complete(false, result)
  363. }
  364. }
  365. }
  366. // MARK: 个人信息模块
  367. /**
  368. @abstract 获取老带新已邀请人数
  369. @param complete 回调
  370. */
  371. func getInviteNum(_ complete: @escaping KMMemberCenterComplete) {
  372. let token: String = KMMemberInfo.shared.access_token
  373. if token == "" {
  374. return
  375. }
  376. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/getInviteNum"
  377. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  378. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  379. } completion: { [weak self] (task, responseObject, error) in
  380. var dic: NSDictionary = [:]
  381. if error == nil, let responseObject = responseObject as? NSDictionary {
  382. dic = responseObject
  383. } else {
  384. var info = responseObject
  385. if let error = error {
  386. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  387. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  388. }
  389. }
  390. dic = (info as? NSDictionary) ?? [:]
  391. }
  392. let code: Int = dic["code"] as? Int ?? 0
  393. let resultInt: Int = dic["result"] as? Int ?? 0
  394. let message: String = dic["msg"] as? String ?? ""
  395. let result = KMMemberCenterResult(code: code, msg: message, resultInt: resultInt)
  396. if code == 200 {
  397. complete(true, result)
  398. } else {
  399. complete(false, result)
  400. }
  401. }
  402. }
  403. /**
  404. @abstract 获取用户个人信息
  405. @param complete 回调
  406. */
  407. func userInfo(_ complete: @escaping KMMemberCenterComplete) {
  408. let token: String = KMMemberInfo.shared.access_token
  409. if token == "" {
  410. return
  411. }
  412. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/info"
  413. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
  414. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  415. } completion: { [weak self] (task, responseObject, error) in
  416. var dic: NSDictionary = [:]
  417. if error == nil, let responseObject = responseObject as? NSDictionary {
  418. dic = responseObject
  419. } else {
  420. var info = responseObject
  421. if let error = error {
  422. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  423. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  424. }
  425. }
  426. dic = (info as? NSDictionary) ?? [:]
  427. }
  428. let code: Int = dic["code"] as? Int ?? 0
  429. let result_dict: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  430. let message: String = dic["msg"] as? String ?? ""
  431. var userId = ""
  432. var email = ""
  433. var fullName = ""
  434. var activeVIP = KMMemberUserInfo()
  435. var aiPoint = 0
  436. var validFlag = ""
  437. var isHaveAIDiscount = ""
  438. var canTrail = ""
  439. if let token = result_dict["id"] { userId = token as! String }
  440. if let token = result_dict["email"] { email = token as! String }
  441. if let token = result_dict["fullName"] { fullName = token as! String }
  442. let activeVIP_dict: NSDictionary = result_dict["activeVIP"] as? NSDictionary ?? [:]
  443. var activeVIP_id = ""
  444. var activeVIP_userId = ""
  445. var activeVIP_status = 0
  446. var activeVIP_endDate = ""
  447. var activeVIP_payType = 0
  448. var activeVIP_productName = ""
  449. var activeVIP_levels = ""
  450. var activeVIP_platforms = ""
  451. var activeVIP_point = 0
  452. var activeVIP_maxDeviceNum = 0
  453. var activeVIP_paymentModel = ""
  454. var activeVIP_isAi = ""
  455. if let token = activeVIP_dict["id"] as? String { activeVIP_id = token }
  456. if let token = activeVIP_dict["userId"] as? String { activeVIP_userId = token }
  457. if let token = activeVIP_dict["status"] as? Int { activeVIP_status = token }
  458. if let token = activeVIP_dict["endDate"] as? String { activeVIP_endDate = token }
  459. if let token = activeVIP_dict["payType"] as? Int { activeVIP_payType = token }
  460. if let token = activeVIP_dict["productName"] as? String { activeVIP_productName = token }
  461. if let token = activeVIP_dict["levels"] as? String { activeVIP_levels = token }
  462. if let token = activeVIP_dict["platforms"] as? String { activeVIP_platforms = token }
  463. if let token = activeVIP_dict["point"] as? Int { activeVIP_point = token }
  464. if let token = activeVIP_dict["maxDeviceNum"] as? Int { activeVIP_maxDeviceNum = token }
  465. if let token = activeVIP_dict["paymentModel"] as? String { activeVIP_paymentModel = token }
  466. if let token = activeVIP_dict["isAi"] { activeVIP_isAi = token as! String }
  467. 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)
  468. let activeAI_dict: NSDictionary = result_dict["activeAI"] as? NSDictionary ?? [:]
  469. var activeAI_id = ""
  470. var activeAI_userId = ""
  471. var activeAI_status = 0
  472. var activeAI_endDate = ""
  473. var activeAI_payType = 0
  474. var activeAI_productName = ""
  475. var activeAI_levels = ""
  476. var activeAI_platforms = ""
  477. var activeAI_point = 0
  478. var activeAI_maxDeviceNum = 0
  479. var activeAI_paymentModel = ""
  480. var activeAI_isAi = ""
  481. if let token = activeAI_dict["id"] as? String { activeAI_id = token }
  482. if let token = activeAI_dict["userId"] as? String { activeAI_userId = token }
  483. if let token = activeAI_dict["status"] as? Int { activeAI_status = token }
  484. if let token = activeAI_dict["endDate"] as? String { activeAI_endDate = token }
  485. if let token = activeAI_dict["payType"] as? Int { activeAI_payType = token }
  486. if let token = activeAI_dict["productName"] as? String { activeAI_productName = token }
  487. if let token = activeAI_dict["levels"] as? String { activeAI_levels = token }
  488. if let token = activeAI_dict["platforms"] as? String { activeAI_platforms = token }
  489. if let token = activeAI_dict["point"] as? Int { activeAI_point = token }
  490. if let token = activeAI_dict["maxDeviceNum"] as? Int { activeAI_maxDeviceNum = token }
  491. if let token = activeAI_dict["paymentModel"] as? String { activeAI_paymentModel = token }
  492. if let token = activeAI_dict["isAi"] as? String { activeAI_isAi = token }
  493. 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)
  494. if let token = result_dict["aiPoint"] { aiPoint = token as! Int }
  495. if let token = result_dict["validFlag"] { validFlag = token as! String }
  496. if let token = result_dict["isHaveAIDiscount"] { isHaveAIDiscount = token as! String }
  497. if let token = result_dict["canTrail"] { canTrail = token as! String }
  498. let userInfo = KMMemberUserInfo(id: userId, email: email, fullName: fullName, activeVIP: [userInfoActiveVIP], activeAI: [userInfoActiveAI], aiPoint: aiPoint, validFlag: validFlag, isHaveAIDiscount: isHaveAIDiscount, canTrail: canTrail)
  499. let result = KMMemberCenterResult(code: code, msg: message, userInfo: userInfo)
  500. // let error = NSError(domain: message, code: code)
  501. if code == 200 {
  502. complete(true, result)
  503. } else {
  504. complete(false, result)
  505. }
  506. }
  507. }
  508. /**
  509. @abstract 退出登录
  510. @param complete 回调
  511. */
  512. func userLogout(_ complete: @escaping KMMemberCenterComplete) {
  513. let token: String = KMMemberInfo.shared.access_token
  514. if token == "" {
  515. return
  516. }
  517. // let urlString = configuration.activityBaseURL() + "/member-system-sso/user/logout"
  518. let uuid: String = GetHardwareUUID() ?? ""
  519. // let params: [String: Any] = ["deviceSign": uuid,
  520. // "appId": "1"]
  521. let urlString = String(format: "%@/member-system-sso/user/logout?deviceSign=%@&appId=1", configuration.activityBaseURL(),uuid)
  522. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  523. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  524. } completion: { [weak self] (task, responseObject, error) in
  525. var dic: NSDictionary = [:]
  526. if error == nil, let responseObject = responseObject as? NSDictionary {
  527. dic = responseObject
  528. } else {
  529. var info = responseObject
  530. if let error = error {
  531. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  532. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  533. }
  534. }
  535. dic = (info as? NSDictionary) ?? [:]
  536. }
  537. let code: Int = dic["code"] as? Int ?? 0
  538. let result_bool: Bool = dic["result"] as? Bool ?? false
  539. let message: String = dic["msg"] as? String ?? ""
  540. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  541. if code == 200 {
  542. complete(true, result)
  543. } else {
  544. complete(false, result)
  545. }
  546. }
  547. }
  548. /**
  549. @abstract 获取用户当前会员情况
  550. @param complete 回调
  551. */
  552. func userRightList(_ complete: @escaping KMMemberCenterComplete) {
  553. let token: String = KMMemberInfo.shared.access_token
  554. if token == "" {
  555. return
  556. }
  557. let urlString = configuration.activityBaseURL() + "/member-system-sso//user/rightList"
  558. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
  559. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  560. } completion: { [weak self] (task, responseObject, error) in
  561. var dic: NSDictionary = [:]
  562. if error == nil, let responseObject = responseObject as? NSDictionary {
  563. dic = responseObject
  564. } else {
  565. var info = responseObject
  566. if let error = error {
  567. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  568. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  569. }
  570. }
  571. dic = (info as? NSDictionary) ?? [:]
  572. }
  573. let code: Int = dic["code"] as? Int ?? 0
  574. let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
  575. let message: String = dic["msg"] as? String ?? ""
  576. var results: [KMMemberUserInfoActiveVIP] = []
  577. for dict1 in result_Array {
  578. var activeVIP_id = ""
  579. var activeVIP_userId = ""
  580. var activeVIP_status = 0
  581. var activeVIP_endDate = ""
  582. var activeVIP_payType = 0
  583. var activeVIP_productName = ""
  584. var activeVIP_levels = ""
  585. var activeVIP_platforms = ""
  586. var activeVIP_point = 0
  587. var activeVIP_maxDeviceNum = 0
  588. var activeVIP_paymentModel = ""
  589. var activeVIP_isAi = ""
  590. if let token = dict1["id"] { activeVIP_id = token as! String }
  591. if let token = dict1["userId"] { activeVIP_userId = token as! String }
  592. if let token = dict1["status"] { activeVIP_status = token as! Int }
  593. if let token = dict1["endDate"] { activeVIP_endDate = token as! String }
  594. if let token = dict1["payType"] { activeVIP_payType = token as! Int }
  595. if let token = dict1["productName"] { activeVIP_productName = token as! String }
  596. if let token = dict1["levels"] { activeVIP_levels = token as! String }
  597. if let token = dict1["platforms"] { activeVIP_platforms = token as! String }
  598. if let token = dict1["point"] { activeVIP_point = token as! Int }
  599. if let token = dict1["maxDeviceNum"] { activeVIP_maxDeviceNum = token as! Int }
  600. if let token = dict1["paymentModel"] { activeVIP_paymentModel = token as! String }
  601. if let token = dict1["isAi"] { activeVIP_isAi = token as! String }
  602. 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)
  603. results.append(userInfoActiveVIP)
  604. }
  605. let result = KMMemberCenterResult(code: code, msg: message, activeVIPs: results)
  606. if code == 200 {
  607. complete(true, result)
  608. } else {
  609. complete(false, result)
  610. }
  611. }
  612. }
  613. /**
  614. @abstract 用户手动注销
  615. @param code 邮箱验证码
  616. @param complete 回调
  617. */
  618. func userLogOffForUser(code: String, _ complete: @escaping KMMemberCenterComplete) {
  619. let token: String = KMMemberInfo.shared.access_token
  620. if token == "" {
  621. return
  622. }
  623. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/logOffForUser"
  624. let params: [String: Any] = ["code": code,
  625. "appId": "1"]
  626. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  627. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  628. } completion: { [weak self] (task, responseObject, error) in
  629. var dic: NSDictionary = [:]
  630. if error == nil, let responseObject = responseObject as? NSDictionary {
  631. dic = responseObject
  632. } else {
  633. var info = responseObject
  634. if let error = error {
  635. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  636. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  637. }
  638. }
  639. dic = (info as? NSDictionary) ?? [:]
  640. }
  641. let code: Int = dic["code"] as? Int ?? 0
  642. let message: String = dic["msg"] as? String ?? ""
  643. let result_dict: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  644. var currentTime = ""
  645. var logOffTime = ""
  646. if let token = result_dict["currentTime"] { currentTime = token as! String }
  647. if let token = result_dict["logOffTime"] { logOffTime = token as! String }
  648. let logOff = KMMemberLogOff(currentTime: currentTime, logOffTime: logOffTime)
  649. let result = KMMemberCenterResult(code: code, msg: message, logOff: logOff)
  650. if code == 200 {
  651. complete(true, result)
  652. } else {
  653. complete(false, result)
  654. }
  655. }
  656. }
  657. /**
  658. @abstract 撤销注销申请
  659. @param complete 回调
  660. */
  661. func userRevokeCancel(_ complete: @escaping KMMemberCenterComplete) {
  662. let token: String = KMMemberInfo.shared.access_token
  663. if token == "" {
  664. return
  665. }
  666. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/revokeCancel"
  667. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  668. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  669. } completion: { [weak self] (task, responseObject, error) in
  670. var dic: NSDictionary = [:]
  671. if error == nil, let responseObject = responseObject as? NSDictionary {
  672. dic = responseObject
  673. } else {
  674. var info = responseObject
  675. if let error = error {
  676. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  677. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  678. }
  679. }
  680. dic = (info as? NSDictionary) ?? [:]
  681. }
  682. let code: Int = dic["code"] as? Int ?? 0
  683. let message: String = dic["msg"] as? String ?? ""
  684. let result_Bool: Bool = dic["result"] as? Bool ?? false
  685. let result = KMMemberCenterResult(code: code, msg: message, result: result_Bool)
  686. if code == 200 {
  687. complete(true, result)
  688. } else {
  689. complete(false, result)
  690. }
  691. }
  692. }
  693. // MARK: 商品模块
  694. /**
  695. @abstract 获取上架中的产品
  696. @param isEducation 是否教育优惠
  697. @param complete 回调
  698. */
  699. func getListingProducts(isEducation: Int, _ complete: @escaping KMMemberProductComplete) {
  700. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getListingProducts"
  701. var platformId = "2"
  702. #if VERSION_FREE
  703. #if VERSION_DMG
  704. // DMG
  705. platformId = "2"
  706. #else
  707. // AppStore 免费版本
  708. #endif
  709. platformId = "3"
  710. #else
  711. // AppStore 付费版
  712. platformId = "5"
  713. #endif
  714. let params: [String: Any] = ["isEducation": isEducation,
  715. "platformId": platformId]
  716. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  717. } completion: { [weak self] (task, responseObject, error) in
  718. var dic: NSDictionary = [:]
  719. if error == nil, let responseObject = responseObject as? NSDictionary {
  720. dic = responseObject
  721. } else {
  722. var info = responseObject
  723. if let error = error {
  724. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  725. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  726. }
  727. }
  728. dic = (info as? NSDictionary) ?? [:]
  729. }
  730. let code: Int = dic["code"] as? Int ?? 0
  731. let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
  732. let message: String = dic["msg"] as? String ?? ""
  733. var results: [KMListingProductsModel] = []
  734. for dict1 in result_Array {
  735. var id = ""
  736. var productName = ""
  737. var price = ""
  738. var maxDeviceNum = 0
  739. var levels = ""
  740. var platforms = ""
  741. var productLineId = 0
  742. var paymentModel = 0
  743. var cycle = 0
  744. var code = ""
  745. var cnyPrice = ""
  746. if let token = dict1["id"] { id = token as! String }
  747. if let token = dict1["productName"] { productName = token as! String }
  748. if let token = dict1["price"] { price = token as! String }
  749. if let token = dict1["maxDeviceNum"] { maxDeviceNum = token as! Int }
  750. if let token = dict1["levels"] { levels = token as! String }
  751. if let token = dict1["platforms"] { platforms = token as! String }
  752. if let token = dict1["productLineId"] { productLineId = token as! Int }
  753. if let token = dict1["paymentModel"] { paymentModel = token as! Int }
  754. if let token = dict1["cycle"] { cycle = token as! Int }
  755. if let token = dict1["code"] { code = token as! String }
  756. if let token = dict1["cnyPrice"] { cnyPrice = token as! String }
  757. let products = KMListingProductsModel(id: id, productName: productName, price: price, maxDeviceNum: maxDeviceNum, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, code: code, cnyPrice: cnyPrice)
  758. results.append(products)
  759. }
  760. let result = KMMemberProductResult(code: code, msg: message, listingProducts: results)
  761. if code == 200 {
  762. complete(true, result)
  763. } else {
  764. complete(false, result)
  765. }
  766. }
  767. }
  768. /**
  769. @abstract 获取已登录用户购买商品价格
  770. @param productId 购买的产品id
  771. @param isEducation 是否教育优惠
  772. @param complete 回调
  773. */
  774. func getProductPriceForBuy(productId: String, isEducation: Int, userId: String, _ complete: @escaping KMMemberProductComplete) {
  775. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getProductPriceForBuy"
  776. let params: [String: Any] = ["productId": productId,
  777. "isEducation": isEducation,
  778. "userId": userId]
  779. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  780. } completion: { [weak self] (task, responseObject, error) in
  781. var dic: NSDictionary = [:]
  782. if error == nil, let responseObject = responseObject as? NSDictionary {
  783. dic = responseObject
  784. } else {
  785. var info = responseObject
  786. if let error = error {
  787. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  788. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  789. }
  790. }
  791. dic = (info as? NSDictionary) ?? [:]
  792. }
  793. let code: Int = dic["code"] as? Int ?? 0
  794. let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
  795. let message: String = dic["msg"] as? String ?? ""
  796. var results: [KMListingProductsModel] = []
  797. for dict1 in result_Array {
  798. var id = ""
  799. var productName = ""
  800. var price = ""
  801. var maxDeviceNum = 0
  802. var levels = ""
  803. var platforms = ""
  804. var productLineId = 0
  805. var paymentModel = 0
  806. var cycle = 0
  807. var code = ""
  808. var cnyPrice = ""
  809. if let token = dict1["id"] { id = token as! String }
  810. if let token = dict1["productName"] { productName = token as! String }
  811. if let token = dict1["price"] { price = token as! String }
  812. if let token = dict1["maxDeviceNum"] { maxDeviceNum = token as! Int }
  813. if let token = dict1["levels"] { levels = token as! String }
  814. if let token = dict1["platforms"] { platforms = token as! String }
  815. if let token = dict1["productLineId"] { productLineId = token as! Int }
  816. if let token = dict1["paymentModel"] { paymentModel = token as! Int }
  817. if let token = dict1["cycle"] { cycle = token as! Int }
  818. if let token = dict1["code"] { code = token as! String }
  819. if let token = dict1["cnyPrice"] { cnyPrice = token as! String }
  820. let products = KMListingProductsModel(id: id, productName: productName, price: price, maxDeviceNum: maxDeviceNum, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, code: code, cnyPrice: cnyPrice)
  821. results.append(products)
  822. }
  823. let result = KMMemberProductResult(code: code, msg: message, listingProducts: results)
  824. if code == 200 {
  825. complete(true, result)
  826. } else {
  827. complete(false, result)
  828. }
  829. }
  830. }
  831. /**
  832. @abstract 获取批量阶段购买价格
  833. @param productId 购买的产品id
  834. @param isEducation 是否教育优惠
  835. @param complete 回调
  836. */
  837. func getBatchProductPrice(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  838. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getBatchProductPrice"
  839. let params: [String: Any] = ["productId": productId,
  840. "num": num]
  841. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  842. } completion: { [weak self] (task, responseObject, error) in
  843. var dic: NSDictionary = [:]
  844. if error == nil, let responseObject = responseObject as? NSDictionary {
  845. dic = responseObject
  846. } else {
  847. var info = responseObject
  848. if let error = error {
  849. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  850. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  851. }
  852. }
  853. dic = (info as? NSDictionary) ?? [:]
  854. }
  855. let code: Int = dic["code"] as? Int ?? 0
  856. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  857. let message: String = dic["msg"] as? String ?? ""
  858. var productId = ""
  859. var totalPrice = ""
  860. var price = ""
  861. var batchPrice = ""
  862. var cnyPrice = ""
  863. var cnyBatchPrice = ""
  864. var cnyTotalPrice = ""
  865. if let token = result["productId"] { productId = token as! String }
  866. if let token = result["totalPrice"] { totalPrice = token as! String }
  867. if let token = result["price"] { price = token as! String }
  868. if let token = result["batchPrice"] { batchPrice = token as! String }
  869. if let token = result["cnyPrice"] { cnyPrice = token as! String }
  870. if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as! String }
  871. if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as! String }
  872. let products = KMBatchProductPriceModel(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
  873. let result1 = KMMemberProductResult(code: code, msg: message, batchProductPrice: products)
  874. if code == 200 {
  875. complete(true, result1)
  876. } else {
  877. complete(false, result1)
  878. }
  879. }
  880. }
  881. /**
  882. @abstract 验证商品优惠券,返回商品优惠后价格
  883. @param productId 购买的产品id
  884. @param isEducation 是否教育优惠
  885. @param complete 回调
  886. */
  887. func checkCoupon(productId: String, userId: String, code: String, _ complete: @escaping KMMemberProductComplete) {
  888. let token: String = KMMemberInfo.shared.access_token
  889. if token == "" {
  890. return
  891. }
  892. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkCoupon"
  893. let params: [String: Any] = ["productId": productId,
  894. "userId": userId,
  895. "code": code]
  896. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  897. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  898. } completion: { [weak self] (task, responseObject, error) in
  899. var dic: NSDictionary = [:]
  900. if error == nil, let responseObject = responseObject as? NSDictionary {
  901. dic = responseObject
  902. } else {
  903. var info = responseObject
  904. if let error = error {
  905. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  906. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  907. }
  908. }
  909. dic = (info as? NSDictionary) ?? [:]
  910. }
  911. let code: Int = dic["code"] as? Int ?? 0
  912. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  913. let message: String = dic["msg"] as? String ?? ""
  914. var id = ""
  915. var productName = ""
  916. var price = ""
  917. var maxDeviceNum = 0
  918. var displayPrice = ""
  919. var levels = ""
  920. var platforms = ""
  921. var productLineId = 0
  922. var paymentModel = 0
  923. var cycle = 0
  924. var cnyPrice = ""
  925. var displayCnyPrice = ""
  926. if let token = result["id"] { id = token as! String }
  927. if let token = result["productName"] { productName = token as! String }
  928. if let token = result["price"] { price = token as! String }
  929. if let token = result["maxDeviceNum"] { maxDeviceNum = token as! Int }
  930. if let token = result["displayPrice"] { displayPrice = token as! String }
  931. if let token = result["levels"] { levels = token as! String }
  932. if let token = result["platforms"] { platforms = token as! String }
  933. if let token = result["productLineId"] { productLineId = token as! Int }
  934. if let token = result["paymentModel"] { paymentModel = token as! Int }
  935. if let token = result["cycle"] { cycle = token as! Int }
  936. if let token = result["cnyPrice"] { cnyPrice = token as! String }
  937. if let token = result["displayCnyPrice"] { displayCnyPrice = token as! String }
  938. 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)
  939. let result1 = KMMemberProductResult(code: code, msg: message, checkCoupon: products)
  940. if code == 200 {
  941. complete(true, result1)
  942. } else {
  943. complete(false, result1)
  944. }
  945. }
  946. }
  947. /**
  948. @abstract 获取批量阶段购买价格
  949. @param productId 购买的产品id
  950. @param isEducation 是否教育优惠
  951. @param complete 回调
  952. */
  953. func checkEducation(email: String, _ complete: @escaping KMMemberProductComplete) {
  954. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkEducation"
  955. let params: [String: Any] = ["email": email]
  956. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  957. } completion: { [weak self] (task, responseObject, error) in
  958. var dic: NSDictionary = [:]
  959. if error == nil, let responseObject = responseObject as? NSDictionary {
  960. dic = responseObject
  961. } else {
  962. var info = responseObject
  963. if let error = error {
  964. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  965. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  966. }
  967. }
  968. dic = (info as? NSDictionary) ?? [:]
  969. }
  970. let code: Int = dic["code"] as? Int ?? 0
  971. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  972. let message: String = dic["msg"] as? String ?? ""
  973. var productId = ""
  974. var totalPrice = ""
  975. var price = ""
  976. var batchPrice = ""
  977. var cnyPrice = ""
  978. var cnyBatchPrice = ""
  979. var cnyTotalPrice = ""
  980. if let token = result["productId"] { productId = token as! String }
  981. if let token = result["totalPrice"] { totalPrice = token as! String }
  982. if let token = result["price"] { price = token as! String }
  983. if let token = result["batchPrice"] { batchPrice = token as! String }
  984. if let token = result["cnyPrice"] { cnyPrice = token as! String }
  985. if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as! String }
  986. if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as! String }
  987. let products = KMBatchProductPriceModel(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
  988. let result1 = KMMemberProductResult(code: code, msg: message, batchProductPrice: products)
  989. if code == 200 {
  990. complete(true, result1)
  991. } else {
  992. complete(false, result1)
  993. }
  994. }
  995. }
  996. // MARK: 个人中心模块
  997. // MARK: 订单模块
  998. /**
  999. @abstract 支付后查询订单状态
  1000. @param orderId 订单id
  1001. @param complete 回调
  1002. */
  1003. func getStateByOrderId(orderId: String, _ complete: @escaping KMMemberProductComplete) {
  1004. let token: String = KMMemberInfo.shared.access_token
  1005. if token == "" {
  1006. return
  1007. }
  1008. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getStateByOrderId"
  1009. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
  1010. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1011. } completion: { [weak self] (task, responseObject, error) in
  1012. var dic: NSDictionary = [:]
  1013. if error == nil, let responseObject = responseObject as? NSDictionary {
  1014. dic = responseObject
  1015. } else {
  1016. var info = responseObject
  1017. if let error = error {
  1018. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1019. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1020. }
  1021. }
  1022. dic = (info as? NSDictionary) ?? [:]
  1023. }
  1024. let code: Int = dic["code"] as? Int ?? 0
  1025. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1026. let message: String = dic["msg"] as? String ?? ""
  1027. var status = ""
  1028. if let token = result["status"] { status = token as! String }
  1029. let result1 = KMMemberProductResult(code: code, msg: message, result: status)
  1030. if code == 200 {
  1031. complete(true, result1)
  1032. } else {
  1033. complete(false, result1)
  1034. }
  1035. }
  1036. }
  1037. /**
  1038. @abstract 创建订单(买断、订阅)
  1039. @param productId 产品id
  1040. @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
  1041. @param price 价格
  1042. @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
  1043. @param couponCode 优惠卷
  1044. @param num 批量购买数量
  1045. @param complete 回调
  1046. */
  1047. func createOrder(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  1048. let token: String = KMMemberInfo.shared.access_token
  1049. if token == "" {
  1050. return
  1051. }
  1052. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/createOrder"
  1053. let params: [String: Any] = ["productId": productId,
  1054. "paymentMethod": paymentMethod,
  1055. "price": price,
  1056. "discountFlag": discountFlag,
  1057. "couponCode": couponCode,
  1058. "num": num]
  1059. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  1060. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1061. } completion: { [weak self] (task, responseObject, error) in
  1062. var dic: NSDictionary = [:]
  1063. if error == nil, let responseObject = responseObject as? NSDictionary {
  1064. dic = responseObject
  1065. } else {
  1066. var info = responseObject
  1067. if let error = error {
  1068. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1069. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1070. }
  1071. }
  1072. dic = (info as? NSDictionary) ?? [:]
  1073. }
  1074. let code: Int = dic["code"] as? Int ?? 0
  1075. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1076. let message: String = dic["msg"] as? String ?? ""
  1077. var thirdOrderNo = ""
  1078. var orderId = ""
  1079. var payHref = ""
  1080. if code == 200 {
  1081. if let token = result["thirdOrderNo"] { thirdOrderNo = token as! String }
  1082. if let token = result["orderId"] { orderId = token as! String }
  1083. if let token = result["payHref"] { payHref = token as! String }
  1084. let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
  1085. let result1 = KMMemberProductResult(code: code, msg: message, createOrder: products)
  1086. complete(true, result1)
  1087. } else {
  1088. let result1 = KMMemberProductResult(code: code, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
  1089. complete(false, result1)
  1090. }
  1091. }
  1092. }
  1093. /**
  1094. @abstract 获取订单列表
  1095. @param orderStatus 0全部1待支付
  1096. @param complete 回调
  1097. */
  1098. func getOrderListByStatus(orderStatus: Int, _ complete: @escaping KMMemberProductComplete) {
  1099. let token: String = KMMemberInfo.shared.access_token
  1100. if token == "" {
  1101. return
  1102. }
  1103. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getOrderListByStatus"
  1104. let params: [String: Any] = ["orderStatus": orderStatus]
  1105. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  1106. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1107. } completion: { [weak self] (task, responseObject, error) in
  1108. var dic: NSDictionary = [:]
  1109. if error == nil, let responseObject = responseObject as? NSDictionary {
  1110. dic = responseObject
  1111. } else {
  1112. var info = responseObject
  1113. if let error = error {
  1114. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1115. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1116. }
  1117. }
  1118. dic = (info as? NSDictionary) ?? [:]
  1119. }
  1120. let code: Int = dic["code"] as? Int ?? 0
  1121. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1122. let message: String = dic["msg"] as? String ?? ""
  1123. // var thirdOrderNo = ""
  1124. // var orderId = ""
  1125. // var payHref = ""
  1126. // if code == 200 {
  1127. // if let token = result["thirdOrderNo"] { thirdOrderNo = token as! String }
  1128. // if let token = result["orderId"] { orderId = token as! String }
  1129. // if let token = result["payHref"] { payHref = token as! String }
  1130. // let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
  1131. // let result1 = KMMemberProductResult(code: code, msg: message, createOrder: products)
  1132. // complete(true, result1)
  1133. // } else {
  1134. // let result1 = KMMemberProductResult(code: code, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
  1135. // complete(false, result1)
  1136. // }
  1137. }
  1138. }
  1139. // MARK: 评估模块
  1140. // MARK: 活动模块
  1141. // MARK: 翻译模块
  1142. // MARK: AI模块
  1143. // MARK: 会员赠送模块
  1144. // MARK: Error Code
  1145. static func typeOfMessage(type: KMMemberCenterErrorCodeType?) -> String {
  1146. var result: String = ""
  1147. switch type {
  1148. case .EXCEPTION_MSG_TOKEN_IS_INVALID:
  1149. result = "无效的token或者token已过期"
  1150. break;
  1151. case .EXCEPTION_MSG_DEVICE_NUM_MAX:
  1152. result = "您的登录设备已达上限,请退出其他设备重新登录"
  1153. break;
  1154. case .EXCEPTION_MSG_USER_NOT_LOGIN:
  1155. result = "用户没有登录,请登录后再访问"
  1156. break;
  1157. case .EMAIL_VERIFY_CODE_KEY_ERROR:
  1158. result = "email code error!"
  1159. break;
  1160. case .EMAIL_REGISTER_ERROR:
  1161. result = "Register error!"
  1162. break;
  1163. case .EXCEPTION_MSG_PASSWORD_ERROR:
  1164. result = "密码错误,您可以检查大小写状态"
  1165. break;
  1166. case .EXCEPTION_MSG_CODE_ACTION_ERROR:
  1167. result = "code action error"
  1168. break;
  1169. case .EXCEPTION_MSG_CODE_SEND_ERROR:
  1170. result = "code send error"
  1171. break;
  1172. case .EXCEPTION_MAIL_CODE_SEND_ERROR:
  1173. result = "mail send error"
  1174. break;
  1175. case .VERIFY_CODE_SEND_TOO_QUICKLY:
  1176. result = "code send too quickly"
  1177. break;
  1178. case .EXCEPTION_MSG_EMAIL_EXIST:
  1179. result = "该邮箱已有账号,请前往登录"
  1180. break;
  1181. case .EXCEPTION_MSG_EMAIL_NOT_REGISTER:
  1182. result = "当前账号未注册,点击下一步我们将为您注册账号"
  1183. break;
  1184. case .EXCEPTION_MSG_EMAIL_LOGOUT_ING:
  1185. result = "注销中,无法登录,若有问题可联系客服"
  1186. break;
  1187. case .EXCEPTION_MSG_EMAIL_INVALID:
  1188. result = "请输入正确的邮箱格式"
  1189. break;
  1190. case .EXCEPTION_MSG_PASSWORD_NOT_INCONSISTENT:
  1191. result = "密码不一致,请重新输入"
  1192. break;
  1193. case .EXCEPTION_MSG_PASSWORD_SIZE_MIN:
  1194. result = "密码请包含6~24个字符"
  1195. break;
  1196. case .EXCEPTION_MSG_PASSWORD_SIZE_MAX:
  1197. result = "密码请包含6~24个字符"
  1198. break;
  1199. case .EXCEPTION_MSG_PLEASE_ADD_AUTH_CONFIG:
  1200. result = "please add auth config"
  1201. break;
  1202. case .EXCEPTION_MSG_USER_SUBSCRIPTION_IN_PROGRESS:
  1203. result = "您目前还在订阅期内,暂时无法注销,请订阅期结束后再点击注销账号"
  1204. break;
  1205. case .EXCEPTION_TIME_TRANSFER_ERROR:
  1206. result = "时间转换失败"
  1207. break;
  1208. case .EXCEPTION_MSG_PASSWORD_CONTAIN_EMPTY:
  1209. result = "密码不能包含空格"
  1210. break;
  1211. case .UNKNOWN:
  1212. result = "UNKNOWN"
  1213. break;
  1214. case .SUCCESS:
  1215. result = "SUCCESS"
  1216. break;
  1217. default:
  1218. result = "Network error"
  1219. }
  1220. return result
  1221. }
  1222. }