KMMemberCenterManager.swift 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  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"] as? String { activeVIP_id = token }
  445. if let token = activeVIP_dict["userId"] as? String { activeVIP_userId = token }
  446. if let token = activeVIP_dict["status"] as? Int { activeVIP_status = token }
  447. if let token = activeVIP_dict["endDate"] as? String { activeVIP_endDate = token }
  448. if let token = activeVIP_dict["payType"] as? Int { activeVIP_payType = token }
  449. if let token = activeVIP_dict["productName"] as? String { activeVIP_productName = token }
  450. if let token = activeVIP_dict["levels"] as? String { activeVIP_levels = token }
  451. if let token = activeVIP_dict["platforms"] as? String { activeVIP_platforms = token }
  452. if let token = activeVIP_dict["point"] as? Int { activeVIP_point = token }
  453. if let token = activeVIP_dict["maxDeviceNum"] as? Int { activeVIP_maxDeviceNum = token }
  454. if let token = activeVIP_dict["paymentModel"] as? String { activeVIP_paymentModel = token }
  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. let activeAI_dict: NSDictionary = result_dict["activeAI"] as? NSDictionary ?? [:]
  458. var activeAI_id = ""
  459. var activeAI_userId = ""
  460. var activeAI_status = 0
  461. var activeAI_endDate = ""
  462. var activeAI_payType = 0
  463. var activeAI_productName = ""
  464. var activeAI_levels = ""
  465. var activeAI_platforms = ""
  466. var activeAI_point = 0
  467. var activeAI_maxDeviceNum = 0
  468. var activeAI_paymentModel = ""
  469. var activeAI_isAi = ""
  470. if let token = activeAI_dict["id"] as? String { activeAI_id = token }
  471. if let token = activeAI_dict["userId"] as? String { activeAI_userId = token }
  472. if let token = activeAI_dict["status"] as? Int { activeAI_status = token }
  473. if let token = activeAI_dict["endDate"] as? String { activeAI_endDate = token }
  474. if let token = activeAI_dict["payType"] as? Int { activeAI_payType = token }
  475. if let token = activeAI_dict["productName"] as? String { activeAI_productName = token }
  476. if let token = activeAI_dict["levels"] as? String { activeAI_levels = token }
  477. if let token = activeAI_dict["platforms"] as? String { activeAI_platforms = token }
  478. if let token = activeAI_dict["point"] as? Int { activeAI_point = token }
  479. if let token = activeAI_dict["maxDeviceNum"] as? Int { activeAI_maxDeviceNum = token }
  480. if let token = activeAI_dict["paymentModel"] as? String { activeAI_paymentModel = token }
  481. if let token = activeAI_dict["isAi"] as? String { activeAI_isAi = token }
  482. let userInfoActiveAI = KMMemberUserInfoActiveVIP(id: activeAI_id, userId: activeAI_userId, status: activeAI_status, endDate: activeAI_endDate, payType: activeAI_payType, productName: activeAI_productName, levels: activeAI_levels, platforms: activeAI_platforms, point: activeAI_point, maxDeviceNum: activeAI_maxDeviceNum, paymentModel: activeAI_paymentModel, isAi: activeAI_isAi)
  483. if let token = result_dict["aiPoint"] { aiPoint = token as! Int }
  484. if let token = result_dict["validFlag"] { validFlag = token as! String }
  485. if let token = result_dict["isHaveAIDiscount"] { isHaveAIDiscount = token as! String }
  486. if let token = result_dict["canTrail"] { canTrail = token as! String }
  487. let userInfo = KMMemberUserInfo(id: userId, email: email, fullName: fullName, activeVIP: [userInfoActiveVIP], activeAI: [userInfoActiveAI], aiPoint: aiPoint, validFlag: validFlag, isHaveAIDiscount: isHaveAIDiscount, canTrail: canTrail)
  488. let result = KMMemberCenterResult(code: code, msg: message, userInfo: userInfo)
  489. // let error = NSError(domain: message, code: code)
  490. if code == 200 {
  491. complete(true, result)
  492. } else {
  493. complete(false, result)
  494. }
  495. }
  496. }
  497. /**
  498. @abstract 退出登录
  499. @param complete 回调
  500. */
  501. func userLogout(_ complete: @escaping KMMemberCenterComplete) {
  502. let token: String = KMMemberInfo.shared.access_token
  503. if token == "" {
  504. return
  505. }
  506. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/logout"
  507. let uuid: String = GetHardwareUUID() ?? ""
  508. let params: [String: Any] = ["deviceSign": uuid,
  509. "appId": "1"]
  510. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  511. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  512. } completion: { [weak self] (task, responseObject, error) in
  513. var dic: NSDictionary = [:]
  514. if error == nil, let responseObject = responseObject as? NSDictionary {
  515. dic = responseObject
  516. } else {
  517. var info = responseObject
  518. if let error = error {
  519. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  520. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  521. }
  522. }
  523. dic = (info as? NSDictionary) ?? [:]
  524. }
  525. let code: Int = dic["code"] as? Int ?? 0
  526. let result_bool: Bool = dic["result"] as? Bool ?? false
  527. let message: String = dic["msg"] as? String ?? ""
  528. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  529. if code == 200 {
  530. complete(true, result)
  531. } else {
  532. complete(false, result)
  533. }
  534. }
  535. }
  536. /**
  537. @abstract 获取用户当前会员情况
  538. @param complete 回调
  539. */
  540. func userRightList(_ complete: @escaping KMMemberCenterComplete) {
  541. let token: String = KMMemberInfo.shared.access_token
  542. if token == "" {
  543. return
  544. }
  545. let urlString = configuration.activityBaseURL() + "/member-system-sso//user/rightList"
  546. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
  547. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  548. } completion: { [weak self] (task, responseObject, error) in
  549. var dic: NSDictionary = [:]
  550. if error == nil, let responseObject = responseObject as? NSDictionary {
  551. dic = responseObject
  552. } else {
  553. var info = responseObject
  554. if let error = error {
  555. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  556. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  557. }
  558. }
  559. dic = (info as? NSDictionary) ?? [:]
  560. }
  561. let code: Int = dic["code"] as? Int ?? 0
  562. let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
  563. let message: String = dic["msg"] as? String ?? ""
  564. var results: [KMMemberUserInfoActiveVIP] = []
  565. for dict1 in result_Array {
  566. var activeVIP_id = ""
  567. var activeVIP_userId = ""
  568. var activeVIP_status = 0
  569. var activeVIP_endDate = ""
  570. var activeVIP_payType = 0
  571. var activeVIP_productName = ""
  572. var activeVIP_levels = ""
  573. var activeVIP_platforms = ""
  574. var activeVIP_point = 0
  575. var activeVIP_maxDeviceNum = 0
  576. var activeVIP_paymentModel = ""
  577. var activeVIP_isAi = ""
  578. if let token = dict1["id"] { activeVIP_id = token as! String }
  579. if let token = dict1["userId"] { activeVIP_userId = token as! String }
  580. if let token = dict1["status"] { activeVIP_status = token as! Int }
  581. if let token = dict1["endDate"] { activeVIP_endDate = token as! String }
  582. if let token = dict1["payType"] { activeVIP_payType = token as! Int }
  583. if let token = dict1["productName"] { activeVIP_productName = token as! String }
  584. if let token = dict1["levels"] { activeVIP_levels = token as! String }
  585. if let token = dict1["platforms"] { activeVIP_platforms = token as! String }
  586. if let token = dict1["point"] { activeVIP_point = token as! Int }
  587. if let token = dict1["maxDeviceNum"] { activeVIP_maxDeviceNum = token as! Int }
  588. if let token = dict1["paymentModel"] { activeVIP_paymentModel = token as! String }
  589. if let token = dict1["isAi"] { activeVIP_isAi = token as! String }
  590. 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)
  591. results.append(userInfoActiveVIP)
  592. }
  593. let result = KMMemberCenterResult(code: code, msg: message, activeVIPs: results)
  594. if code == 200 {
  595. complete(true, result)
  596. } else {
  597. complete(false, result)
  598. }
  599. }
  600. }
  601. /**
  602. @abstract 用户手动注销
  603. @param code 邮箱验证码
  604. @param complete 回调
  605. */
  606. func userLogOffForUser(code: String, _ complete: @escaping KMMemberCenterComplete) {
  607. let token: String = KMMemberInfo.shared.access_token
  608. if token == "" {
  609. return
  610. }
  611. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/logOffForUser"
  612. let params: [String: Any] = ["code": code,
  613. "appId": "1"]
  614. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  615. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  616. } completion: { [weak self] (task, responseObject, error) in
  617. var dic: NSDictionary = [:]
  618. if error == nil, let responseObject = responseObject as? NSDictionary {
  619. dic = responseObject
  620. } else {
  621. var info = responseObject
  622. if let error = error {
  623. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  624. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  625. }
  626. }
  627. dic = (info as? NSDictionary) ?? [:]
  628. }
  629. let code: Int = dic["code"] as? Int ?? 0
  630. let message: String = dic["msg"] as? String ?? ""
  631. let result_dict: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  632. var currentTime = ""
  633. var logOffTime = ""
  634. if let token = result_dict["currentTime"] { currentTime = token as! String }
  635. if let token = result_dict["logOffTime"] { logOffTime = token as! String }
  636. let logOff = KMMemberLogOff(currentTime: currentTime, logOffTime: logOffTime)
  637. let result = KMMemberCenterResult(code: code, msg: message, logOff: logOff)
  638. if code == 200 {
  639. complete(true, result)
  640. } else {
  641. complete(false, result)
  642. }
  643. }
  644. }
  645. /**
  646. @abstract 撤销注销申请
  647. @param complete 回调
  648. */
  649. func userRevokeCancel(_ complete: @escaping KMMemberCenterComplete) {
  650. let token: String = KMMemberInfo.shared.access_token
  651. if token == "" {
  652. return
  653. }
  654. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/revokeCancel"
  655. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  656. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  657. } completion: { [weak self] (task, responseObject, error) in
  658. var dic: NSDictionary = [:]
  659. if error == nil, let responseObject = responseObject as? NSDictionary {
  660. dic = responseObject
  661. } else {
  662. var info = responseObject
  663. if let error = error {
  664. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  665. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  666. }
  667. }
  668. dic = (info as? NSDictionary) ?? [:]
  669. }
  670. let code: Int = dic["code"] as? Int ?? 0
  671. let message: String = dic["msg"] as? String ?? ""
  672. let result_Bool: Bool = dic["result"] as? Bool ?? false
  673. let result = KMMemberCenterResult(code: code, msg: message, result: result_Bool)
  674. if code == 200 {
  675. complete(true, result)
  676. } else {
  677. complete(false, result)
  678. }
  679. }
  680. }
  681. // MARK: 商品模块
  682. /**
  683. @abstract 获取上架中的产品
  684. @param isEducation 是否教育优惠
  685. @param complete 回调
  686. */
  687. func getListingProducts(isEducation: Int, _ complete: @escaping KMMemberProductComplete) {
  688. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getListingProducts"
  689. var platformId = "2"
  690. #if VERSION_FREE
  691. #if VERSION_DMG
  692. // DMG
  693. platformId = "2"
  694. #else
  695. // AppStore 免费版本
  696. #endif
  697. platformId = "3"
  698. #else
  699. // AppStore 付费版
  700. platformId = "5"
  701. #endif
  702. let params: [String: Any] = ["isEducation": isEducation,
  703. "platformId": platformId]
  704. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  705. } completion: { [weak self] (task, responseObject, error) in
  706. var dic: NSDictionary = [:]
  707. if error == nil, let responseObject = responseObject as? NSDictionary {
  708. dic = responseObject
  709. } else {
  710. var info = responseObject
  711. if let error = error {
  712. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  713. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  714. }
  715. }
  716. dic = (info as? NSDictionary) ?? [:]
  717. }
  718. let code: Int = dic["code"] as? Int ?? 0
  719. let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
  720. let message: String = dic["msg"] as? String ?? ""
  721. var results: [KMListingProductsModel] = []
  722. for dict1 in result_Array {
  723. var id = ""
  724. var productName = ""
  725. var price = ""
  726. var maxDeviceNum = 0
  727. var levels = ""
  728. var platforms = ""
  729. var productLineId = 0
  730. var paymentModel = 0
  731. var cycle = 0
  732. var code = ""
  733. var cnyPrice = ""
  734. if let token = dict1["id"] { id = token as! String }
  735. if let token = dict1["productName"] { productName = token as! String }
  736. if let token = dict1["price"] { price = token as! String }
  737. if let token = dict1["maxDeviceNum"] { maxDeviceNum = token as! Int }
  738. if let token = dict1["levels"] { levels = token as! String }
  739. if let token = dict1["platforms"] { platforms = token as! String }
  740. if let token = dict1["productLineId"] { productLineId = token as! Int }
  741. if let token = dict1["paymentModel"] { paymentModel = token as! Int }
  742. if let token = dict1["cycle"] { cycle = token as! Int }
  743. if let token = dict1["code"] { code = token as! String }
  744. if let token = dict1["cnyPrice"] { cnyPrice = token as! String }
  745. 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)
  746. results.append(products)
  747. }
  748. let result = KMMemberProductResult(code: code, msg: message, listingProducts: results)
  749. if code == 200 {
  750. complete(true, result)
  751. } else {
  752. complete(false, result)
  753. }
  754. }
  755. }
  756. /**
  757. @abstract 获取已登录用户购买商品价格
  758. @param productId 购买的产品id
  759. @param isEducation 是否教育优惠
  760. @param complete 回调
  761. */
  762. func getProductPriceForBuy(productId: String, isEducation: Int, userId: String, _ complete: @escaping KMMemberProductComplete) {
  763. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getProductPriceForBuy"
  764. let params: [String: Any] = ["productId": productId,
  765. "isEducation": isEducation,
  766. "userId": userId]
  767. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  768. } completion: { [weak self] (task, responseObject, error) in
  769. var dic: NSDictionary = [:]
  770. if error == nil, let responseObject = responseObject as? NSDictionary {
  771. dic = responseObject
  772. } else {
  773. var info = responseObject
  774. if let error = error {
  775. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  776. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  777. }
  778. }
  779. dic = (info as? NSDictionary) ?? [:]
  780. }
  781. let code: Int = dic["code"] as? Int ?? 0
  782. let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
  783. let message: String = dic["msg"] as? String ?? ""
  784. var results: [KMListingProductsModel] = []
  785. for dict1 in result_Array {
  786. var id = ""
  787. var productName = ""
  788. var price = ""
  789. var maxDeviceNum = 0
  790. var levels = ""
  791. var platforms = ""
  792. var productLineId = 0
  793. var paymentModel = 0
  794. var cycle = 0
  795. var code = ""
  796. var cnyPrice = ""
  797. if let token = dict1["id"] { id = token as! String }
  798. if let token = dict1["productName"] { productName = token as! String }
  799. if let token = dict1["price"] { price = token as! String }
  800. if let token = dict1["maxDeviceNum"] { maxDeviceNum = token as! Int }
  801. if let token = dict1["levels"] { levels = token as! String }
  802. if let token = dict1["platforms"] { platforms = token as! String }
  803. if let token = dict1["productLineId"] { productLineId = token as! Int }
  804. if let token = dict1["paymentModel"] { paymentModel = token as! Int }
  805. if let token = dict1["cycle"] { cycle = token as! Int }
  806. if let token = dict1["code"] { code = token as! String }
  807. if let token = dict1["cnyPrice"] { cnyPrice = token as! String }
  808. 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)
  809. results.append(products)
  810. }
  811. let result = KMMemberProductResult(code: code, msg: message, listingProducts: results)
  812. if code == 200 {
  813. complete(true, result)
  814. } else {
  815. complete(false, result)
  816. }
  817. }
  818. }
  819. /**
  820. @abstract 获取批量阶段购买价格
  821. @param productId 购买的产品id
  822. @param isEducation 是否教育优惠
  823. @param complete 回调
  824. */
  825. func getBatchProductPrice(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  826. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getBatchProductPrice"
  827. let params: [String: Any] = ["productId": productId,
  828. "num": num]
  829. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  830. } completion: { [weak self] (task, responseObject, error) in
  831. var dic: NSDictionary = [:]
  832. if error == nil, let responseObject = responseObject as? NSDictionary {
  833. dic = responseObject
  834. } else {
  835. var info = responseObject
  836. if let error = error {
  837. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  838. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  839. }
  840. }
  841. dic = (info as? NSDictionary) ?? [:]
  842. }
  843. let code: Int = dic["code"] as? Int ?? 0
  844. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  845. let message: String = dic["msg"] as? String ?? ""
  846. var productId = ""
  847. var totalPrice = ""
  848. var price = ""
  849. var batchPrice = ""
  850. var cnyPrice = ""
  851. var cnyBatchPrice = ""
  852. var cnyTotalPrice = ""
  853. if let token = result["productId"] { productId = token as! String }
  854. if let token = result["totalPrice"] { totalPrice = token as! String }
  855. if let token = result["price"] { price = token as! String }
  856. if let token = result["batchPrice"] { batchPrice = token as! String }
  857. if let token = result["cnyPrice"] { cnyPrice = token as! String }
  858. if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as! String }
  859. if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as! String }
  860. let products = KMBatchProductPriceModel(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
  861. let result1 = KMMemberProductResult(code: code, msg: message, batchProductPrice: products)
  862. if code == 200 {
  863. complete(true, result1)
  864. } else {
  865. complete(false, result1)
  866. }
  867. }
  868. }
  869. /**
  870. @abstract 验证商品优惠券,返回商品优惠后价格
  871. @param productId 购买的产品id
  872. @param isEducation 是否教育优惠
  873. @param complete 回调
  874. */
  875. func checkCoupon(productId: String, userId: String, code: String, _ complete: @escaping KMMemberProductComplete) {
  876. let token: String = KMMemberInfo.shared.access_token
  877. if token == "" {
  878. return
  879. }
  880. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkCoupon"
  881. let params: [String: Any] = ["productId": productId,
  882. "userId": userId,
  883. "code": code]
  884. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  885. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  886. } completion: { [weak self] (task, responseObject, error) in
  887. var dic: NSDictionary = [:]
  888. if error == nil, let responseObject = responseObject as? NSDictionary {
  889. dic = responseObject
  890. } else {
  891. var info = responseObject
  892. if let error = error {
  893. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  894. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  895. }
  896. }
  897. dic = (info as? NSDictionary) ?? [:]
  898. }
  899. let code: Int = dic["code"] as? Int ?? 0
  900. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  901. let message: String = dic["msg"] as? String ?? ""
  902. var id = ""
  903. var productName = ""
  904. var price = ""
  905. var maxDeviceNum = 0
  906. var displayPrice = ""
  907. var levels = ""
  908. var platforms = ""
  909. var productLineId = 0
  910. var paymentModel = 0
  911. var cycle = 0
  912. var cnyPrice = ""
  913. var displayCnyPrice = ""
  914. if let token = result["id"] { id = token as! String }
  915. if let token = result["productName"] { productName = token as! String }
  916. if let token = result["price"] { price = token as! String }
  917. if let token = result["maxDeviceNum"] { maxDeviceNum = token as! Int }
  918. if let token = result["displayPrice"] { displayPrice = token as! String }
  919. if let token = result["levels"] { levels = token as! String }
  920. if let token = result["platforms"] { platforms = token as! String }
  921. if let token = result["productLineId"] { productLineId = token as! Int }
  922. if let token = result["paymentModel"] { paymentModel = token as! Int }
  923. if let token = result["cycle"] { cycle = token as! Int }
  924. if let token = result["cnyPrice"] { cnyPrice = token as! String }
  925. if let token = result["displayCnyPrice"] { displayCnyPrice = token as! String }
  926. 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)
  927. let result1 = KMMemberProductResult(code: code, msg: message, checkCoupon: products)
  928. if code == 200 {
  929. complete(true, result1)
  930. } else {
  931. complete(false, result1)
  932. }
  933. }
  934. }
  935. /**
  936. @abstract 获取批量阶段购买价格
  937. @param productId 购买的产品id
  938. @param isEducation 是否教育优惠
  939. @param complete 回调
  940. */
  941. func checkEducation(email: String, _ complete: @escaping KMMemberProductComplete) {
  942. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkEducation"
  943. let params: [String: Any] = ["email": email]
  944. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  945. } completion: { [weak self] (task, responseObject, error) in
  946. var dic: NSDictionary = [:]
  947. if error == nil, let responseObject = responseObject as? NSDictionary {
  948. dic = responseObject
  949. } else {
  950. var info = responseObject
  951. if let error = error {
  952. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  953. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  954. }
  955. }
  956. dic = (info as? NSDictionary) ?? [:]
  957. }
  958. let code: Int = dic["code"] as? Int ?? 0
  959. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  960. let message: String = dic["msg"] as? String ?? ""
  961. var productId = ""
  962. var totalPrice = ""
  963. var price = ""
  964. var batchPrice = ""
  965. var cnyPrice = ""
  966. var cnyBatchPrice = ""
  967. var cnyTotalPrice = ""
  968. if let token = result["productId"] { productId = token as! String }
  969. if let token = result["totalPrice"] { totalPrice = token as! String }
  970. if let token = result["price"] { price = token as! String }
  971. if let token = result["batchPrice"] { batchPrice = token as! String }
  972. if let token = result["cnyPrice"] { cnyPrice = token as! String }
  973. if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as! String }
  974. if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as! String }
  975. let products = KMBatchProductPriceModel(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
  976. let result1 = KMMemberProductResult(code: code, msg: message, batchProductPrice: products)
  977. if code == 200 {
  978. complete(true, result1)
  979. } else {
  980. complete(false, result1)
  981. }
  982. }
  983. }
  984. // MARK: 个人中心模块
  985. // MARK: 订单模块
  986. /**
  987. @abstract 支付后查询订单状态
  988. @param orderId 订单id
  989. @param complete 回调
  990. */
  991. func getStateByOrderId(orderId: String, _ complete: @escaping KMMemberProductComplete) {
  992. let token: String = KMMemberInfo.shared.access_token
  993. if token == "" {
  994. return
  995. }
  996. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getStateByOrderId"
  997. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
  998. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  999. } completion: { [weak self] (task, responseObject, error) in
  1000. var dic: NSDictionary = [:]
  1001. if error == nil, let responseObject = responseObject as? NSDictionary {
  1002. dic = responseObject
  1003. } else {
  1004. var info = responseObject
  1005. if let error = error {
  1006. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1007. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1008. }
  1009. }
  1010. dic = (info as? NSDictionary) ?? [:]
  1011. }
  1012. let code: Int = dic["code"] as? Int ?? 0
  1013. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1014. let message: String = dic["msg"] as? String ?? ""
  1015. var status = ""
  1016. if let token = result["status"] { status = token as! String }
  1017. let result1 = KMMemberProductResult(code: code, msg: message, result: status)
  1018. if code == 200 {
  1019. complete(true, result1)
  1020. } else {
  1021. complete(false, result1)
  1022. }
  1023. }
  1024. }
  1025. /**
  1026. @abstract 创建订单(买断、订阅)
  1027. @param productId 产品id
  1028. @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
  1029. @param price 价格
  1030. @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
  1031. @param couponCode 优惠卷
  1032. @param num 批量购买数量
  1033. @param complete 回调
  1034. */
  1035. func createOrder(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  1036. let token: String = KMMemberInfo.shared.access_token
  1037. if token == "" {
  1038. return
  1039. }
  1040. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/createOrder"
  1041. let params: [String: Any] = ["productId": productId,
  1042. "paymentMethod": paymentMethod,
  1043. "price": price,
  1044. "discountFlag": discountFlag,
  1045. "couponCode": couponCode,
  1046. "num": num]
  1047. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  1048. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1049. } completion: { [weak self] (task, responseObject, error) in
  1050. var dic: NSDictionary = [:]
  1051. if error == nil, let responseObject = responseObject as? NSDictionary {
  1052. dic = responseObject
  1053. } else {
  1054. var info = responseObject
  1055. if let error = error {
  1056. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1057. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1058. }
  1059. }
  1060. dic = (info as? NSDictionary) ?? [:]
  1061. }
  1062. let code: Int = dic["code"] as? Int ?? 0
  1063. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1064. let message: String = dic["msg"] as? String ?? ""
  1065. var thirdOrderNo = ""
  1066. var orderId = ""
  1067. var payHref = ""
  1068. if code == 200 {
  1069. if let token = result["thirdOrderNo"] { thirdOrderNo = token as! String }
  1070. if let token = result["orderId"] { orderId = token as! String }
  1071. if let token = result["payHref"] { payHref = token as! String }
  1072. let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
  1073. let result1 = KMMemberProductResult(code: code, msg: message, createOrder: products)
  1074. complete(true, result1)
  1075. } else {
  1076. let result1 = KMMemberProductResult(code: code, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
  1077. complete(false, result1)
  1078. }
  1079. }
  1080. }
  1081. /**
  1082. @abstract 获取订单列表
  1083. @param orderStatus 0全部1待支付
  1084. @param complete 回调
  1085. */
  1086. func getOrderListByStatus(orderStatus: Int, _ complete: @escaping KMMemberProductComplete) {
  1087. let token: String = KMMemberInfo.shared.access_token
  1088. if token == "" {
  1089. return
  1090. }
  1091. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getOrderListByStatus"
  1092. let params: [String: Any] = ["orderStatus": orderStatus]
  1093. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  1094. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1095. } completion: { [weak self] (task, responseObject, error) in
  1096. var dic: NSDictionary = [:]
  1097. if error == nil, let responseObject = responseObject as? NSDictionary {
  1098. dic = responseObject
  1099. } else {
  1100. var info = responseObject
  1101. if let error = error {
  1102. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1103. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1104. }
  1105. }
  1106. dic = (info as? NSDictionary) ?? [:]
  1107. }
  1108. let code: Int = dic["code"] as? Int ?? 0
  1109. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1110. let message: String = dic["msg"] as? String ?? ""
  1111. // var thirdOrderNo = ""
  1112. // var orderId = ""
  1113. // var payHref = ""
  1114. // if code == 200 {
  1115. // if let token = result["thirdOrderNo"] { thirdOrderNo = token as! String }
  1116. // if let token = result["orderId"] { orderId = token as! String }
  1117. // if let token = result["payHref"] { payHref = token as! String }
  1118. // let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
  1119. // let result1 = KMMemberProductResult(code: code, msg: message, createOrder: products)
  1120. // complete(true, result1)
  1121. // } else {
  1122. // let result1 = KMMemberProductResult(code: code, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
  1123. // complete(false, result1)
  1124. // }
  1125. }
  1126. }
  1127. // MARK: 评估模块
  1128. // MARK: 活动模块
  1129. // MARK: 翻译模块
  1130. // MARK: AI模块
  1131. // MARK: 会员赠送模块
  1132. // MARK: Error Code
  1133. static func typeOfMessage(type: KMMemberCenterErrorCodeType?) -> String {
  1134. var result: String = ""
  1135. switch type {
  1136. case .EXCEPTION_MSG_TOKEN_IS_INVALID:
  1137. result = "无效的token或者token已过期"
  1138. break;
  1139. case .EXCEPTION_MSG_DEVICE_NUM_MAX:
  1140. result = "您的登录设备已达上限,请退出其他设备重新登录"
  1141. break;
  1142. case .EXCEPTION_MSG_USER_NOT_LOGIN:
  1143. result = "用户没有登录,请登录后再访问"
  1144. break;
  1145. case .EMAIL_VERIFY_CODE_KEY_ERROR:
  1146. result = "email code error!"
  1147. break;
  1148. case .EMAIL_REGISTER_ERROR:
  1149. result = "Register error!"
  1150. break;
  1151. case .EXCEPTION_MSG_PASSWORD_ERROR:
  1152. result = "密码错误,您可以检查大小写状态"
  1153. break;
  1154. case .EXCEPTION_MSG_CODE_ACTION_ERROR:
  1155. result = "code action error"
  1156. break;
  1157. case .EXCEPTION_MSG_CODE_SEND_ERROR:
  1158. result = "code send error"
  1159. break;
  1160. case .EXCEPTION_MAIL_CODE_SEND_ERROR:
  1161. result = "mail send error"
  1162. break;
  1163. case .VERIFY_CODE_SEND_TOO_QUICKLY:
  1164. result = "code send too quickly"
  1165. break;
  1166. case .EXCEPTION_MSG_EMAIL_EXIST:
  1167. result = "该邮箱已有账号,请前往登录"
  1168. break;
  1169. case .EXCEPTION_MSG_EMAIL_NOT_REGISTER:
  1170. result = "当前账号未注册,点击下一步我们将为您注册账号"
  1171. break;
  1172. case .EXCEPTION_MSG_EMAIL_LOGOUT_ING:
  1173. result = "注销中,无法登录,若有问题可联系客服"
  1174. break;
  1175. case .EXCEPTION_MSG_EMAIL_INVALID:
  1176. result = "请输入正确的邮箱格式"
  1177. break;
  1178. case .EXCEPTION_MSG_PASSWORD_NOT_INCONSISTENT:
  1179. result = "密码不一致,请重新输入"
  1180. break;
  1181. case .EXCEPTION_MSG_PASSWORD_SIZE_MIN:
  1182. result = "密码请包含6~24个字符"
  1183. break;
  1184. case .EXCEPTION_MSG_PASSWORD_SIZE_MAX:
  1185. result = "密码请包含6~24个字符"
  1186. break;
  1187. case .EXCEPTION_MSG_PLEASE_ADD_AUTH_CONFIG:
  1188. result = "please add auth config"
  1189. break;
  1190. case .EXCEPTION_MSG_USER_SUBSCRIPTION_IN_PROGRESS:
  1191. result = "您目前还在订阅期内,暂时无法注销,请订阅期结束后再点击注销账号"
  1192. break;
  1193. case .EXCEPTION_TIME_TRANSFER_ERROR:
  1194. result = "时间转换失败"
  1195. break;
  1196. case .EXCEPTION_MSG_PASSWORD_CONTAIN_EMPTY:
  1197. result = "密码不能包含空格"
  1198. break;
  1199. case .UNKNOWN:
  1200. result = "UNKNOWN"
  1201. break;
  1202. case .SUCCESS:
  1203. result = "SUCCESS"
  1204. break;
  1205. default:
  1206. result = "Network error"
  1207. }
  1208. return result
  1209. }
  1210. }