KMMemberCenterManager.swift 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  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. class KMMemberCenterManager: NSObject {
  50. static let manager = KMMemberCenterManager()
  51. private let configuration: KMMemberCenterConfig = KMMemberCenterConfig()
  52. // MARK: 登录模块
  53. /**
  54. @abstract 新会员系统重置密码
  55. @param email 邮箱
  56. @param verifyCode 验证码
  57. @param password 密码
  58. @param complete 回调
  59. */
  60. func resetPassword(email: String, verifyCode: String, password: String, _ complete: @escaping KMMemberCenterComplete) {
  61. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/memberResetPassword"
  62. let params: [String: Any] = ["email": email,
  63. "verifyCode": verifyCode,
  64. "appId": "1",
  65. "password": password]
  66. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  67. } completion: { [weak self] (task, responseObject, error) in
  68. var dic: NSDictionary = [:]
  69. if error == nil, let responseObject = responseObject as? NSDictionary {
  70. dic = responseObject
  71. } else {
  72. var info = responseObject
  73. if let error = error {
  74. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  75. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  76. }
  77. }
  78. dic = (info as? NSDictionary) ?? [:]
  79. }
  80. let code: Int = dic["code"] as? Int ?? 0
  81. let result_bool: Bool = dic["result"] as? Bool ?? false
  82. let message: String = dic["msg"] as? String ?? ""
  83. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  84. // let error = NSError(domain: message, code: code)
  85. if code == 200 {
  86. complete(true, result)
  87. } else {
  88. complete(false, result)
  89. }
  90. }
  91. }
  92. /**
  93. @abstract 验证邮箱(重置密码输入邮箱点击下一步时校验邮箱是否注册)
  94. @param email 邮箱
  95. @param complete 回调
  96. */
  97. func emailVerification(email: String, _ complete: @escaping KMMemberCenterComplete) {
  98. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/validEmail"
  99. let params: [String: Any] = ["email": email]
  100. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  101. } completion: { [weak self] (task, responseObject, error) in
  102. var dic: NSDictionary = [:]
  103. if error == nil, let responseObject = responseObject as? NSDictionary {
  104. dic = responseObject
  105. } else {
  106. var info = responseObject
  107. if let error = error {
  108. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  109. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  110. }
  111. }
  112. dic = (info as? NSDictionary) ?? [:]
  113. }
  114. let code: Int = dic["code"] as? Int ?? 0
  115. let result_bool: Bool = dic["result"] as? Bool ?? false
  116. let message: String = dic["msg"] as? String ?? ""
  117. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  118. // let error = NSError(domain: message, code: code)
  119. if code == 200 {
  120. complete(true, result)
  121. } else {
  122. complete(false, result)
  123. }
  124. }
  125. }
  126. /**
  127. @abstract 获取邮箱验证码
  128. @param action 验证码用途
  129. @param receiver 邮箱号
  130. @param complete 回调
  131. */
  132. func getVerificationCode(action: KMVerificationCodeType, receiver: String, _ complete: @escaping KMMemberCenterComplete) {
  133. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/getVerifyCode"
  134. var actionType = "member_login"
  135. if action == .reset {
  136. actionType = "member_reset_password"
  137. } else if action == .logout {
  138. actionType = "user_log_off"
  139. }
  140. let params: [String: Any] = ["action": actionType,
  141. "type": 0,
  142. "receiver": receiver,
  143. "appId": "1"]
  144. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  145. } completion: { [weak self] (task, responseObject, error) in
  146. var dic: NSDictionary = [:]
  147. if error == nil, let responseObject = responseObject as? NSDictionary {
  148. dic = responseObject
  149. } else {
  150. var info = responseObject
  151. if let error = error {
  152. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  153. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  154. }
  155. }
  156. dic = (info as? NSDictionary) ?? [:]
  157. }
  158. let code: Int = dic["code"] as? Int ?? 0
  159. let result_bool: Bool = dic["result"] as? Bool ?? false
  160. let message: String = dic["msg"] as? String ?? ""
  161. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  162. // let error = NSError(domain: message, code: code)
  163. if code == 200 {
  164. complete(true, result)
  165. } else {
  166. complete(false, result)
  167. }
  168. }
  169. }
  170. /**
  171. @abstract 实时检查邮件验证码
  172. @param type 验证码用途
  173. @param account 账户
  174. @param code 验证码
  175. @param complete 回调
  176. */
  177. func checkVerificationCode(type: KMVerificationCodeType, account: String, code: String, _ complete: @escaping KMMemberCenterComplete) {
  178. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/isEmailCodeValid"
  179. var actionType = "member_login"
  180. if type == .reset {
  181. actionType = "member_reset_password"
  182. } else if type == .logout {
  183. actionType = "user_log_off"
  184. }
  185. let params: [String: Any] = ["type": actionType,
  186. "account": account,
  187. "code": code,
  188. "appId": "1"]
  189. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  190. } completion: { [weak self] (task, responseObject, error) in
  191. var dic: NSDictionary = [:]
  192. if error == nil, let responseObject = responseObject as? NSDictionary {
  193. dic = responseObject
  194. } else {
  195. var info = responseObject
  196. if let error = error {
  197. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  198. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  199. }
  200. }
  201. dic = (info as? NSDictionary) ?? [:]
  202. }
  203. let code: Int = dic["code"] as? Int ?? 0
  204. let result_bool: Bool = dic["result"] as? Bool ?? false
  205. let message: String = dic["msg"] as? String ?? ""
  206. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  207. // let error = NSError(domain: message, code: code)
  208. if code == 200 {
  209. complete(true, result)
  210. } else {
  211. complete(false, result)
  212. }
  213. }
  214. }
  215. /**
  216. @abstract 邮箱验证码登录 & 密码登录
  217. @param email 邮箱
  218. @param code 验证码/密码
  219. @param complete 回调
  220. */
  221. func emailLogin(email: String, code: String, _ complete: @escaping KMMemberCenterComplete) {
  222. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/memberLogin"
  223. let uuid: String = GetHardwareUUID() ?? ""
  224. let params: [String: Any] = ["email": email,
  225. "code": code,
  226. "appId": "1",
  227. "deviceSign": uuid,
  228. "deviceName": NSFullUserName(),
  229. "model": "mac"]
  230. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  231. // requestSerializer.setValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  232. } completion: { [weak self] (task, responseObject, error) in
  233. var dic: NSDictionary = [:]
  234. if error == nil, let responseObject = responseObject as? NSDictionary {
  235. dic = responseObject
  236. } else {
  237. var info = responseObject
  238. if let error = error {
  239. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  240. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  241. }
  242. }
  243. dic = (info as? NSDictionary) ?? [:]
  244. }
  245. let code: Int = dic["code"] as? Int ?? 0
  246. let result_dict: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  247. let message: String = dic["msg"] as? String ?? ""
  248. var refresh_token = ""
  249. var access_token = ""
  250. var token_type = ""
  251. var expires_in = ""
  252. var scope = ""
  253. if let token = result_dict["refresh_token"] { refresh_token = token as! String }
  254. if let token = result_dict["access_token"] { access_token = token as! String }
  255. if let token = result_dict["token_type"] { token_type = token as! String }
  256. if let token = result_dict["expires_in"] { expires_in = token as! String }
  257. let loginResult = KMMemberLoginResult(refreshToken: refresh_token, accessToken: access_token, tokenType: token_type, expiresIn: expires_in)
  258. let result = KMMemberCenterResult(loginResult: loginResult)
  259. result.code = code
  260. result.msg = message
  261. // let error = NSError(domain: message, code: code)
  262. if code == 200 {
  263. complete(true, result)
  264. } else {
  265. complete(false, result)
  266. }
  267. }
  268. }
  269. /**
  270. @abstract 获取用户登录设备列表
  271. @param email 邮箱
  272. @param complete 回调
  273. */
  274. func getUserDeviceList(email: String, _ complete: @escaping KMMemberCenterComplete) {
  275. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/getLoginDeviceList"
  276. let params: [String: Any] = ["email": email,
  277. "appId": "1"]
  278. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  279. } completion: { [weak self] (task, responseObject, error) in
  280. var dic: NSDictionary = [:]
  281. if error == nil, let responseObject = responseObject as? NSDictionary {
  282. dic = responseObject
  283. } else {
  284. var info = responseObject
  285. if let error = error {
  286. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  287. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  288. }
  289. }
  290. dic = (info as? NSDictionary) ?? [:]
  291. }
  292. let code: Int = dic["code"] as? Int ?? 0
  293. let result_dict: Dictionary = dic["result"] as? Dictionary ?? [:]
  294. let message: String = dic["msg"] as? String ?? ""
  295. let deviceList: [Dictionary] = result_dict["deviceList"] as? [Dictionary] ?? [[:]]
  296. var deviceLists: [KMMemberDeviceList] = []
  297. for dict in deviceList {
  298. var device_id = ""
  299. var productId = ""
  300. var uniqueSn = ""
  301. var deviceName = ""
  302. if let token = dict["device_id"] { device_id = token as! String }
  303. if let token = dict["productId"] { productId = token as! String }
  304. if let token = dict["uniqueSn"] { uniqueSn = token as! String }
  305. if let token = dict["deviceName"] { deviceName = token as! String }
  306. let list = KMMemberDeviceList(deviceId: device_id, productId: productId, uniqueSn: uniqueSn, appId: deviceName)
  307. deviceLists.append(list)
  308. }
  309. var maxDeviceNum = 0
  310. if let token = result_dict["maxDeviceNum"] {
  311. maxDeviceNum = token as! Int
  312. }
  313. let result = KMMemberCenterResult(deviceListResult: deviceLists, maxDeviceNum: maxDeviceNum)
  314. if code == 200 {
  315. complete(true, result)
  316. } else {
  317. complete(false, result)
  318. }
  319. }
  320. }
  321. /**
  322. @abstract 登出用户的指定设备
  323. @param deviceId 设备记录ID
  324. @param complete 回调
  325. */
  326. func logoutDevice(deviceId: String, complete: @escaping KMMemberCenterComplete) {
  327. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/logoutDevice"
  328. let params: [String: Any] = ["deviceId": deviceId]
  329. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  330. } completion: { [weak self] (task, responseObject, error) in
  331. var dic: NSDictionary = [:]
  332. if error == nil, let responseObject = responseObject as? NSDictionary {
  333. dic = responseObject
  334. } else {
  335. var info = responseObject
  336. if let error = error {
  337. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  338. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  339. }
  340. }
  341. dic = (info as? NSDictionary) ?? [:]
  342. }
  343. let code: Int = dic["code"] as? Int ?? 0
  344. let resultStr: String = dic["result"] as? String ?? ""
  345. let message: String = dic["msg"] as? String ?? ""
  346. let result = KMMemberCenterResult(code: code, msg: message, resultStr: resultStr)
  347. if code == 200 {
  348. complete(true, result)
  349. } else {
  350. complete(false, result)
  351. }
  352. }
  353. }
  354. // MARK: 个人信息模块
  355. /**
  356. @abstract 获取老带新已邀请人数
  357. @param complete 回调
  358. */
  359. func getInviteNum(_ complete: @escaping KMMemberCenterComplete) {
  360. let token: String = KMMemberInfo.shared.access_token
  361. if token == "" {
  362. return
  363. }
  364. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/getInviteNum"
  365. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  366. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  367. } completion: { [weak self] (task, responseObject, error) in
  368. var dic: NSDictionary = [:]
  369. if error == nil, let responseObject = responseObject as? NSDictionary {
  370. dic = responseObject
  371. } else {
  372. var info = responseObject
  373. if let error = error {
  374. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  375. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  376. }
  377. }
  378. dic = (info as? NSDictionary) ?? [:]
  379. }
  380. let code: Int = dic["code"] as? Int ?? 0
  381. let resultInt: Int = dic["result"] as? Int ?? 0
  382. let message: String = dic["msg"] as? String ?? ""
  383. let result = KMMemberCenterResult(code: code, msg: message, resultInt: resultInt)
  384. if code == 200 {
  385. complete(true, result)
  386. } else {
  387. complete(false, result)
  388. }
  389. }
  390. }
  391. /**
  392. @abstract 获取用户个人信息
  393. @param complete 回调
  394. */
  395. func userInfo(_ complete: @escaping KMMemberCenterComplete) {
  396. let token: String = KMMemberInfo.shared.access_token
  397. if token == "" {
  398. return
  399. }
  400. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/info"
  401. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
  402. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  403. } completion: { [weak self] (task, responseObject, error) in
  404. var dic: NSDictionary = [:]
  405. if error == nil, let responseObject = responseObject as? NSDictionary {
  406. dic = responseObject
  407. } else {
  408. var info = responseObject
  409. if let error = error {
  410. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  411. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  412. }
  413. }
  414. dic = (info as? NSDictionary) ?? [:]
  415. }
  416. let code: Int = dic["code"] as? Int ?? 0
  417. let result_dict: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  418. let message: String = dic["msg"] as? String ?? ""
  419. var userId = ""
  420. var email = ""
  421. var fullName = ""
  422. var activeVIP = KMMemberUserInfo()
  423. var aiPoint = 0
  424. var validFlag = ""
  425. var isHaveAIDiscount = ""
  426. var canTrail = ""
  427. if let token = result_dict["id"] { userId = token as! String }
  428. if let token = result_dict["email"] { email = token as! String }
  429. if let token = result_dict["fullName"] { fullName = token as! String }
  430. let activeVIP_dict: NSDictionary = result_dict["activeVIP"] as? NSDictionary ?? [:]
  431. var activeVIP_id = ""
  432. var activeVIP_userId = ""
  433. var activeVIP_status = 0
  434. var activeVIP_endDate = ""
  435. var activeVIP_payType = 0
  436. var activeVIP_productName = ""
  437. var activeVIP_levels = ""
  438. var activeVIP_platforms = ""
  439. var activeVIP_point = 0
  440. var activeVIP_maxDeviceNum = 0
  441. var activeVIP_paymentModel = ""
  442. var activeVIP_isAi = ""
  443. if let token = activeVIP_dict["id"] { activeVIP_id = token as! String }
  444. if let token = activeVIP_dict["userId"] { activeVIP_userId = token as! String }
  445. if let token = activeVIP_dict["status"] { activeVIP_status = token as! Int }
  446. if let token = activeVIP_dict["endDate"] { activeVIP_endDate = token as! String }
  447. if let token = activeVIP_dict["payType"] { activeVIP_payType = token as! Int }
  448. if let token = activeVIP_dict["productName"] { activeVIP_productName = token as! String }
  449. if let token = activeVIP_dict["levels"] { activeVIP_levels = token as! String }
  450. if let token = activeVIP_dict["platforms"] { activeVIP_platforms = token as! String }
  451. if let token = activeVIP_dict["point"] { activeVIP_point = token as! Int }
  452. if let token = activeVIP_dict["maxDeviceNum"] { activeVIP_maxDeviceNum = token as! Int }
  453. if let token = activeVIP_dict["paymentModel"] { activeVIP_paymentModel = token as! String }
  454. if let token = activeVIP_dict["isAi"] { activeVIP_isAi = token as! String }
  455. 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)
  456. if let token = result_dict["aiPoint"] { aiPoint = token as! Int }
  457. if let token = result_dict["validFlag"] { validFlag = token as! String }
  458. if let token = result_dict["isHaveAIDiscount"] { isHaveAIDiscount = token as! String }
  459. if let token = result_dict["canTrail"] { canTrail = token as! String }
  460. let userInfo = KMMemberUserInfo(id: userId, email: email, fullName: fullName, activeVIP: [userInfoActiveVIP], aiPoint: aiPoint, validFlag: validFlag, isHaveAIDiscount: isHaveAIDiscount, canTrail: canTrail)
  461. let result = KMMemberCenterResult(code: code, msg: message, userInfo: userInfo)
  462. // let error = NSError(domain: message, code: code)
  463. if code == 200 {
  464. complete(true, result)
  465. } else {
  466. complete(false, result)
  467. }
  468. }
  469. }
  470. /**
  471. @abstract 退出登录
  472. @param complete 回调
  473. */
  474. func userLogout(_ complete: @escaping KMMemberCenterComplete) {
  475. let token: String = KMMemberInfo.shared.access_token
  476. if token == "" {
  477. return
  478. }
  479. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/logout"
  480. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  481. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  482. } completion: { [weak self] (task, responseObject, error) in
  483. var dic: NSDictionary = [:]
  484. if error == nil, let responseObject = responseObject as? NSDictionary {
  485. dic = responseObject
  486. } else {
  487. var info = responseObject
  488. if let error = error {
  489. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  490. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  491. }
  492. }
  493. dic = (info as? NSDictionary) ?? [:]
  494. }
  495. let code: Int = dic["code"] as? Int ?? 0
  496. let result_bool: Bool = dic["result"] as? Bool ?? false
  497. let message: String = dic["msg"] as? String ?? ""
  498. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  499. if code == 200 {
  500. complete(true, result)
  501. } else {
  502. complete(false, result)
  503. }
  504. }
  505. }
  506. /**
  507. @abstract 获取用户当前会员情况
  508. @param complete 回调
  509. */
  510. func userRightList(_ complete: @escaping KMMemberCenterComplete) {
  511. let token: String = KMMemberInfo.shared.access_token
  512. if token == "" {
  513. return
  514. }
  515. let urlString = configuration.activityBaseURL() + "/member-system-sso//user/rightList"
  516. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
  517. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  518. } completion: { [weak self] (task, responseObject, error) in
  519. var dic: NSDictionary = [:]
  520. if error == nil, let responseObject = responseObject as? NSDictionary {
  521. dic = responseObject
  522. } else {
  523. var info = responseObject
  524. if let error = error {
  525. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  526. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  527. }
  528. }
  529. dic = (info as? NSDictionary) ?? [:]
  530. }
  531. let code: Int = dic["code"] as? Int ?? 0
  532. let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
  533. let message: String = dic["msg"] as? String ?? ""
  534. var results: [KMMemberUserInfoActiveVIP] = []
  535. for dict1 in result_Array {
  536. var activeVIP_id = ""
  537. var activeVIP_userId = ""
  538. var activeVIP_status = 0
  539. var activeVIP_endDate = ""
  540. var activeVIP_payType = 0
  541. var activeVIP_productName = ""
  542. var activeVIP_levels = ""
  543. var activeVIP_platforms = ""
  544. var activeVIP_point = 0
  545. var activeVIP_maxDeviceNum = 0
  546. var activeVIP_paymentModel = ""
  547. var activeVIP_isAi = ""
  548. if let token = dict1["id"] { activeVIP_id = token as! String }
  549. if let token = dict1["userId"] { activeVIP_userId = token as! String }
  550. if let token = dict1["status"] { activeVIP_status = token as! Int }
  551. if let token = dict1["endDate"] { activeVIP_endDate = token as! String }
  552. if let token = dict1["payType"] { activeVIP_payType = token as! Int }
  553. if let token = dict1["productName"] { activeVIP_productName = token as! String }
  554. if let token = dict1["levels"] { activeVIP_levels = token as! String }
  555. if let token = dict1["platforms"] { activeVIP_platforms = token as! String }
  556. if let token = dict1["point"] { activeVIP_point = token as! Int }
  557. if let token = dict1["maxDeviceNum"] { activeVIP_maxDeviceNum = token as! Int }
  558. if let token = dict1["paymentModel"] { activeVIP_paymentModel = token as! String }
  559. if let token = dict1["isAi"] { activeVIP_isAi = token as! String }
  560. 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)
  561. results.append(userInfoActiveVIP)
  562. }
  563. let result = KMMemberCenterResult(code: code, msg: message, activeVIPs: results)
  564. if code == 200 {
  565. complete(true, result)
  566. } else {
  567. complete(false, result)
  568. }
  569. }
  570. }
  571. /**
  572. @abstract 用户手动注销
  573. @param code 邮箱验证码
  574. @param complete 回调
  575. */
  576. func userLogOffForUser(code: String, _ complete: @escaping KMMemberCenterComplete) {
  577. let token: String = KMMemberInfo.shared.access_token
  578. if token == "" {
  579. return
  580. }
  581. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/logOffForUser"
  582. let params: [String: Any] = ["code": code,
  583. "appId": "1"]
  584. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  585. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  586. } completion: { [weak self] (task, responseObject, error) in
  587. var dic: NSDictionary = [:]
  588. if error == nil, let responseObject = responseObject as? NSDictionary {
  589. dic = responseObject
  590. } else {
  591. var info = responseObject
  592. if let error = error {
  593. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  594. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  595. }
  596. }
  597. dic = (info as? NSDictionary) ?? [:]
  598. }
  599. let code: Int = dic["code"] as? Int ?? 0
  600. let message: String = dic["msg"] as? String ?? ""
  601. let result_dict: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  602. var currentTime = ""
  603. var logOffTime = ""
  604. if let token = result_dict["currentTime"] { currentTime = token as! String }
  605. if let token = result_dict["logOffTime"] { logOffTime = token as! String }
  606. let logOff = KMMemberLogOff(currentTime: currentTime, logOffTime: logOffTime)
  607. let result = KMMemberCenterResult(code: code, msg: message, logOff: logOff)
  608. if code == 200 {
  609. complete(true, result)
  610. } else {
  611. complete(false, result)
  612. }
  613. }
  614. }
  615. /**
  616. @abstract 撤销注销申请
  617. @param complete 回调
  618. */
  619. func userRevokeCancel(_ complete: @escaping KMMemberCenterComplete) {
  620. let token: String = KMMemberInfo.shared.access_token
  621. if token == "" {
  622. return
  623. }
  624. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/revokeCancel"
  625. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  626. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  627. } completion: { [weak self] (task, responseObject, error) in
  628. var dic: NSDictionary = [:]
  629. if error == nil, let responseObject = responseObject as? NSDictionary {
  630. dic = responseObject
  631. } else {
  632. var info = responseObject
  633. if let error = error {
  634. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  635. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  636. }
  637. }
  638. dic = (info as? NSDictionary) ?? [:]
  639. }
  640. let code: Int = dic["code"] as? Int ?? 0
  641. let message: String = dic["msg"] as? String ?? ""
  642. let result_Bool: Bool = dic["result"] as? Bool ?? false
  643. let result = KMMemberCenterResult(code: code, msg: message, result: result_Bool)
  644. if code == 200 {
  645. complete(true, result)
  646. } else {
  647. complete(false, result)
  648. }
  649. }
  650. }
  651. // MARK: 商品模块
  652. // /**
  653. // @abstract 获取上架中的产品
  654. // @param complete 回调
  655. // */
  656. // func getListingProducts(_ complete: @escaping KMMemberCenterComplete) {
  657. //
  658. // let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getListingProducts"
  659. // let params: [String: Any] = ["isEducation": actionType,
  660. // "platformId": 0]
  661. // KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
  662. //
  663. // } completion: { [weak self] (task, responseObject, error) in
  664. // var dic: NSDictionary = [:]
  665. // if error == nil, let responseObject = responseObject as? NSDictionary {
  666. // dic = responseObject
  667. // } else {
  668. // var info = responseObject
  669. // if let error = error {
  670. // if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  671. // info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  672. // }
  673. // }
  674. // dic = (info as? NSDictionary) ?? [:]
  675. // }
  676. // let code: Int = dic["code"] as? Int ?? 0
  677. // let message: String = dic["msg"] as? String ?? ""
  678. // let result_Bool: Bool = dic["result"] as? Bool ?? false
  679. //
  680. // let result = KMMemberCenterResult(code: code, msg: message, result: result_Bool)
  681. // if code == 200 {
  682. // complete(true, result)
  683. // } else {
  684. // complete(false, result)
  685. // }
  686. // }
  687. // }
  688. // MARK: 个人中心模块
  689. // MARK: 订单模块
  690. // MARK: 评估模块
  691. // MARK: 活动模块
  692. // MARK: 翻译模块
  693. // MARK: AI模块
  694. // MARK: 会员赠送模块
  695. // MARK: Error Code
  696. static func typeOfMessage(type: KMMemberCenterErrorCodeType?) -> String {
  697. var result: String = ""
  698. switch type {
  699. case .EXCEPTION_MSG_TOKEN_IS_INVALID:
  700. result = "无效的token或者token已过期"
  701. break;
  702. case .EXCEPTION_MSG_DEVICE_NUM_MAX:
  703. result = "您的登录设备已达上限,请退出其他设备重新登录"
  704. break;
  705. case .EXCEPTION_MSG_USER_NOT_LOGIN:
  706. result = "用户没有登录,请登录后再访问"
  707. break;
  708. case .EMAIL_VERIFY_CODE_KEY_ERROR:
  709. result = "email code error!"
  710. break;
  711. case .EMAIL_REGISTER_ERROR:
  712. result = "Register error!"
  713. break;
  714. case .EXCEPTION_MSG_PASSWORD_ERROR:
  715. result = "密码错误,您可以检查大小写状态"
  716. break;
  717. case .EXCEPTION_MSG_CODE_ACTION_ERROR:
  718. result = "code action error"
  719. break;
  720. case .EXCEPTION_MSG_CODE_SEND_ERROR:
  721. result = "code send error"
  722. break;
  723. case .EXCEPTION_MAIL_CODE_SEND_ERROR:
  724. result = "mail send error"
  725. break;
  726. case .VERIFY_CODE_SEND_TOO_QUICKLY:
  727. result = "code send too quickly"
  728. break;
  729. case .EXCEPTION_MSG_EMAIL_EXIST:
  730. result = "该邮箱已有账号,请前往登录"
  731. break;
  732. case .EXCEPTION_MSG_EMAIL_NOT_REGISTER:
  733. result = "当前账号未注册,点击下一步我们将为您注册账号"
  734. break;
  735. case .EXCEPTION_MSG_EMAIL_LOGOUT_ING:
  736. result = "注销中,无法登录,若有问题可联系客服"
  737. break;
  738. case .EXCEPTION_MSG_EMAIL_INVALID:
  739. result = "请输入正确的邮箱格式"
  740. break;
  741. case .EXCEPTION_MSG_PASSWORD_NOT_INCONSISTENT:
  742. result = "密码不一致,请重新输入"
  743. break;
  744. case .EXCEPTION_MSG_PASSWORD_SIZE_MIN:
  745. result = "密码请包含6~24个字符"
  746. break;
  747. case .EXCEPTION_MSG_PASSWORD_SIZE_MAX:
  748. result = "密码请包含6~24个字符"
  749. break;
  750. case .EXCEPTION_MSG_PLEASE_ADD_AUTH_CONFIG:
  751. result = "please add auth config"
  752. break;
  753. case .EXCEPTION_MSG_USER_SUBSCRIPTION_IN_PROGRESS:
  754. result = "您目前还在订阅期内,暂时无法注销,请订阅期结束后再点击注销账号"
  755. break;
  756. case .EXCEPTION_TIME_TRANSFER_ERROR:
  757. result = "时间转换失败"
  758. break;
  759. case .EXCEPTION_MSG_PASSWORD_CONTAIN_EMPTY:
  760. result = "密码不能包含空格"
  761. break;
  762. case .UNKNOWN:
  763. result = "UNKNOWN"
  764. break;
  765. case .SUCCESS:
  766. result = "SUCCESS"
  767. break;
  768. default:
  769. result = "Network error"
  770. }
  771. return result
  772. }
  773. }