KMMemberCenterManager.swift 60 KB

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