KMMemberCenterManager.swift 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622
  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. typealias KMMemberRequestInfoComplete = (_ success: Bool, _ info: NSDictionary?) -> Void
  51. class KMMemberCenterManager: NSObject {
  52. static let manager = KMMemberCenterManager()
  53. private let configuration: KMMemberCenterConfig = KMMemberCenterConfig()
  54. // MARK: 判断有无网络
  55. func isConnectionAvailable() -> Bool {
  56. let reachability = Reachability(hostname: "www.apple.com")
  57. let state = reachability?.currentReachabilityStatus()
  58. if(state == NotReachable) {
  59. return false
  60. }
  61. return true
  62. }
  63. // MARK: 拼接URL(为Get类型)
  64. func constructURLString(baseURLString: String, parameters: [String: Any]) -> String? {
  65. // Ensure the base URL is valid
  66. guard var components = URLComponents(string: baseURLString) else {
  67. return nil
  68. }
  69. // Convert parameters to query items
  70. components.queryItems = parameters.map { key, value in
  71. URLQueryItem(name: key, value: "\(value)")
  72. }
  73. // Return the complete URL as a string
  74. return components.url?.absoluteString
  75. }
  76. // MARK: 登录模块
  77. /**
  78. @abstract 新会员系统重置密码
  79. @param email 邮箱
  80. @param verifyCode 验证码
  81. @param password 密码
  82. @param complete 回调
  83. */
  84. func resetPassword(email: String, verifyCode: String, password: String, _ complete: @escaping KMMemberCenterComplete) {
  85. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/memberResetPassword"
  86. // var escapedString = q
  87. // escapedString = String(data: escapedString.data(using: .utf8)!, encoding: .utf8)!
  88. let paraDict: [String: Any] = ["email": email,
  89. "verifyCode": verifyCode,
  90. "appId": "1",
  91. "password": password]
  92. let postData = try! JSONSerialization.data(withJSONObject: paraDict)
  93. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  94. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  95. request.httpMethod = "POST"
  96. request.httpBody = postData
  97. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  98. guard let data = data else {
  99. print(String(describing: error))
  100. return
  101. }
  102. let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:]
  103. if jsonObject != nil {
  104. let code: Int = jsonObject!["code"] as? Int ?? 0
  105. let result_bool: Bool = jsonObject!["result"] as? Bool ?? false
  106. let message: String = jsonObject!["msg"] as? String ?? ""
  107. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  108. if code == 200 {
  109. complete(true, result)
  110. } else {
  111. complete(false, result)
  112. }
  113. } else {
  114. complete(false, KMMemberCenterResult(code: 0, msg: "unknown error", result: false))
  115. }
  116. }
  117. task.resume()
  118. // let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/memberResetPassword"
  119. // let params: [String: Any] = ["email": email,
  120. // "verifyCode": verifyCode,
  121. // "appId": "1",
  122. // "password": password]
  123. // KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  124. //
  125. // } completion: { [weak self] (task, responseObject, error) in
  126. // var dic: NSDictionary = [:]
  127. // if error == nil, let responseObject = responseObject as? NSDictionary {
  128. // dic = responseObject
  129. // } else {
  130. // var info = responseObject
  131. // if let error = error {
  132. // if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  133. // info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  134. // }
  135. // }
  136. // dic = (info as? NSDictionary) ?? [:]
  137. // }
  138. //
  139. // let code: Int = dic["code"] as? Int ?? 0
  140. // let result_bool: Bool = dic["result"] as? Bool ?? false
  141. // let message: String = dic["msg"] as? String ?? ""
  142. //
  143. // let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  144. //// let error = NSError(domain: message, code: code)
  145. // if code == 200 {
  146. // complete(true, result)
  147. // } else {
  148. // complete(false, result)
  149. // }
  150. // }
  151. }
  152. /**
  153. @abstract 验证邮箱(重置密码输入邮箱点击下一步时校验邮箱是否注册)
  154. @param email 邮箱
  155. @param complete 回调
  156. */
  157. func emailVerification(email: String, _ complete: @escaping KMMemberCenterComplete) {
  158. let urlString = String(format: "%@/member-system-sso/auth/validEmail?email=%@", configuration.activityBaseURL(), email)
  159. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  160. } completion: { (task, responseObject, error) in
  161. var dic: NSDictionary = [:]
  162. if error == nil, let responseObject = responseObject as? NSDictionary {
  163. dic = responseObject
  164. } else {
  165. var info = responseObject
  166. if let error = error {
  167. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  168. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  169. }
  170. }
  171. dic = (info as? NSDictionary) ?? [:]
  172. }
  173. let code: Int = dic["code"] as? Int ?? 0
  174. let result_bool: Bool = dic["result"] as? Bool ?? false
  175. let message: String = dic["msg"] as? String ?? ""
  176. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  177. if code == 200 {
  178. complete(true, result)
  179. } else {
  180. complete(false, result)
  181. }
  182. }
  183. }
  184. /**
  185. @abstract 获取邮箱验证码
  186. @param action 验证码用途
  187. @param receiver 邮箱号
  188. @param complete 回调
  189. */
  190. func getVerificationCode(action: KMVerificationCodeType, receiver: String, _ complete: @escaping KMMemberCenterComplete) {
  191. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/getVerifyCode"
  192. var actionType = "member_login"
  193. if action == .reset {
  194. actionType = "member_reset_password"
  195. } else if action == .logout {
  196. actionType = "member_log_off"
  197. }
  198. let params: [String: Any] = ["action": actionType,
  199. "type": 0,
  200. "receiver": receiver,
  201. "appId": "1"]
  202. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  203. } completion: { (task, responseObject, error) in
  204. var dic: NSDictionary = [:]
  205. if error == nil, let responseObject = responseObject as? NSDictionary {
  206. dic = responseObject
  207. } else {
  208. var info = responseObject
  209. if let error = error {
  210. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  211. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  212. }
  213. }
  214. dic = (info as? NSDictionary) ?? [:]
  215. }
  216. let code: Int = dic["code"] as? Int ?? 0
  217. let result_bool: Bool = dic["result"] as? Bool ?? false
  218. let message: String = dic["msg"] as? String ?? ""
  219. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  220. if code == 200 {
  221. complete(true, result)
  222. } else {
  223. complete(false, result)
  224. }
  225. }
  226. }
  227. /**
  228. @abstract 实时检查邮件验证码
  229. @param type 验证码用途
  230. @param account 账户
  231. @param code 验证码
  232. @param complete 回调
  233. */
  234. func checkVerificationCode(type: KMVerificationCodeType, account: String, code: String, _ complete: @escaping KMMemberCenterComplete) {
  235. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/isEmailCodeValid"
  236. var actionType = "member_login"
  237. if type == .reset {
  238. actionType = "member_reset_password"
  239. } else if type == .logout {
  240. actionType = "user_log_off"
  241. }
  242. let params: [String: Any] = ["type": actionType,
  243. "account": account,
  244. "code": code,
  245. "appId": "1"]
  246. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
  247. } completion: { [weak self] (task, responseObject, error) in
  248. var dic: NSDictionary = [:]
  249. if error == nil, let responseObject = responseObject as? NSDictionary {
  250. dic = responseObject
  251. } else {
  252. var info = responseObject
  253. if let error = error {
  254. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  255. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  256. }
  257. }
  258. dic = (info as? NSDictionary) ?? [:]
  259. }
  260. let code: Int = dic["code"] as? Int ?? 0
  261. let result_bool: Bool = dic["result"] as? Bool ?? false
  262. let message: String = dic["msg"] as? String ?? ""
  263. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  264. if code == 200 {
  265. complete(true, result)
  266. } else {
  267. complete(false, result)
  268. }
  269. }
  270. }
  271. /**
  272. @abstract 邮箱验证码登录 & 密码登录
  273. @param email 邮箱
  274. @param code 验证码/密码
  275. @param type 密码类型(验证码?密码?)
  276. @param complete 回调
  277. */
  278. func emailLogin(email: String, code: String, type: KMSignUpState, _ complete: @escaping KMMemberCenterComplete) {
  279. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/memberLogin"
  280. let uuid: String = GetHardwareUUID() ?? ""
  281. var params: [String: Any] = [:]
  282. if type == .verificationCode {
  283. params = ["email": email,
  284. "code": code,
  285. "appId": "1",
  286. "deviceSign": uuid,
  287. "deviceName": NSFullUserName(),
  288. "model": "mac"]
  289. } else {
  290. params = ["email": email,
  291. "password": code,
  292. "appId": "1",
  293. "deviceSign": uuid,
  294. "deviceName": NSFullUserName(),
  295. "model": "mac"]
  296. }
  297. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  298. // requestSerializer.setValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  299. } completion: { [weak self] (task, responseObject, error) in
  300. var dic: NSDictionary = [:]
  301. if error == nil, let responseObject = responseObject as? NSDictionary {
  302. dic = responseObject
  303. } else {
  304. var info = responseObject
  305. if let error = error {
  306. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  307. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  308. }
  309. }
  310. dic = (info as? NSDictionary) ?? [:]
  311. }
  312. let code: Int = dic["code"] as? Int ?? 0
  313. let result_dict: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  314. let message: String = dic["msg"] as? String ?? ""
  315. var refresh_token = ""
  316. var access_token = ""
  317. var token_type = ""
  318. var expires_in = ""
  319. var scope = ""
  320. if let token = result_dict["refresh_token"] { refresh_token = token as! String }
  321. if let token = result_dict["access_token"] { access_token = token as! String }
  322. if let token = result_dict["token_type"] { token_type = token as! String }
  323. if let token = result_dict["expires_in"] { expires_in = token as! String }
  324. let loginResult = KMMemberLoginResult(refreshToken: refresh_token, accessToken: access_token, tokenType: token_type, expiresIn: expires_in)
  325. let result = KMMemberCenterResult(loginResult: loginResult)
  326. result.code = code
  327. result.msg = message
  328. // let error = NSError(domain: message, code: code)
  329. if code == 200 {
  330. complete(true, result)
  331. } else {
  332. complete(false, result)
  333. }
  334. }
  335. }
  336. /**
  337. @abstract 获取用户登录设备列表
  338. @param email 邮箱
  339. @param complete 回调
  340. */
  341. func getUserDeviceList(email: String, _ complete: @escaping KMMemberCenterComplete) {
  342. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/getLoginDeviceList?email=\(email)&appId=1"
  343. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: [:]) { requestSerializer in
  344. } completion: { [weak self] (task, responseObject, error) in
  345. var dic: NSDictionary = [:]
  346. if error == nil, let responseObject = responseObject as? NSDictionary {
  347. dic = responseObject
  348. } else {
  349. var info = responseObject
  350. if let error = error {
  351. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  352. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  353. }
  354. }
  355. dic = (info as? NSDictionary) ?? [:]
  356. }
  357. let code: Int = dic["code"] as? Int ?? 0
  358. let result_dict: Dictionary = dic["result"] as? Dictionary ?? [:]
  359. let message: String = dic["msg"] as? String ?? ""
  360. let deviceList: [Dictionary] = result_dict["deviceList"] as? [Dictionary] ?? [[:]]
  361. var deviceLists: [KMMemberDeviceList] = []
  362. for dict in deviceList {
  363. var device_id = ""
  364. var productId = ""
  365. var uniqueSn = ""
  366. var deviceName = ""
  367. var id = ""
  368. if let token = dict["device_id"] {
  369. device_id = token as? String ?? ""
  370. }
  371. if let token = dict["productId"] {
  372. productId = token as? String ?? ""
  373. }
  374. if let token = dict["uniqueSn"] {
  375. uniqueSn = token as? String ?? ""
  376. }
  377. if let token = dict["deviceName"] {
  378. deviceName = token as? String ?? ""
  379. }
  380. if let token = dict["id"] {
  381. id = token as? String ?? ""
  382. }
  383. let list = KMMemberDeviceList(deviceId: device_id, productId: productId, uniqueSn: uniqueSn, appId: "", deviceName: deviceName)
  384. list.id = id
  385. deviceLists.append(list)
  386. }
  387. var maxDeviceNum = 0
  388. if let token = result_dict["maxDeviceNum"] {
  389. maxDeviceNum = token as! Int
  390. }
  391. let result = KMMemberCenterResult(deviceListResult: deviceLists, maxDeviceNum: maxDeviceNum)
  392. if code == 200 {
  393. complete(true, result)
  394. } else {
  395. complete(false, result)
  396. }
  397. }
  398. }
  399. /**
  400. @abstract 登出用户的指定设备
  401. @param deviceId 设备记录ID
  402. @param complete 回调
  403. */
  404. func logoutDevice(deviceId: String, complete: @escaping KMMemberCenterComplete) {
  405. let urlString = configuration.activityBaseURL() + "/member-system-sso/auth/logoutDevice?deviceId=\(deviceId)"
  406. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: [:]) { requestSerializer in
  407. } completion: { [weak self] (task, responseObject, error) in
  408. var dic: NSDictionary = [:]
  409. if error == nil, let responseObject = responseObject as? NSDictionary {
  410. dic = responseObject
  411. } else {
  412. var info = responseObject
  413. if let error = error {
  414. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  415. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  416. }
  417. }
  418. dic = (info as? NSDictionary) ?? [:]
  419. }
  420. let code: Int = dic["code"] as? Int ?? 0
  421. let resultStr: String = dic["result"] as? String ?? ""
  422. let message: String = dic["msg"] as? String ?? ""
  423. let result = KMMemberCenterResult(code: code, msg: message, resultStr: resultStr)
  424. if code == 200 {
  425. complete(true, result)
  426. } else {
  427. complete(false, result)
  428. }
  429. }
  430. }
  431. // MARK: 个人信息模块
  432. /**
  433. @abstract 获取老带新已邀请人数
  434. @param complete 回调
  435. */
  436. func getInviteNum(_ complete: @escaping KMMemberCenterComplete) {
  437. let token: String = KMMemberInfo.shared.access_token
  438. if token == "" {
  439. complete(false, nil)
  440. return
  441. }
  442. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/getInviteNum"
  443. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  444. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  445. } completion: { [weak self] (task, responseObject, error) in
  446. var dic: NSDictionary = [:]
  447. if error == nil, let responseObject = responseObject as? NSDictionary {
  448. dic = responseObject
  449. } else {
  450. var info = responseObject
  451. if let error = error {
  452. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  453. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  454. }
  455. }
  456. dic = (info as? NSDictionary) ?? [:]
  457. }
  458. let code: Int = dic["code"] as? Int ?? 0
  459. let resultInt: Int = dic["result"] as? Int ?? 0
  460. let message: String = dic["msg"] as? String ?? ""
  461. let result = KMMemberCenterResult(code: code, msg: message, resultInt: resultInt)
  462. if code == 200 {
  463. complete(true, result)
  464. } else {
  465. complete(false, result)
  466. }
  467. }
  468. }
  469. /**
  470. @abstract 获取用户个人信息
  471. @param complete 回调
  472. */
  473. func userInfo(_ complete: @escaping KMMemberCenterComplete) {
  474. let token: String = KMMemberInfo.shared.access_token
  475. if token == "" {
  476. complete(false, nil)
  477. return
  478. }
  479. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/info"
  480. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
  481. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  482. } completion: { [weak self] (task, responseObject, error) in
  483. var dic: NSDictionary = [:]
  484. if error == nil, let responseObject = responseObject as? NSDictionary {
  485. dic = responseObject
  486. } else {
  487. var info = responseObject
  488. if let error = error {
  489. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  490. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  491. }
  492. }
  493. dic = (info as? NSDictionary) ?? [:]
  494. }
  495. let code: Int = dic["code"] as? Int ?? 0
  496. let result_dict: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  497. let message: String = dic["msg"] as? String ?? ""
  498. var userId = ""
  499. var email = ""
  500. var fullName = ""
  501. var activeVIP = KMMemberUserInfo()
  502. var aiPoint = 0
  503. var validFlag = ""
  504. var isHaveAIDiscount = ""
  505. var canTrail = ""
  506. if let token = result_dict["id"] { userId = token as! String }
  507. if let token = result_dict["email"] { email = token as! String }
  508. if let token = result_dict["fullName"] { fullName = token as! String }
  509. let activeVIP_dict: NSDictionary = result_dict["activeVIP"] as? NSDictionary ?? [:]
  510. var activeVIP_id = ""
  511. var activeVIP_userId = ""
  512. var activeVIP_status = 0
  513. var activeVIP_endDate = ""
  514. var activeVIP_payType = 0
  515. var activeVIP_productName = ""
  516. var activeVIP_levels = ""
  517. var activeVIP_platforms = ""
  518. var activeVIP_point = 0
  519. var activeVIP_maxDeviceNum = 0
  520. var activeVIP_paymentModel = ""
  521. var activeVIP_isAi = ""
  522. var activeVIP_cycle = 0
  523. if let token = activeVIP_dict["id"] as? String { activeVIP_id = token }
  524. if let token = activeVIP_dict["userId"] as? String { activeVIP_userId = token }
  525. if let token = activeVIP_dict["status"] as? Int { activeVIP_status = token }
  526. if let token = activeVIP_dict["endDate"] as? String { activeVIP_endDate = token }
  527. if let token = activeVIP_dict["payType"] as? Int { activeVIP_payType = token }
  528. if let token = activeVIP_dict["productName"] as? String { activeVIP_productName = token }
  529. if let token = activeVIP_dict["levels"] as? String { activeVIP_levels = token }
  530. if let token = activeVIP_dict["platforms"] as? String { activeVIP_platforms = token }
  531. if let token = activeVIP_dict["point"] as? Int { activeVIP_point = token }
  532. if let token = activeVIP_dict["maxDeviceNum"] as? Int { activeVIP_maxDeviceNum = token }
  533. if let token = activeVIP_dict["paymentModel"] as? String { activeVIP_paymentModel = token }
  534. if let token = activeVIP_dict["isAi"] as? String { activeVIP_isAi = token }
  535. if let token = activeVIP_dict["cycle"] as? Int { activeVIP_cycle = token }
  536. 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, cycle: activeVIP_cycle)
  537. let activeAI_dict: NSDictionary = result_dict["activeAI"] as? NSDictionary ?? [:]
  538. var activeAI_id = ""
  539. var activeAI_userId = ""
  540. var activeAI_status = 0
  541. var activeAI_endDate = ""
  542. var activeAI_payType = 0
  543. var activeAI_productName = ""
  544. var activeAI_levels = ""
  545. var activeAI_platforms = ""
  546. var activeAI_point = 0
  547. var activeAI_maxDeviceNum = 0
  548. var activeAI_paymentModel = ""
  549. var activeAI_isAi = ""
  550. var activeAI_cycle = 0
  551. if let token = activeAI_dict["id"] as? String { activeAI_id = token }
  552. if let token = activeAI_dict["userId"] as? String { activeAI_userId = token }
  553. if let token = activeAI_dict["status"] as? Int { activeAI_status = token }
  554. if let token = activeAI_dict["endDate"] as? String { activeAI_endDate = token }
  555. if let token = activeAI_dict["payType"] as? Int { activeAI_payType = token }
  556. if let token = activeAI_dict["productName"] as? String { activeAI_productName = token }
  557. if let token = activeAI_dict["levels"] as? String { activeAI_levels = token }
  558. if let token = activeAI_dict["platforms"] as? String { activeAI_platforms = token }
  559. if let token = activeAI_dict["point"] as? Int { activeAI_point = token }
  560. if let token = activeAI_dict["maxDeviceNum"] as? Int { activeAI_maxDeviceNum = token }
  561. if let token = activeAI_dict["paymentModel"] as? String { activeAI_paymentModel = token }
  562. if let token = activeAI_dict["isAi"] as? String { activeAI_isAi = token }
  563. if let token = activeAI_dict["cycle"] as? Int { activeAI_cycle = token }
  564. 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, cycle: activeAI_cycle)
  565. if let token = result_dict["aiPoint"] { aiPoint = token as! Int }
  566. if let token = result_dict["validFlag"] { validFlag = token as! String }
  567. if let token = result_dict["isHaveAIDiscount"] { isHaveAIDiscount = token as! String }
  568. if let token = result_dict["canTrail"] { canTrail = token as! String }
  569. let userInfo = KMMemberUserInfo(id: userId, email: email, fullName: fullName, activeVIP: [userInfoActiveVIP], activeAI: [userInfoActiveAI], aiPoint: aiPoint, validFlag: validFlag, isHaveAIDiscount: isHaveAIDiscount, canTrail: canTrail)
  570. let result = KMMemberCenterResult(code: code, msg: message, userInfo: userInfo)
  571. if code == 200 {
  572. complete(true, result)
  573. } else {
  574. complete(false, result)
  575. }
  576. }
  577. }
  578. /**
  579. @abstract 退出登录
  580. @param complete 回调
  581. */
  582. func userLogout(_ complete: @escaping KMMemberCenterComplete) {
  583. let token: String = KMMemberInfo.shared.access_token
  584. if token == "" {
  585. complete(false, nil)
  586. return
  587. }
  588. let uuid: String = GetHardwareUUID() ?? ""
  589. let urlString = String(format: "%@/member-system-sso/user/logout?deviceSign=%@&appId=1", configuration.activityBaseURL(),uuid)
  590. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  591. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  592. } completion: { [weak self] (task, responseObject, error) in
  593. var dic: NSDictionary = [:]
  594. if error == nil, let responseObject = responseObject as? NSDictionary {
  595. dic = responseObject
  596. } else {
  597. var info = responseObject
  598. if let error = error {
  599. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  600. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  601. }
  602. }
  603. dic = (info as? NSDictionary) ?? [:]
  604. }
  605. let code: Int = dic["code"] as? Int ?? 0
  606. let result_bool: Bool = dic["result"] as? Bool ?? false
  607. let message: String = dic["msg"] as? String ?? ""
  608. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  609. if code == 200 {
  610. complete(true, result)
  611. } else {
  612. complete(false, result)
  613. }
  614. }
  615. }
  616. /**
  617. @abstract 获取用户当前会员情况
  618. @param complete 回调
  619. */
  620. func userRightList(_ complete: @escaping KMMemberCenterComplete) {
  621. let token: String = KMMemberInfo.shared.access_token
  622. if token == "" {
  623. complete(false, nil)
  624. return
  625. }
  626. let urlString = configuration.activityBaseURL() + "/member-system-sso//user/rightList"
  627. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
  628. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  629. } completion: { [weak self] (task, responseObject, error) in
  630. var dic: NSDictionary = [:]
  631. if error == nil, let responseObject = responseObject as? NSDictionary {
  632. dic = responseObject
  633. } else {
  634. var info = responseObject
  635. if let error = error {
  636. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  637. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  638. }
  639. }
  640. dic = (info as? NSDictionary) ?? [:]
  641. }
  642. let code: Int = dic["code"] as? Int ?? 0
  643. let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
  644. let message: String = dic["msg"] as? String ?? ""
  645. var results: [KMMemberUserInfoActiveVIP] = []
  646. for dict1 in result_Array {
  647. var activeVIP_id = ""
  648. var activeVIP_userId = ""
  649. var activeVIP_status = 0
  650. var activeVIP_endDate = ""
  651. var activeVIP_payType = 0
  652. var activeVIP_productName = ""
  653. var activeVIP_levels = ""
  654. var activeVIP_platforms = ""
  655. var activeVIP_point = 0
  656. var activeVIP_maxDeviceNum = 0
  657. var activeVIP_paymentModel = ""
  658. var activeVIP_isAi = ""
  659. if let token = dict1["id"] { activeVIP_id = token as! String }
  660. if let token = dict1["userId"] { activeVIP_userId = token as! String }
  661. if let token = dict1["status"] { activeVIP_status = token as! Int }
  662. if let token = dict1["endDate"] { activeVIP_endDate = token as! String }
  663. if let token = dict1["payType"] { activeVIP_payType = token as! Int }
  664. if let token = dict1["productName"] { activeVIP_productName = token as! String }
  665. if let token = dict1["levels"] { activeVIP_levels = token as! String }
  666. if let token = dict1["platforms"] { activeVIP_platforms = token as! String }
  667. if let token = dict1["point"] { activeVIP_point = token as! Int }
  668. if let token = dict1["maxDeviceNum"] { activeVIP_maxDeviceNum = token as! Int }
  669. if let token = dict1["paymentModel"] { activeVIP_paymentModel = token as! String }
  670. if let token = dict1["isAi"] { activeVIP_isAi = token as! String }
  671. 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)
  672. results.append(userInfoActiveVIP)
  673. }
  674. let result = KMMemberCenterResult(code: code, msg: message, activeVIPs: results)
  675. if code == 200 {
  676. complete(true, result)
  677. } else {
  678. complete(false, result)
  679. }
  680. }
  681. }
  682. /**
  683. @abstract 用户手动注销
  684. @param code 邮箱验证码
  685. @param complete 回调
  686. */
  687. func userLogOffForUser(code: String, _ complete: @escaping KMMemberCenterComplete) {
  688. let token: String = KMMemberInfo.shared.access_token
  689. if token == "" {
  690. complete(false, nil)
  691. return
  692. }
  693. let urlString = String(format: "%@/member-system-sso/user/logOffForUser?code=%@&appId=1", configuration.activityBaseURL(), code)
  694. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  695. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  696. } completion: { [weak self] (task, responseObject, error) in
  697. var dic: NSDictionary = [:]
  698. if error == nil, let responseObject = responseObject as? NSDictionary {
  699. dic = responseObject
  700. } else {
  701. var info = responseObject
  702. if let error = error {
  703. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  704. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  705. }
  706. }
  707. dic = (info as? NSDictionary) ?? [:]
  708. }
  709. let code: Int = dic["code"] as? Int ?? 0
  710. let message: String = dic["msg"] as? String ?? ""
  711. let result_dict: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  712. var currentTime = ""
  713. var logOffTime = ""
  714. if let token = result_dict["currentTime"] { currentTime = token as! String }
  715. if let token = result_dict["logOffTime"] { logOffTime = token as! String }
  716. let logOff = KMMemberLogOff(currentTime: currentTime, logOffTime: logOffTime)
  717. let result = KMMemberCenterResult(code: code, msg: message, logOff: logOff)
  718. if code == 200 {
  719. complete(true, result)
  720. } else {
  721. complete(false, result)
  722. }
  723. }
  724. }
  725. /**
  726. @abstract 撤销注销申请
  727. @param complete 回调
  728. */
  729. func userRevokeCancel(_ complete: @escaping KMMemberCenterComplete) {
  730. let token: String = KMMemberInfo.shared.access_token
  731. if token == "" {
  732. complete(false, nil)
  733. return
  734. }
  735. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/revokeCancel"
  736. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  737. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  738. } completion: { [weak self] (task, responseObject, error) in
  739. var dic: NSDictionary = [:]
  740. if error == nil, let responseObject = responseObject as? NSDictionary {
  741. dic = responseObject
  742. } else {
  743. var info = responseObject
  744. if let error = error {
  745. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  746. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  747. }
  748. }
  749. dic = (info as? NSDictionary) ?? [:]
  750. }
  751. let code: Int = dic["code"] as? Int ?? 0
  752. let message: String = dic["msg"] as? String ?? ""
  753. let result_Bool: Bool = dic["result"] as? Bool ?? false
  754. let result = KMMemberCenterResult(code: code, msg: message, result: result_Bool)
  755. if code == 200 {
  756. complete(true, result)
  757. } else {
  758. complete(false, result)
  759. }
  760. }
  761. }
  762. // MARK: 商品模块
  763. /**
  764. @abstract 获取上架中的产品
  765. @param isEducation 是否教育优惠
  766. @param complete 回调
  767. */
  768. func getListingProducts(isEducation: Int, _ complete: @escaping KMMemberProductComplete) {
  769. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getListingProducts"
  770. var platformId = "2"
  771. #if VERSION_FREE
  772. #if VERSION_DMG
  773. // DMG
  774. platformId = "2"
  775. #else
  776. // AppStore 免费版本
  777. #endif
  778. #else
  779. // AppStore 付费版
  780. platformId = "5"
  781. #endif
  782. let params: [String: Any] = ["isEducation": NSNumber(value: Int32(isEducation)),
  783. "platformId": platformId]
  784. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  785. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  786. } completion: { [weak self] (task, responseObject, error) in
  787. var dic: NSDictionary = [:]
  788. if error == nil, let responseObject = responseObject as? NSDictionary {
  789. dic = responseObject
  790. } else {
  791. var info = responseObject
  792. if let error = error {
  793. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  794. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  795. }
  796. }
  797. dic = (info as? NSDictionary) ?? [:]
  798. }
  799. let code: Int = dic["code"] as? Int ?? 0
  800. let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
  801. let message: String = dic["msg"] as? String ?? ""
  802. var results: [KMListingProductsModel] = []
  803. for dict1 in result_Array {
  804. var id = ""
  805. var productName = ""
  806. var maxDeviceNum = 0
  807. var levels = ""
  808. var platforms = ""
  809. var productLineId = 0
  810. var paymentModel = 0
  811. var cycle = 0
  812. var code = ""
  813. var price = NSNumber(value: 0.0)
  814. var displayPrice = NSNumber(value: 0.0)
  815. var upgradePrice = NSNumber(value: 0.0)
  816. var cnyPrice = NSNumber(value: 0.0)
  817. var displayCnyPrice = NSNumber(value: 0.0)
  818. if let token = dict1["id"] { id = token as? String ?? id }
  819. if let token = dict1["productName"] { productName = token as? String ?? productName }
  820. if let token = dict1["maxDeviceNum"] { maxDeviceNum = token as? Int ?? maxDeviceNum }
  821. if let token = dict1["levels"] { levels = token as? String ?? levels }
  822. if let token = dict1["platforms"] { platforms = token as? String ?? platforms }
  823. if let token = dict1["productLineId"] { productLineId = token as? Int ?? productLineId }
  824. if let token = dict1["paymentModel"] { paymentModel = token as? Int ?? paymentModel }
  825. if let token = dict1["cycle"] { cycle = token as? Int ?? cycle }
  826. if let token = dict1["code"] { code = token as? String ?? code }
  827. if let token = dict1["price"] { price = token as? NSNumber ?? price }
  828. if let token = dict1["displayPrice"] { displayPrice = token as? NSNumber ?? displayPrice }
  829. if let token = dict1["upgradePrice"] { upgradePrice = token as? NSNumber ?? upgradePrice }
  830. if let token = dict1["cnyPrice"] { cnyPrice = token as? NSNumber ?? cnyPrice }
  831. if let token = dict1["displayCnyPrice"] { displayCnyPrice = token as? NSNumber ?? displayCnyPrice }
  832. let products = KMListingProductsModel(id: id, productName: productName, price: price, maxDeviceNum: maxDeviceNum, displayPrice: displayPrice, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, cnyPrice: cnyPrice, displayCnyPrice: displayCnyPrice, upgradePrice: upgradePrice, code: code)
  833. results.append(products)
  834. }
  835. let result = KMMemberProductResult(code: code, msg: message, listingProducts: results)
  836. if code == 200 {
  837. complete(true, result)
  838. } else {
  839. complete(false, result)
  840. }
  841. }
  842. } else {
  843. print("Invalid URL")
  844. complete(false, nil)
  845. }
  846. }
  847. /**
  848. @abstract 获取已登录用户购买商品价格
  849. @param productId 购买的产品id
  850. @param isEducation 是否教育优惠
  851. @param complete 回调
  852. */
  853. func getProductPriceForBuy(productId: String, isEducation: Int, userId: String, _ complete: @escaping KMMemberProductComplete) {
  854. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getProductPriceForBuy"
  855. let params: [String: Any] = ["productId": productId,
  856. "isEducation": isEducation,
  857. "userId": userId]
  858. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  859. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  860. } completion: { [weak self] (task, responseObject, error) in
  861. var dic: NSDictionary = [:]
  862. if error == nil, let responseObject = responseObject as? NSDictionary {
  863. dic = responseObject
  864. } else {
  865. var info = responseObject
  866. if let error = error {
  867. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  868. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  869. }
  870. }
  871. dic = (info as? NSDictionary) ?? [:]
  872. }
  873. let code: Int = dic["code"] as? Int ?? 0
  874. let result_Array: [NSDictionary] = [dic["result"]] as? [NSDictionary] ?? [[:]]
  875. let message: String = dic["msg"] as? String ?? ""
  876. var results: [KMListingProductsModel] = []
  877. for dict1 in result_Array {
  878. var id = ""
  879. var productName = ""
  880. var maxDeviceNum = 0
  881. var levels = ""
  882. var platforms = ""
  883. var productLineId = 0
  884. var paymentModel = 0
  885. var cycle = 0
  886. var code = ""
  887. var price = NSNumber(value: 0.0)
  888. var displayPrice = NSNumber(value: 0.0)
  889. var upgradePrice = NSNumber(value: 0.0)
  890. var cnyPrice = NSNumber(value: 0.0)
  891. var displayCnyPrice = NSNumber(value: 0.0)
  892. if let token = dict1["id"] { id = token as? String ?? id }
  893. if let token = dict1["productName"] { productName = token as? String ?? productName }
  894. if let token = dict1["maxDeviceNum"] { maxDeviceNum = token as? Int ?? maxDeviceNum }
  895. if let token = dict1["levels"] { levels = token as? String ?? levels }
  896. if let token = dict1["platforms"] { platforms = token as? String ?? platforms }
  897. if let token = dict1["productLineId"] { productLineId = token as? Int ?? productLineId }
  898. if let token = dict1["paymentModel"] { paymentModel = token as? Int ?? paymentModel }
  899. if let token = dict1["cycle"] { cycle = token as? Int ?? cycle }
  900. if let token = dict1["code"] { code = token as? String ?? code }
  901. if let token = dict1["price"] { price = token as? NSNumber ?? price }
  902. if let token = dict1["displayPrice"] { displayPrice = token as? NSNumber ?? displayPrice }
  903. if let token = dict1["upgradePrice"] { upgradePrice = token as? NSNumber ?? upgradePrice }
  904. if let token = dict1["cnyPrice"] { cnyPrice = token as? NSNumber ?? cnyPrice }
  905. if let token = dict1["displayCnyPrice"] { displayCnyPrice = token as? NSNumber ?? displayCnyPrice }
  906. let products = KMListingProductsModel(id: id, productName: productName, price: price, maxDeviceNum: maxDeviceNum, displayPrice: displayPrice, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, cnyPrice: cnyPrice, displayCnyPrice: displayCnyPrice, upgradePrice: upgradePrice, code: code)
  907. results.append(products)
  908. }
  909. let result = KMMemberProductResult(code: code, msg: message, listingProducts: results)
  910. if code == 200 {
  911. complete(true, result)
  912. } else {
  913. complete(false, result)
  914. }
  915. }
  916. } else {
  917. print("Invalid URL")
  918. complete(false, nil)
  919. }
  920. }
  921. /**
  922. @abstract 获取批量阶段购买价格
  923. @param productId 购买的产品id
  924. @param num 批量个数
  925. @param complete 回调
  926. */
  927. func getBatchProductPrice(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  928. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getBatchProductPrice"
  929. let params: [String: Any] = ["productId": productId,
  930. "num": NSNumber(value: Int32(num))]
  931. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  932. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  933. } completion: { [weak self] (task, responseObject, error) in
  934. var dic: NSDictionary = [:]
  935. if error == nil, let responseObject = responseObject as? NSDictionary {
  936. dic = responseObject
  937. } else {
  938. var info = responseObject
  939. if let error = error {
  940. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  941. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  942. }
  943. }
  944. dic = (info as? NSDictionary) ?? [:]
  945. }
  946. let code: Int = dic["code"] as? Int ?? 0
  947. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  948. let message: String = dic["msg"] as? String ?? ""
  949. var productId = ""
  950. var totalPrice = ""
  951. var price = ""
  952. var batchPrice = ""
  953. var cnyPrice = ""
  954. var cnyBatchPrice = ""
  955. var cnyTotalPrice = ""
  956. if let token = result["productId"] { productId = token as? String ?? productId}
  957. if let token = result["totalPrice"] { totalPrice = token as? String ?? totalPrice}
  958. if let token = result["price"] { price = token as? String ?? price}
  959. if let token = result["batchPrice"] { batchPrice = token as? String ?? batchPrice}
  960. if let token = result["cnyPrice"] { cnyPrice = token as? String ?? cnyPrice}
  961. if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as? String ?? cnyBatchPrice}
  962. if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as? String ?? cnyTotalPrice}
  963. let products = KMBatchProductPriceModel(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
  964. let result1 = KMMemberProductResult(code: code, msg: message, batchProductPrice: products)
  965. if code == 200 {
  966. complete(true, result1)
  967. } else {
  968. complete(false, result1)
  969. }
  970. }
  971. } else {
  972. print("Invalid URL")
  973. }
  974. }
  975. /**
  976. @abstract 验证商品优惠券,返回商品优惠后价格
  977. @param productId 购买的产品id
  978. @param userId 用户ID
  979. @param code 优惠券
  980. @param complete 回调
  981. */
  982. func checkCoupon(productId: String, userId: String, code: String, _ complete: @escaping KMMemberProductComplete) {
  983. let token: String = KMMemberInfo.shared.access_token
  984. if token == "" {
  985. complete(false, nil)
  986. return
  987. }
  988. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkCoupon"
  989. let params: [String: Any] = ["productId": productId,
  990. "userId": userId,
  991. "code": code]
  992. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  993. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  994. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  995. } completion: { [weak self] (task, responseObject, error) in
  996. var dic: NSDictionary = [:]
  997. if error == nil, let responseObject = responseObject as? NSDictionary {
  998. dic = responseObject
  999. } else {
  1000. var info = responseObject
  1001. if let error = error {
  1002. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1003. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1004. }
  1005. }
  1006. dic = (info as? NSDictionary) ?? [:]
  1007. }
  1008. let requestCode: Int = dic["code"] as? Int ?? 0
  1009. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1010. let message: String = dic["msg"] as? String ?? ""
  1011. var id = ""
  1012. var productName = ""
  1013. var maxDeviceNum = 0
  1014. var levels = ""
  1015. var platforms = ""
  1016. var productLineId = 0
  1017. var paymentModel = 0
  1018. var cycle = 0
  1019. var code = ""
  1020. var price = NSNumber(value: 0.0)
  1021. var displayPrice = NSNumber(value: 0.0)
  1022. var upgradePrice = NSNumber(value: 0.0)
  1023. var cnyPrice = NSNumber(value: 0.0)
  1024. var displayCnyPrice = NSNumber(value: 0.0)
  1025. if let token = dic["id"] { id = token as? String ?? id }
  1026. if let token = dic["productName"] { productName = token as? String ?? productName }
  1027. if let token = dic["maxDeviceNum"] { maxDeviceNum = token as? Int ?? maxDeviceNum }
  1028. if let token = dic["levels"] { levels = token as? String ?? levels }
  1029. if let token = dic["platforms"] { platforms = token as? String ?? platforms }
  1030. if let token = dic["productLineId"] { productLineId = token as? Int ?? productLineId }
  1031. if let token = dic["paymentModel"] { paymentModel = token as? Int ?? paymentModel }
  1032. if let token = dic["cycle"] { cycle = token as? Int ?? cycle }
  1033. if let token = dic["code"] { code = token as? String ?? code }
  1034. if let token = dic["price"] { price = token as? NSNumber ?? price }
  1035. if let token = dic["displayPrice"] { displayPrice = token as? NSNumber ?? displayPrice }
  1036. if let token = dic["upgradePrice"] { upgradePrice = token as? NSNumber ?? upgradePrice }
  1037. if let token = dic["cnyPrice"] { cnyPrice = token as? NSNumber ?? cnyPrice }
  1038. if let token = dic["displayCnyPrice"] { displayCnyPrice = token as? NSNumber ?? displayCnyPrice }
  1039. 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, upgradePrice: upgradePrice, code: code)
  1040. let result1 = KMMemberProductResult(code: requestCode, msg: message, checkCoupon: products)
  1041. if requestCode == 200 {
  1042. complete(true, result1)
  1043. } else {
  1044. complete(false, result1)
  1045. }
  1046. }
  1047. } else {
  1048. print("Invalid URL")
  1049. complete(false, nil)
  1050. }
  1051. }
  1052. /**
  1053. @abstract 检查邮箱教育优惠资格
  1054. @param email 邮箱
  1055. @param complete 回调
  1056. */
  1057. func checkEducation(email: String, _ complete: @escaping KMMemberProductComplete) {
  1058. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkEducation"
  1059. let params: [String: Any] = ["email": email]
  1060. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  1061. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  1062. } completion: { [weak self] (task, responseObject, error) in
  1063. var dic: NSDictionary = [:]
  1064. if error == nil, let responseObject = responseObject as? NSDictionary {
  1065. dic = responseObject
  1066. } else {
  1067. var info = responseObject
  1068. if let error = error {
  1069. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1070. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1071. }
  1072. }
  1073. dic = (info as? NSDictionary) ?? [:]
  1074. }
  1075. let code: Int = dic["code"] as? Int ?? 0
  1076. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1077. let message: String = dic["msg"] as? String ?? ""
  1078. var productId = ""
  1079. var totalPrice = ""
  1080. var price = ""
  1081. var batchPrice = ""
  1082. var cnyPrice = ""
  1083. var cnyBatchPrice = ""
  1084. var cnyTotalPrice = ""
  1085. if let token = result["productId"] { productId = token as? String ?? productId}
  1086. if let token = result["totalPrice"] { totalPrice = token as? String ?? totalPrice}
  1087. if let token = result["price"] { price = token as? String ?? price}
  1088. if let token = result["batchPrice"] { batchPrice = token as? String ?? batchPrice}
  1089. if let token = result["cnyPrice"] { cnyPrice = token as? String ?? cnyPrice}
  1090. if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as? String ?? cnyBatchPrice}
  1091. if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as? String ?? cnyTotalPrice}
  1092. let products = KMBatchProductPriceModel(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
  1093. let result1 = KMMemberProductResult(code: code, msg: message, batchProductPrice: products)
  1094. if code == 200 {
  1095. complete(true, result1)
  1096. } else {
  1097. complete(false, result1)
  1098. }
  1099. }
  1100. } else {
  1101. print("Invalid URL")
  1102. complete(false, nil)
  1103. }
  1104. }
  1105. // MARK: 个人中心模块
  1106. // MARK: 订单模块
  1107. /**
  1108. @abstract 支付后查询订单状态
  1109. @param orderId 订单id
  1110. @param complete 回调
  1111. */
  1112. func getStateByOrderId(orderId: String, _ complete: @escaping KMMemberRequestInfoComplete) {
  1113. let token: String = KMMemberInfo.shared.access_token
  1114. if token == "" {
  1115. complete(false, nil)
  1116. return
  1117. }
  1118. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getStateByOrderId"
  1119. let params: [String: Any] = ["orderId": orderId]
  1120. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  1121. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  1122. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1123. } completion: { [weak self] (task, responseObject, error) in
  1124. var dic: NSDictionary = [:]
  1125. if error == nil, let responseObject = responseObject as? NSDictionary {
  1126. dic = responseObject
  1127. } else {
  1128. var info = responseObject
  1129. if let error = error {
  1130. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1131. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1132. }
  1133. }
  1134. dic = (info as? NSDictionary) ?? [:]
  1135. }
  1136. let code: Int = dic["code"] as? Int ?? 0
  1137. if code == 200 {
  1138. complete(true, dic)
  1139. } else {
  1140. complete(false, dic)
  1141. }
  1142. }
  1143. } else {
  1144. print("Invalid URL")
  1145. complete(false, nil)
  1146. }
  1147. }
  1148. /**
  1149. @abstract 创建订单(买断)
  1150. @param productId 产品id
  1151. @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
  1152. @param price 价格
  1153. @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
  1154. @param couponCode 优惠卷
  1155. @param num 批量购买数量
  1156. @param complete 回调
  1157. */
  1158. func createOrder(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  1159. let token: String = KMMemberInfo.shared.access_token
  1160. if token == "" {
  1161. complete(false, nil)
  1162. return
  1163. }
  1164. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/createOrder"
  1165. let params: [String: Any] = ["productId": productId,
  1166. "paymentMethod": paymentMethod,
  1167. "price": price,
  1168. "discountFlag": discountFlag,
  1169. "couponCode": couponCode,
  1170. "num": num]
  1171. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  1172. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1173. } completion: { [weak self] (task, responseObject, error) in
  1174. var dic: NSDictionary = [:]
  1175. if error == nil, let responseObject = responseObject as? NSDictionary {
  1176. dic = responseObject
  1177. } else {
  1178. var info = responseObject
  1179. if let error = error {
  1180. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1181. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1182. }
  1183. }
  1184. dic = (info as? NSDictionary) ?? [:]
  1185. }
  1186. let code: Int = dic["code"] as? Int ?? 0
  1187. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1188. let message: String = dic["msg"] as? String ?? ""
  1189. var thirdOrderNo = ""
  1190. var orderId = ""
  1191. var payHref = ""
  1192. if code == 200 {
  1193. if let token = result["thirdOrderNo"] { thirdOrderNo = token as? String ?? thirdOrderNo}
  1194. if let token = result["orderId"] { orderId = token as? String ?? orderId}
  1195. if let token = result["payHref"] { payHref = token as? String ?? payHref}
  1196. let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
  1197. let result1 = KMMemberProductResult(code: code, msg: message, createOrder: products)
  1198. complete(true, result1)
  1199. } else {
  1200. let result1 = KMMemberProductResult(code: code, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
  1201. complete(false, result1)
  1202. }
  1203. }
  1204. }
  1205. /**
  1206. @abstract 创建订单(订阅)
  1207. @param productId 产品id
  1208. @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
  1209. @param price 价格
  1210. @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
  1211. @param couponCode 优惠卷
  1212. @param num 批量购买数量
  1213. @param complete 回调
  1214. */
  1215. func createSubscriber(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  1216. let token: String = KMMemberInfo.shared.access_token
  1217. if token == "" {
  1218. complete(false, nil)
  1219. return
  1220. }
  1221. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/createSubscription"
  1222. let params: [String: Any] = ["productId": productId,
  1223. "paymentMethod": paymentMethod,
  1224. "price": price,
  1225. "discountFlag": discountFlag,
  1226. "couponCode": couponCode,
  1227. "num": num]
  1228. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  1229. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1230. } completion: { [weak self] (task, responseObject, error) in
  1231. var dic: NSDictionary = [:]
  1232. if error == nil, let responseObject = responseObject as? NSDictionary {
  1233. dic = responseObject
  1234. } else {
  1235. var info = responseObject
  1236. if let error = error {
  1237. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1238. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1239. }
  1240. }
  1241. dic = (info as? NSDictionary) ?? [:]
  1242. }
  1243. let code: Int = dic["code"] as? Int ?? 0
  1244. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1245. let message: String = dic["msg"] as? String ?? ""
  1246. var thirdOrderNo = ""
  1247. var orderId = ""
  1248. var payHref = ""
  1249. if code == 200 {
  1250. if let token = result["thirdOrderNo"] { thirdOrderNo = token as? String ?? thirdOrderNo}
  1251. if let token = result["orderId"] { orderId = token as? String ?? orderId}
  1252. if let token = result["payHref"] { payHref = token as? String ?? payHref}
  1253. let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
  1254. let result1 = KMMemberProductResult(code: code, msg: message, createOrder: products)
  1255. complete(true, result1)
  1256. } else {
  1257. let result1 = KMMemberProductResult(code: code, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
  1258. complete(false, result1)
  1259. }
  1260. }
  1261. }
  1262. /**
  1263. @abstract 获取订单列表
  1264. @param orderStatus 0全部1待支付
  1265. @param complete 回调
  1266. */
  1267. func getOrderListByStatus(orderStatus: Int, _ complete: @escaping KMMemberRequestInfoComplete) {
  1268. let token: String = KMMemberInfo.shared.access_token
  1269. if token == "" {
  1270. complete(false, nil)
  1271. return
  1272. }
  1273. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getOrderListByStatus"
  1274. let params: [String: Any] = ["orderStatus": orderStatus]
  1275. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  1276. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  1277. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1278. } completion: { [weak self] (task, responseObject, error) in
  1279. var dic: NSDictionary = [:]
  1280. if error == nil, let responseObject = responseObject as? NSDictionary {
  1281. dic = responseObject
  1282. } else {
  1283. var info = responseObject
  1284. if let error = error {
  1285. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1286. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1287. }
  1288. }
  1289. dic = (info as? NSDictionary) ?? [:]
  1290. }
  1291. let code: Int = dic["code"] as? Int ?? 0
  1292. if code == 200 {
  1293. complete(true, dic)
  1294. } else {
  1295. complete(false, dic)
  1296. }
  1297. // var thirdOrderNo = ""
  1298. // var orderId = ""
  1299. // var payHref = ""
  1300. // if code == 200 {
  1301. // if let token = result["thirdOrderNo"] { thirdOrderNo = token as! String }
  1302. // if let token = result["orderId"] { orderId = token as! String }
  1303. // if let token = result["payHref"] { payHref = token as! String }
  1304. // let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
  1305. // let result1 = KMMemberProductResult(code: code, msg: message, createOrder: products)
  1306. // complete(true, result1)
  1307. // } else {
  1308. // let result1 = KMMemberProductResult(code: code, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
  1309. // complete(false, result1)
  1310. // }
  1311. }
  1312. } else {
  1313. complete(false, nil)
  1314. }
  1315. }
  1316. /**
  1317. @abstract 关闭订单
  1318. @param orderId 订单id
  1319. @param complete 回调
  1320. */
  1321. func closeByOrderId(orderId: String, _ complete: @escaping KMMemberRequestInfoComplete) {
  1322. let token: String = KMMemberInfo.shared.access_token
  1323. if token == "" {
  1324. complete(false, nil)
  1325. return
  1326. }
  1327. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/closeOrder"
  1328. let params: [String: Any] = ["orderId": orderId]
  1329. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  1330. KMRequestServer.requestServer.request(urlString: urlNewString, method: .post, params: nil) { requestSerializer in
  1331. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1332. } completion: { [weak self] (task, responseObject, error) in
  1333. var dic: NSDictionary = [:]
  1334. if error == nil, let responseObject = responseObject as? NSDictionary {
  1335. dic = responseObject
  1336. } else {
  1337. var info = responseObject
  1338. if let error = error {
  1339. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1340. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1341. }
  1342. }
  1343. dic = (info as? NSDictionary) ?? [:]
  1344. }
  1345. let code: Int = dic["code"] as? Int ?? 0
  1346. if code == 200 {
  1347. complete(true, dic)
  1348. } else {
  1349. complete(false, dic)
  1350. }
  1351. }
  1352. } else {
  1353. complete(false, nil)
  1354. }
  1355. }
  1356. // MARK: 苹果支付
  1357. /**
  1358. @abstract APPstore 权益校验
  1359. @param applePayProductId
  1360. @param transactionId
  1361. @param productCode
  1362. @param complete 回调
  1363. */
  1364. func appStoreEquityVerification(applePayProductId: String, transactionId: String, productCode: String, _ complete: @escaping KMMemberProductComplete) {
  1365. let token: String = KMMemberInfo.shared.access_token
  1366. if token == "" {
  1367. complete(false, nil)
  1368. return
  1369. }
  1370. let urlString = configuration.activityBaseURL() + "/member-system-website/applePay/appStoreEquityVerification"
  1371. let params: [String: Any] = ["userId": KMMemberInfo.shared.userID,
  1372. "applePayProductId": applePayProductId,
  1373. "transactionId": transactionId,
  1374. "productCode": productCode]
  1375. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  1376. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1377. } completion: { [weak self] (task, responseObject, error) in
  1378. var dic: NSDictionary = [:]
  1379. if error == nil, let responseObject = responseObject as? NSDictionary {
  1380. dic = responseObject
  1381. } else {
  1382. var info = responseObject
  1383. if let error = error {
  1384. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1385. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1386. }
  1387. }
  1388. dic = (info as? NSDictionary) ?? [:]
  1389. }
  1390. let code: Int = dic["code"] as? Int ?? 0
  1391. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1392. let message: String = dic["msg"] as? String ?? ""
  1393. let result1 = KMMemberProductResult(code: code, msg: message, result: "")
  1394. if code == 200 {
  1395. complete(true, result1)
  1396. } else {
  1397. complete(false, result1)
  1398. }
  1399. }
  1400. }
  1401. // MARK: 评估模块
  1402. // MARK: 活动模块
  1403. // MARK: 翻译模块
  1404. // MARK: AI模块
  1405. // MARK: 会员赠送模块
  1406. // MARK: Error Code
  1407. static func typeOfMessage(type: KMMemberCenterErrorCodeType?) -> String {
  1408. var result: String = ""
  1409. switch type {
  1410. case .EXCEPTION_MSG_TOKEN_IS_INVALID:
  1411. result = "无效的token或者token已过期"
  1412. break;
  1413. case .EXCEPTION_MSG_DEVICE_NUM_MAX:
  1414. result = "您的登录设备已达上限,请退出其他设备重新登录"
  1415. break;
  1416. case .EXCEPTION_MSG_USER_NOT_LOGIN:
  1417. result = "用户没有登录,请登录后再访问"
  1418. break;
  1419. case .EMAIL_VERIFY_CODE_KEY_ERROR:
  1420. result = "email code error!"
  1421. break;
  1422. case .EMAIL_REGISTER_ERROR:
  1423. result = "Register error!"
  1424. break;
  1425. case .EXCEPTION_MSG_PASSWORD_ERROR:
  1426. result = NSLocalizedString("Password error.", tableName: "MemberCenterLocalizable", comment: "")
  1427. break;
  1428. case .EXCEPTION_MSG_CODE_ACTION_ERROR:
  1429. result = "code action error"
  1430. break;
  1431. case .EXCEPTION_MSG_CODE_SEND_ERROR:
  1432. result = "code send error"
  1433. break;
  1434. case .EXCEPTION_MAIL_CODE_SEND_ERROR:
  1435. result = "mail send error"
  1436. break;
  1437. case .VERIFY_CODE_SEND_TOO_QUICKLY:
  1438. result = "code send too quickly"
  1439. break;
  1440. case .EXCEPTION_MSG_EMAIL_EXIST:
  1441. result = "该邮箱已有账号,请前往登录"
  1442. break;
  1443. case .EXCEPTION_MSG_EMAIL_NOT_REGISTER:
  1444. result = NSLocalizedString("This email has not been registered, please log in through the account verification code, we will automatically register an account for you.", tableName: "MemberCenterLocalizable", comment: "")
  1445. break;
  1446. case .EXCEPTION_MSG_EMAIL_LOGOUT_ING:
  1447. result = "注销中,无法登录,若有问题可联系客服"
  1448. break;
  1449. case .EXCEPTION_MSG_EMAIL_INVALID:
  1450. result = NSLocalizedString("Email format error. Please enter the correct email.", tableName: "MemberCenterLocalizable", comment: "")
  1451. break;
  1452. case .EXCEPTION_MSG_PASSWORD_NOT_INCONSISTENT:
  1453. result = "密码不一致,请重新输入"
  1454. break;
  1455. case .EXCEPTION_MSG_PASSWORD_SIZE_MIN:
  1456. result = "密码请包含6~24个字符"
  1457. break;
  1458. case .EXCEPTION_MSG_PASSWORD_SIZE_MAX:
  1459. result = "密码请包含6~24个字符"
  1460. break;
  1461. case .EXCEPTION_MSG_PLEASE_ADD_AUTH_CONFIG:
  1462. result = "please add auth config"
  1463. break;
  1464. case .EXCEPTION_MSG_USER_SUBSCRIPTION_IN_PROGRESS:
  1465. result = "您目前还在订阅期内,暂时无法注销,请订阅期结束后再点击注销账号"
  1466. break;
  1467. case .EXCEPTION_TIME_TRANSFER_ERROR:
  1468. result = "时间转换失败"
  1469. break;
  1470. case .EXCEPTION_MSG_PASSWORD_CONTAIN_EMPTY:
  1471. result = "密码不能包含空格"
  1472. break;
  1473. case .UNKNOWN:
  1474. result = "UNKNOWN"
  1475. break;
  1476. case .SUCCESS:
  1477. result = "SUCCESS"
  1478. break;
  1479. default:
  1480. result = "Network error"
  1481. }
  1482. return result
  1483. }
  1484. }