KMMemberCenterManager.swift 63 KB

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