KMMemberCenterManager.swift 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641
  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 {
  527. // 创建一个日期格式化器
  528. let dateFormatter = DateFormatter()
  529. dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
  530. // 将字符串转换为日期对象
  531. if let date = dateFormatter.date(from: token) {
  532. // 创建一个新的日期格式化器,用于只显示天
  533. let dayFormatter = DateFormatter()
  534. dayFormatter.dateFormat = "yyyy-MM-dd" // 只保留年月日部分
  535. activeVIP_endDate = dayFormatter.string(from: date)
  536. }
  537. }
  538. if let token = activeVIP_dict["payType"] as? Int { activeVIP_payType = token }
  539. if let token = activeVIP_dict["productName"] as? String { activeVIP_productName = token }
  540. if let token = activeVIP_dict["levels"] as? String { activeVIP_levels = token }
  541. if let token = activeVIP_dict["platforms"] as? String { activeVIP_platforms = token }
  542. if let token = activeVIP_dict["point"] as? Int { activeVIP_point = token }
  543. if let token = activeVIP_dict["maxDeviceNum"] as? Int { activeVIP_maxDeviceNum = token }
  544. if let token = activeVIP_dict["paymentModel"] as? String { activeVIP_paymentModel = token }
  545. if let token = activeVIP_dict["isAi"] as? String { activeVIP_isAi = token }
  546. if let token = activeVIP_dict["cycle"] as? Int { activeVIP_cycle = token }
  547. 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)
  548. let activeAI_dict: NSDictionary = result_dict["activeAI"] as? NSDictionary ?? [:]
  549. var activeAI_id = ""
  550. var activeAI_userId = ""
  551. var activeAI_status = 0
  552. var activeAI_endDate = ""
  553. var activeAI_payType = 0
  554. var activeAI_productName = ""
  555. var activeAI_levels = ""
  556. var activeAI_platforms = ""
  557. var activeAI_point = 0
  558. var activeAI_maxDeviceNum = 0
  559. var activeAI_paymentModel = ""
  560. var activeAI_isAi = ""
  561. var activeAI_cycle = 0
  562. if let token = activeAI_dict["id"] as? String { activeAI_id = token }
  563. if let token = activeAI_dict["userId"] as? String { activeAI_userId = token }
  564. if let token = activeAI_dict["status"] as? Int { activeAI_status = token }
  565. if let token = activeAI_dict["endDate"] as? String { activeAI_endDate = token }
  566. if let token = activeAI_dict["payType"] as? Int { activeAI_payType = token }
  567. if let token = activeAI_dict["productName"] as? String { activeAI_productName = token }
  568. if let token = activeAI_dict["levels"] as? String { activeAI_levels = token }
  569. if let token = activeAI_dict["platforms"] as? String { activeAI_platforms = token }
  570. if let token = activeAI_dict["point"] as? Int { activeAI_point = token }
  571. if let token = activeAI_dict["maxDeviceNum"] as? Int { activeAI_maxDeviceNum = token }
  572. if let token = activeAI_dict["paymentModel"] as? String { activeAI_paymentModel = token }
  573. if let token = activeAI_dict["isAi"] as? String { activeAI_isAi = token }
  574. if let token = activeAI_dict["cycle"] as? Int { activeAI_cycle = token }
  575. 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)
  576. if let token = result_dict["aiPoint"] { aiPoint = token as! Int }
  577. if let token = result_dict["validFlag"] { validFlag = token as! String }
  578. if let token = result_dict["isHaveAIDiscount"] { isHaveAIDiscount = token as! String }
  579. if let token = result_dict["canTrail"] { canTrail = token as! String }
  580. let userInfo = KMMemberUserInfo(id: userId, email: email, fullName: fullName, activeVIP: [userInfoActiveVIP], activeAI: [userInfoActiveAI], aiPoint: aiPoint, validFlag: validFlag, isHaveAIDiscount: isHaveAIDiscount, canTrail: canTrail)
  581. let result = KMMemberCenterResult(code: code, msg: message, userInfo: userInfo)
  582. if code == 200 {
  583. complete(true, result)
  584. } else {
  585. complete(false, result)
  586. }
  587. }
  588. }
  589. /**
  590. @abstract 退出登录
  591. @param complete 回调
  592. */
  593. func userLogout(_ complete: @escaping KMMemberCenterComplete) {
  594. let token: String = KMMemberInfo.shared.access_token
  595. if token == "" {
  596. complete(false, nil)
  597. return
  598. }
  599. let uuid: String = GetHardwareUUID() ?? ""
  600. let urlString = String(format: "%@/member-system-sso/user/logout?deviceSign=%@&appId=1", configuration.activityBaseURL(),uuid)
  601. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  602. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  603. } completion: { [weak self] (task, responseObject, error) in
  604. var dic: NSDictionary = [:]
  605. if error == nil, let responseObject = responseObject as? NSDictionary {
  606. dic = responseObject
  607. } else {
  608. var info = responseObject
  609. if let error = error {
  610. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  611. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  612. }
  613. }
  614. dic = (info as? NSDictionary) ?? [:]
  615. }
  616. let code: Int = dic["code"] as? Int ?? 0
  617. let result_bool: Bool = dic["result"] as? Bool ?? false
  618. let message: String = dic["msg"] as? String ?? ""
  619. let result = KMMemberCenterResult(code: code, msg: message, result: result_bool)
  620. if code == 200 {
  621. complete(true, result)
  622. } else {
  623. complete(false, result)
  624. }
  625. }
  626. }
  627. /**
  628. @abstract 获取用户当前会员情况
  629. @param complete 回调
  630. */
  631. func userRightList(_ complete: @escaping KMMemberCenterComplete) {
  632. let token: String = KMMemberInfo.shared.access_token
  633. if token == "" {
  634. complete(false, nil)
  635. return
  636. }
  637. let urlString = configuration.activityBaseURL() + "/member-system-sso//user/rightList"
  638. KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
  639. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  640. } completion: { [weak self] (task, responseObject, error) in
  641. var dic: NSDictionary = [:]
  642. if error == nil, let responseObject = responseObject as? NSDictionary {
  643. dic = responseObject
  644. } else {
  645. var info = responseObject
  646. if let error = error {
  647. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  648. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  649. }
  650. }
  651. dic = (info as? NSDictionary) ?? [:]
  652. }
  653. let code: Int = dic["code"] as? Int ?? 0
  654. let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
  655. let message: String = dic["msg"] as? String ?? ""
  656. var results: [KMMemberUserInfoActiveVIP] = []
  657. for dict1 in result_Array {
  658. var activeVIP_id = ""
  659. var activeVIP_userId = ""
  660. var activeVIP_status = 0
  661. var activeVIP_endDate = ""
  662. var activeVIP_payType = 0
  663. var activeVIP_productName = ""
  664. var activeVIP_levels = ""
  665. var activeVIP_platforms = ""
  666. var activeVIP_point = 0
  667. var activeVIP_maxDeviceNum = 0
  668. var activeVIP_paymentModel = ""
  669. var activeVIP_isAi = ""
  670. if let token = dict1["id"] { activeVIP_id = token as! String }
  671. if let token = dict1["userId"] { activeVIP_userId = token as! String }
  672. if let token = dict1["status"] { activeVIP_status = token as! Int }
  673. if let token = dict1["endDate"] { activeVIP_endDate = token as! String }
  674. if let token = dict1["payType"] { activeVIP_payType = token as! Int }
  675. if let token = dict1["productName"] { activeVIP_productName = token as! String }
  676. if let token = dict1["levels"] { activeVIP_levels = token as! String }
  677. if let token = dict1["platforms"] { activeVIP_platforms = token as! String }
  678. if let token = dict1["point"] { activeVIP_point = token as! Int }
  679. if let token = dict1["maxDeviceNum"] { activeVIP_maxDeviceNum = token as! Int }
  680. if let token = dict1["paymentModel"] { activeVIP_paymentModel = token as! String }
  681. if let token = dict1["isAi"] { activeVIP_isAi = token as! String }
  682. 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)
  683. results.append(userInfoActiveVIP)
  684. }
  685. let result = KMMemberCenterResult(code: code, msg: message, activeVIPs: results)
  686. if code == 200 {
  687. complete(true, result)
  688. } else {
  689. complete(false, result)
  690. }
  691. }
  692. }
  693. /**
  694. @abstract 用户手动注销
  695. @param code 邮箱验证码
  696. @param complete 回调
  697. */
  698. func userLogOffForUser(code: String, _ complete: @escaping KMMemberCenterComplete) {
  699. let token: String = KMMemberInfo.shared.access_token
  700. if token == "" {
  701. complete(false, nil)
  702. return
  703. }
  704. let urlString = String(format: "%@/member-system-sso/user/logOffForUser?code=%@&appId=1", configuration.activityBaseURL(), code)
  705. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  706. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  707. } completion: { [weak self] (task, responseObject, error) in
  708. var dic: NSDictionary = [:]
  709. if error == nil, let responseObject = responseObject as? NSDictionary {
  710. dic = responseObject
  711. } else {
  712. var info = responseObject
  713. if let error = error {
  714. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  715. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  716. }
  717. }
  718. dic = (info as? NSDictionary) ?? [:]
  719. }
  720. let code: Int = dic["code"] as? Int ?? 0
  721. let message: String = dic["msg"] as? String ?? ""
  722. let result_dict: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  723. var currentTime = ""
  724. var logOffTime = ""
  725. if let token = result_dict["currentTime"] { currentTime = token as! String }
  726. if let token = result_dict["logOffTime"] { logOffTime = token as! String }
  727. let logOff = KMMemberLogOff(currentTime: currentTime, logOffTime: logOffTime)
  728. let result = KMMemberCenterResult(code: code, msg: message, logOff: logOff)
  729. if code == 200 {
  730. complete(true, result)
  731. } else {
  732. complete(false, result)
  733. }
  734. }
  735. }
  736. /**
  737. @abstract 撤销注销申请
  738. @param complete 回调
  739. */
  740. func userRevokeCancel(_ complete: @escaping KMMemberCenterComplete) {
  741. let token: String = KMMemberInfo.shared.access_token
  742. if token == "" {
  743. complete(false, nil)
  744. return
  745. }
  746. let urlString = configuration.activityBaseURL() + "/member-system-sso/user/revokeCancel"
  747. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
  748. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  749. } completion: { [weak self] (task, responseObject, error) in
  750. var dic: NSDictionary = [:]
  751. if error == nil, let responseObject = responseObject as? NSDictionary {
  752. dic = responseObject
  753. } else {
  754. var info = responseObject
  755. if let error = error {
  756. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  757. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  758. }
  759. }
  760. dic = (info as? NSDictionary) ?? [:]
  761. }
  762. let code: Int = dic["code"] as? Int ?? 0
  763. let message: String = dic["msg"] as? String ?? ""
  764. let result_Bool: Bool = dic["result"] as? Bool ?? false
  765. let result = KMMemberCenterResult(code: code, msg: message, result: result_Bool)
  766. if code == 200 {
  767. complete(true, result)
  768. } else {
  769. complete(false, result)
  770. }
  771. }
  772. }
  773. // MARK: 商品模块
  774. /**
  775. @abstract 获取上架中的产品
  776. @param isEducation 是否教育优惠
  777. @param complete 回调
  778. */
  779. func getListingProducts(isEducation: Int, _ complete: @escaping KMMemberProductComplete) {
  780. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getListingProducts"
  781. var platformId = "2"
  782. #if VERSION_FREE
  783. #if VERSION_DMG
  784. // DMG
  785. platformId = "2"
  786. #else
  787. // AppStore 免费版本
  788. #endif
  789. #else
  790. // AppStore 付费版
  791. platformId = "5"
  792. #endif
  793. let params: [String: Any] = ["isEducation": NSNumber(value: Int32(isEducation)),
  794. "platformId": platformId]
  795. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  796. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  797. } completion: { [weak self] (task, responseObject, error) in
  798. var dic: NSDictionary = [:]
  799. if error == nil, let responseObject = responseObject as? NSDictionary {
  800. dic = responseObject
  801. } else {
  802. var info = responseObject
  803. if let error = error {
  804. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  805. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  806. }
  807. }
  808. dic = (info as? NSDictionary) ?? [:]
  809. }
  810. let requestCode: Int = dic["code"] as? Int ?? 0
  811. let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
  812. let message: String = dic["msg"] as? String ?? ""
  813. var results: [KMListingProductsModel] = []
  814. for dict1 in result_Array {
  815. var id = ""
  816. var productName = ""
  817. var maxDeviceNum = 0
  818. var levels = ""
  819. var platforms = ""
  820. var productLineId = 0
  821. var paymentModel = 0
  822. var cycle = 0
  823. var code = ""
  824. var price = NSNumber(value: 0.0)
  825. var displayPrice = NSNumber(value: 0.0)
  826. var upgradePrice = NSNumber(value: 0.0)
  827. var cnyPrice = NSNumber(value: 0.0)
  828. var displayCnyPrice = NSNumber(value: 0.0)
  829. if let token = dict1["id"] { id = token as? String ?? id }
  830. if let token = dict1["productName"] { productName = token as? String ?? productName }
  831. if let token = dict1["maxDeviceNum"] { maxDeviceNum = token as? Int ?? maxDeviceNum }
  832. if let token = dict1["levels"] { levels = token as? String ?? levels }
  833. if let token = dict1["platforms"] { platforms = token as? String ?? platforms }
  834. if let token = dict1["productLineId"] { productLineId = token as? Int ?? productLineId }
  835. if let token = dict1["paymentModel"] { paymentModel = token as? Int ?? paymentModel }
  836. if let token = dict1["cycle"] { cycle = token as? Int ?? cycle }
  837. if let token = dict1["code"] { code = token as? String ?? code }
  838. if let token = dict1["price"] { price = token as? NSNumber ?? price }
  839. if let token = dict1["displayPrice"] { displayPrice = token as? NSNumber ?? displayPrice }
  840. if let token = dict1["upgradePrice"] { upgradePrice = token as? NSNumber ?? upgradePrice }
  841. if let token = dict1["cnyPrice"] { cnyPrice = token as? NSNumber ?? cnyPrice }
  842. if let token = dict1["displayCnyPrice"] { displayCnyPrice = token as? NSNumber ?? displayCnyPrice }
  843. 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)
  844. results.append(products)
  845. }
  846. let result = KMMemberProductResult(code: requestCode, msg: message, listingProducts: results)
  847. if requestCode == 200 {
  848. complete(true, result)
  849. } else {
  850. complete(false, result)
  851. }
  852. }
  853. } else {
  854. print("Invalid URL")
  855. complete(false, nil)
  856. }
  857. }
  858. /**
  859. @abstract 获取已登录用户购买商品价格
  860. @param productId 购买的产品id
  861. @param isEducation 是否教育优惠
  862. @param complete 回调
  863. */
  864. func getProductPriceForBuy(productId: String, isEducation: Int, userId: String, _ complete: @escaping KMMemberProductComplete) {
  865. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getProductPriceForBuy"
  866. let params: [String: Any] = ["productId": productId,
  867. "isEducation": isEducation,
  868. "userId": userId]
  869. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  870. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  871. } completion: { [weak self] (task, responseObject, error) in
  872. var dic: NSDictionary = [:]
  873. if error == nil, let responseObject = responseObject as? NSDictionary {
  874. dic = responseObject
  875. } else {
  876. var info = responseObject
  877. if let error = error {
  878. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  879. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  880. }
  881. }
  882. dic = (info as? NSDictionary) ?? [:]
  883. }
  884. let requestCode: Int = dic["code"] as? Int ?? 0
  885. let result_Array: [NSDictionary] = [dic["result"]] as? [NSDictionary] ?? [[:]]
  886. let message: String = dic["msg"] as? String ?? ""
  887. var results: [KMListingProductsModel] = []
  888. for dict1 in result_Array {
  889. var id = ""
  890. var productName = ""
  891. var maxDeviceNum = 0
  892. var levels = ""
  893. var platforms = ""
  894. var productLineId = 0
  895. var paymentModel = 0
  896. var cycle = 0
  897. var code = ""
  898. var price = NSNumber(value: 0.0)
  899. var displayPrice = NSNumber(value: 0.0)
  900. var upgradePrice = NSNumber(value: 0.0)
  901. var cnyPrice = NSNumber(value: 0.0)
  902. var displayCnyPrice = NSNumber(value: 0.0)
  903. if let token = dict1["id"] { id = token as? String ?? id }
  904. if let token = dict1["productName"] { productName = token as? String ?? productName }
  905. if let token = dict1["maxDeviceNum"] { maxDeviceNum = token as? Int ?? maxDeviceNum }
  906. if let token = dict1["levels"] { levels = token as? String ?? levels }
  907. if let token = dict1["platforms"] { platforms = token as? String ?? platforms }
  908. if let token = dict1["productLineId"] { productLineId = token as? Int ?? productLineId }
  909. if let token = dict1["paymentModel"] { paymentModel = token as? Int ?? paymentModel }
  910. if let token = dict1["cycle"] { cycle = token as? Int ?? cycle }
  911. if let token = dict1["code"] { code = token as? String ?? code }
  912. if let token = dict1["price"] { price = token as? NSNumber ?? price }
  913. if let token = dict1["displayPrice"] { displayPrice = token as? NSNumber ?? displayPrice }
  914. if let token = dict1["upgradePrice"] { upgradePrice = token as? NSNumber ?? upgradePrice }
  915. if let token = dict1["cnyPrice"] { cnyPrice = token as? NSNumber ?? cnyPrice }
  916. if let token = dict1["displayCnyPrice"] { displayCnyPrice = token as? NSNumber ?? displayCnyPrice }
  917. 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)
  918. results.append(products)
  919. }
  920. let result = KMMemberProductResult(code: requestCode, msg: message, listingProducts: results)
  921. if requestCode == 200 {
  922. complete(true, result)
  923. } else {
  924. complete(false, result)
  925. }
  926. }
  927. } else {
  928. print("Invalid URL")
  929. complete(false, nil)
  930. }
  931. }
  932. /**
  933. @abstract 获取批量阶段购买价格
  934. @param productId 购买的产品id
  935. @param num 批量个数
  936. @param complete 回调
  937. */
  938. func getBatchProductPrice(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  939. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getBatchProductPrice"
  940. let params: [String: Any] = ["productId": productId,
  941. "num": NSNumber(value: Int32(num))]
  942. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  943. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  944. } completion: { [weak self] (task, responseObject, error) in
  945. var dic: NSDictionary = [:]
  946. if error == nil, let responseObject = responseObject as? NSDictionary {
  947. dic = responseObject
  948. } else {
  949. var info = responseObject
  950. if let error = error {
  951. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  952. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  953. }
  954. }
  955. dic = (info as? NSDictionary) ?? [:]
  956. }
  957. let requestCode: Int = dic["code"] as? Int ?? 0
  958. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  959. let message: String = dic["msg"] as? String ?? ""
  960. var productId = ""
  961. var totalPrice = ""
  962. var price = ""
  963. var batchPrice = ""
  964. var cnyPrice = ""
  965. var cnyBatchPrice = ""
  966. var cnyTotalPrice = ""
  967. if let token = result["productId"] { productId = token as? String ?? productId}
  968. if let token = result["totalPrice"] { totalPrice = token as? String ?? totalPrice}
  969. if let token = result["price"] { price = token as? String ?? price}
  970. if let token = result["batchPrice"] { batchPrice = token as? String ?? batchPrice}
  971. if let token = result["cnyPrice"] { cnyPrice = token as? String ?? cnyPrice}
  972. if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as? String ?? cnyBatchPrice}
  973. if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as? String ?? cnyTotalPrice}
  974. let products = KMBatchProductPriceModel(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
  975. let result1 = KMMemberProductResult(code: requestCode, msg: message, batchProductPrice: products)
  976. if requestCode == 200 {
  977. complete(true, result1)
  978. } else {
  979. complete(false, result1)
  980. }
  981. }
  982. } else {
  983. print("Invalid URL")
  984. }
  985. }
  986. /**
  987. @abstract 验证商品优惠券,返回商品优惠后价格
  988. @param productId 购买的产品id
  989. @param userId 用户ID
  990. @param code 优惠券
  991. @param complete 回调
  992. */
  993. func checkCoupon(productId: String, userId: String, code: String, _ complete: @escaping KMMemberProductComplete) {
  994. let token: String = KMMemberInfo.shared.access_token
  995. if token == "" {
  996. complete(false, nil)
  997. return
  998. }
  999. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkCoupon"
  1000. let params: [String: Any] = ["productId": productId,
  1001. "userId": userId,
  1002. "code": code]
  1003. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  1004. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  1005. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1006. } completion: { [weak self] (task, responseObject, error) in
  1007. var dic: NSDictionary = [:]
  1008. if error == nil, let responseObject = responseObject as? NSDictionary {
  1009. dic = responseObject
  1010. } else {
  1011. var info = responseObject
  1012. if let error = error {
  1013. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1014. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1015. }
  1016. }
  1017. dic = (info as? NSDictionary) ?? [:]
  1018. }
  1019. let requestCode: Int = dic["code"] as? Int ?? 0
  1020. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1021. let message: String = dic["msg"] as? String ?? ""
  1022. var id = ""
  1023. var productName = ""
  1024. var maxDeviceNum = 0
  1025. var levels = ""
  1026. var platforms = ""
  1027. var productLineId = 0
  1028. var paymentModel = 0
  1029. var cycle = 0
  1030. var code = ""
  1031. var price = NSNumber(value: 0.0)
  1032. var displayPrice = NSNumber(value: 0.0)
  1033. var upgradePrice = NSNumber(value: 0.0)
  1034. var cnyPrice = NSNumber(value: 0.0)
  1035. var displayCnyPrice = NSNumber(value: 0.0)
  1036. if let token = dic["id"] { id = token as? String ?? id }
  1037. if let token = dic["productName"] { productName = token as? String ?? productName }
  1038. if let token = dic["maxDeviceNum"] { maxDeviceNum = token as? Int ?? maxDeviceNum }
  1039. if let token = dic["levels"] { levels = token as? String ?? levels }
  1040. if let token = dic["platforms"] { platforms = token as? String ?? platforms }
  1041. if let token = dic["productLineId"] { productLineId = token as? Int ?? productLineId }
  1042. if let token = dic["paymentModel"] { paymentModel = token as? Int ?? paymentModel }
  1043. if let token = dic["cycle"] { cycle = token as? Int ?? cycle }
  1044. if let token = dic["code"] { code = token as? String ?? code }
  1045. if let token = dic["price"] { price = token as? NSNumber ?? price }
  1046. if let token = dic["displayPrice"] { displayPrice = token as? NSNumber ?? displayPrice }
  1047. if let token = dic["upgradePrice"] { upgradePrice = token as? NSNumber ?? upgradePrice }
  1048. if let token = dic["cnyPrice"] { cnyPrice = token as? NSNumber ?? cnyPrice }
  1049. if let token = dic["displayCnyPrice"] { displayCnyPrice = token as? NSNumber ?? displayCnyPrice }
  1050. 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)
  1051. let result1 = KMMemberProductResult(code: requestCode, msg: message, checkCoupon: products)
  1052. if requestCode == 200 {
  1053. complete(true, result1)
  1054. } else {
  1055. complete(false, result1)
  1056. }
  1057. }
  1058. } else {
  1059. print("Invalid URL")
  1060. complete(false, nil)
  1061. }
  1062. }
  1063. /**
  1064. @abstract 检查邮箱教育优惠资格
  1065. @param email 邮箱
  1066. @param complete 回调
  1067. */
  1068. func checkEducation(email: String, _ complete: @escaping KMMemberProductComplete) {
  1069. let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkEducation"
  1070. let params: [String: Any] = ["email": email]
  1071. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  1072. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  1073. } completion: { [weak self] (task, responseObject, error) in
  1074. var dic: NSDictionary = [:]
  1075. if error == nil, let responseObject = responseObject as? NSDictionary {
  1076. dic = responseObject
  1077. } else {
  1078. var info = responseObject
  1079. if let error = error {
  1080. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1081. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1082. }
  1083. }
  1084. dic = (info as? NSDictionary) ?? [:]
  1085. }
  1086. let requestCode: Int = dic["code"] as? Int ?? 0
  1087. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1088. let message: String = dic["msg"] as? String ?? ""
  1089. var productId = ""
  1090. var totalPrice = ""
  1091. var price = ""
  1092. var batchPrice = ""
  1093. var cnyPrice = ""
  1094. var cnyBatchPrice = ""
  1095. var cnyTotalPrice = ""
  1096. if let token = result["productId"] { productId = token as? String ?? productId}
  1097. if let token = result["totalPrice"] { totalPrice = token as? String ?? totalPrice}
  1098. if let token = result["price"] { price = token as? String ?? price}
  1099. if let token = result["batchPrice"] { batchPrice = token as? String ?? batchPrice}
  1100. if let token = result["cnyPrice"] { cnyPrice = token as? String ?? cnyPrice}
  1101. if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as? String ?? cnyBatchPrice}
  1102. if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as? String ?? cnyTotalPrice}
  1103. let products = KMBatchProductPriceModel(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
  1104. let result1 = KMMemberProductResult(code: requestCode, msg: message, batchProductPrice: products)
  1105. if requestCode == 200 {
  1106. complete(true, result1)
  1107. } else {
  1108. complete(false, result1)
  1109. }
  1110. }
  1111. } else {
  1112. print("Invalid URL")
  1113. complete(false, nil)
  1114. }
  1115. }
  1116. // MARK: 个人中心模块
  1117. // MARK: 订单模块
  1118. /**
  1119. @abstract 支付后查询订单状态
  1120. @param orderId 订单id
  1121. @param complete 回调
  1122. */
  1123. func getStateByOrderId(orderId: String, _ complete: @escaping KMMemberRequestInfoComplete) {
  1124. let token: String = KMMemberInfo.shared.access_token
  1125. if token == "" {
  1126. complete(false, nil)
  1127. return
  1128. }
  1129. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getStateByOrderId"
  1130. let params: [String: Any] = ["orderId": orderId]
  1131. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  1132. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  1133. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1134. } completion: { [weak self] (task, responseObject, error) in
  1135. var dic: NSDictionary = [:]
  1136. if error == nil, let responseObject = responseObject as? NSDictionary {
  1137. dic = responseObject
  1138. } else {
  1139. var info = responseObject
  1140. if let error = error {
  1141. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1142. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1143. }
  1144. }
  1145. dic = (info as? NSDictionary) ?? [:]
  1146. }
  1147. let requestCode: Int = dic["code"] as? Int ?? 0
  1148. if requestCode == 200 {
  1149. complete(true, dic)
  1150. } else {
  1151. complete(false, dic)
  1152. }
  1153. }
  1154. } else {
  1155. print("Invalid URL")
  1156. complete(false, nil)
  1157. }
  1158. }
  1159. /**
  1160. @abstract 创建订单(买断)
  1161. @param productId 产品id
  1162. @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
  1163. @param price 价格
  1164. @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
  1165. @param couponCode 优惠卷
  1166. @param num 批量购买数量
  1167. @param complete 回调
  1168. */
  1169. func createOrder(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  1170. let token: String = KMMemberInfo.shared.access_token
  1171. if token == "" {
  1172. complete(false, nil)
  1173. return
  1174. }
  1175. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/createOrder"
  1176. let params: [String: Any] = ["productId": productId,
  1177. "paymentMethod": paymentMethod,
  1178. "price": price,
  1179. "discountFlag": discountFlag,
  1180. "couponCode": couponCode,
  1181. "num": num]
  1182. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  1183. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1184. } completion: { [weak self] (task, responseObject, error) in
  1185. var dic: NSDictionary = [:]
  1186. if error == nil, let responseObject = responseObject as? NSDictionary {
  1187. dic = responseObject
  1188. } else {
  1189. var info = responseObject
  1190. if let error = error {
  1191. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1192. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1193. }
  1194. }
  1195. dic = (info as? NSDictionary) ?? [:]
  1196. }
  1197. let requestCode: Int = dic["code"] as? Int ?? 0
  1198. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1199. let message: String = dic["msg"] as? String ?? ""
  1200. var thirdOrderNo = ""
  1201. var orderId = ""
  1202. var payHref = ""
  1203. if requestCode == 200 {
  1204. if let token = result["thirdOrderNo"] { thirdOrderNo = token as? String ?? thirdOrderNo}
  1205. if let token = result["orderId"] { orderId = token as? String ?? orderId}
  1206. if let token = result["payHref"] { payHref = token as? String ?? payHref}
  1207. let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
  1208. let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: products)
  1209. complete(true, result1)
  1210. } else {
  1211. let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
  1212. complete(false, result1)
  1213. }
  1214. }
  1215. }
  1216. /**
  1217. @abstract 创建订单(订阅)
  1218. @param productId 产品id
  1219. @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
  1220. @param price 价格
  1221. @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
  1222. @param couponCode 优惠卷
  1223. @param num 批量购买数量
  1224. @param complete 回调
  1225. */
  1226. func createSubscriber(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  1227. let token: String = KMMemberInfo.shared.access_token
  1228. if token == "" {
  1229. complete(false, nil)
  1230. return
  1231. }
  1232. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/createSubscription"
  1233. let params: [String: Any] = ["productId": productId,
  1234. "paymentMethod": paymentMethod,
  1235. "price": price,
  1236. "discountFlag": discountFlag,
  1237. "couponCode": couponCode,
  1238. "num": num]
  1239. KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
  1240. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1241. } completion: { [weak self] (task, responseObject, error) in
  1242. var dic: NSDictionary = [:]
  1243. if error == nil, let responseObject = responseObject as? NSDictionary {
  1244. dic = responseObject
  1245. } else {
  1246. var info = responseObject
  1247. if let error = error {
  1248. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1249. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1250. }
  1251. }
  1252. dic = (info as? NSDictionary) ?? [:]
  1253. }
  1254. let requestCode: Int = dic["code"] as? Int ?? 0
  1255. let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1256. let message: String = dic["msg"] as? String ?? ""
  1257. var thirdOrderNo = ""
  1258. var orderId = ""
  1259. var payHref = ""
  1260. if requestCode == 200 {
  1261. if let token = result["thirdOrderNo"] { thirdOrderNo = token as? String ?? thirdOrderNo}
  1262. if let token = result["orderId"] { orderId = token as? String ?? orderId}
  1263. if let token = result["payHref"] { payHref = token as? String ?? payHref}
  1264. let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
  1265. let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: products)
  1266. complete(true, result1)
  1267. } else {
  1268. let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
  1269. complete(false, result1)
  1270. }
  1271. }
  1272. }
  1273. /**
  1274. @abstract 获取订单列表
  1275. @param orderStatus 0全部1待支付
  1276. @param complete 回调
  1277. */
  1278. func getOrderListByStatus(orderStatus: Int, _ complete: @escaping KMMemberRequestInfoComplete) {
  1279. let token: String = KMMemberInfo.shared.access_token
  1280. if token == "" {
  1281. complete(false, nil)
  1282. return
  1283. }
  1284. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getOrderListByStatus"
  1285. let params: [String: Any] = ["orderStatus": orderStatus]
  1286. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  1287. KMRequestServer.requestServer.request(urlString: urlNewString, method: .get, params: nil) { requestSerializer in
  1288. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1289. } completion: { [weak self] (task, responseObject, error) in
  1290. var dic: NSDictionary = [:]
  1291. if error == nil, let responseObject = responseObject as? NSDictionary {
  1292. dic = responseObject
  1293. } else {
  1294. var info = responseObject
  1295. if let error = error {
  1296. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1297. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1298. }
  1299. }
  1300. dic = (info as? NSDictionary) ?? [:]
  1301. }
  1302. let requestCode: Int = dic["code"] as? Int ?? 0
  1303. if requestCode == 200 {
  1304. complete(true, dic)
  1305. } else {
  1306. complete(false, dic)
  1307. }
  1308. // var thirdOrderNo = ""
  1309. // var orderId = ""
  1310. // var payHref = ""
  1311. // if code == 200 {
  1312. // if let token = result["thirdOrderNo"] { thirdOrderNo = token as! String }
  1313. // if let token = result["orderId"] { orderId = token as! String }
  1314. // if let token = result["payHref"] { payHref = token as! String }
  1315. // let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
  1316. // let result1 = KMMemberProductResult(code: code, msg: message, createOrder: products)
  1317. // complete(true, result1)
  1318. // } else {
  1319. // let result1 = KMMemberProductResult(code: code, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
  1320. // complete(false, result1)
  1321. // }
  1322. }
  1323. } else {
  1324. complete(false, nil)
  1325. }
  1326. }
  1327. /**
  1328. @abstract 关闭订单
  1329. @param orderId 订单id
  1330. @param complete 回调
  1331. */
  1332. func closeByOrderId(orderId: String, _ complete: @escaping KMMemberRequestInfoComplete) {
  1333. let token: String = KMMemberInfo.shared.access_token
  1334. if token == "" {
  1335. complete(false, nil)
  1336. return
  1337. }
  1338. let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/closeOrder"
  1339. let params: [String: Any] = ["orderId": orderId]
  1340. if let urlNewString = constructURLString(baseURLString: urlString, parameters: params) {
  1341. KMRequestServer.requestServer.request(urlString: urlNewString, method: .post, params: nil) { requestSerializer in
  1342. requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1343. } completion: { [weak self] (task, responseObject, error) in
  1344. var dic: NSDictionary = [:]
  1345. if error == nil, let responseObject = responseObject as? NSDictionary {
  1346. dic = responseObject
  1347. } else {
  1348. var info = responseObject
  1349. if let error = error {
  1350. if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
  1351. info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
  1352. }
  1353. }
  1354. dic = (info as? NSDictionary) ?? [:]
  1355. }
  1356. let requestCode: Int = dic["code"] as? Int ?? 0
  1357. if requestCode == 200 {
  1358. complete(true, dic)
  1359. } else {
  1360. complete(false, dic)
  1361. }
  1362. }
  1363. } else {
  1364. complete(false, nil)
  1365. }
  1366. }
  1367. // MARK: 苹果支付
  1368. /**
  1369. @abstract APPstore 权益校验
  1370. @param applePayProductId
  1371. @param transactionId
  1372. @param productCode
  1373. @param complete 回调
  1374. */
  1375. func appStoreEquityVerification(applePayProductId: String, transactionId: String, productCode: String, _ complete: @escaping KMMemberProductComplete) {
  1376. let token: String = KMMemberInfo.shared.access_token
  1377. if token == "" {
  1378. complete(false, nil)
  1379. return
  1380. }
  1381. let urlString = configuration.activityBaseURL() + "/member-system-website/applePay/appStoreEquityVerification"
  1382. let bundleID = Bundle.main.object(forInfoDictionaryKey: "CFBundleIdentifier") ?? ""
  1383. let params: [String: Any] = ["appBundleId": bundleID,
  1384. "applePayProductId": applePayProductId,
  1385. "transactionId": transactionId,
  1386. "productCode": productCode]
  1387. let postData = try! JSONSerialization.data(withJSONObject: params)
  1388. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  1389. request.addValue("Bearer " + token, forHTTPHeaderField: "Authorization")
  1390. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  1391. request.httpMethod = "POST"
  1392. request.httpBody = postData
  1393. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  1394. guard let data = data else {
  1395. print(String(describing: error))
  1396. return
  1397. }
  1398. let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:]
  1399. if jsonObject != nil {
  1400. let code: Int = jsonObject!["code"] as? Int ?? 0
  1401. let result: NSDictionary = jsonObject!["result"] as? NSDictionary ?? [:]
  1402. let message: String = jsonObject!["msg"] as? String ?? ""
  1403. let result1 = KMMemberProductResult(code: code, msg: message, result: "")
  1404. if code == 200 {
  1405. complete(true, result1)
  1406. } else {
  1407. complete(false, result1)
  1408. }
  1409. } else {
  1410. complete(false, KMMemberProductResult(code: 0, msg: "", result: ""))
  1411. }
  1412. }
  1413. task.resume()
  1414. }
  1415. // MARK: 评估模块
  1416. // MARK: 活动模块
  1417. // MARK: 翻译模块
  1418. // MARK: AI模块
  1419. // MARK: 会员赠送模块
  1420. // MARK: Error Code
  1421. static func typeOfMessage(type: KMMemberCenterErrorCodeType?) -> String {
  1422. var result: String = ""
  1423. switch type {
  1424. case .EXCEPTION_MSG_TOKEN_IS_INVALID:
  1425. result = "无效的token或者token已过期"
  1426. break;
  1427. case .EXCEPTION_MSG_DEVICE_NUM_MAX:
  1428. result = "您的登录设备已达上限,请退出其他设备重新登录"
  1429. break;
  1430. case .EXCEPTION_MSG_USER_NOT_LOGIN:
  1431. result = "用户没有登录,请登录后再访问"
  1432. break;
  1433. case .EMAIL_VERIFY_CODE_KEY_ERROR:
  1434. result = "email code error!"
  1435. break;
  1436. case .EMAIL_REGISTER_ERROR:
  1437. result = "Register error!"
  1438. break;
  1439. case .EXCEPTION_MSG_PASSWORD_ERROR:
  1440. result = NSLocalizedString("Password error.", tableName: "MemberCenterLocalizable", comment: "")
  1441. break;
  1442. case .EXCEPTION_MSG_CODE_ACTION_ERROR:
  1443. result = "code action error"
  1444. break;
  1445. case .EXCEPTION_MSG_CODE_SEND_ERROR:
  1446. result = "code send error"
  1447. break;
  1448. case .EXCEPTION_MAIL_CODE_SEND_ERROR:
  1449. result = "mail send error"
  1450. break;
  1451. case .VERIFY_CODE_SEND_TOO_QUICKLY:
  1452. result = "code send too quickly"
  1453. break;
  1454. case .EXCEPTION_MSG_EMAIL_EXIST:
  1455. result = "该邮箱已有账号,请前往登录"
  1456. break;
  1457. case .EXCEPTION_MSG_EMAIL_NOT_REGISTER:
  1458. 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: "")
  1459. break;
  1460. case .EXCEPTION_MSG_EMAIL_LOGOUT_ING:
  1461. result = "注销中,无法登录,若有问题可联系客服"
  1462. break;
  1463. case .EXCEPTION_MSG_EMAIL_INVALID:
  1464. result = NSLocalizedString("Email format error. Please enter the correct email.", tableName: "MemberCenterLocalizable", comment: "")
  1465. break;
  1466. case .EXCEPTION_MSG_PASSWORD_NOT_INCONSISTENT:
  1467. result = "密码不一致,请重新输入"
  1468. break;
  1469. case .EXCEPTION_MSG_PASSWORD_SIZE_MIN:
  1470. result = "密码请包含6~24个字符"
  1471. break;
  1472. case .EXCEPTION_MSG_PASSWORD_SIZE_MAX:
  1473. result = "密码请包含6~24个字符"
  1474. break;
  1475. case .EXCEPTION_MSG_PLEASE_ADD_AUTH_CONFIG:
  1476. result = "please add auth config"
  1477. break;
  1478. case .EXCEPTION_MSG_USER_SUBSCRIPTION_IN_PROGRESS:
  1479. result = "您目前还在订阅期内,暂时无法注销,请订阅期结束后再点击注销账号"
  1480. break;
  1481. case .EXCEPTION_TIME_TRANSFER_ERROR:
  1482. result = "时间转换失败"
  1483. break;
  1484. case .EXCEPTION_MSG_PASSWORD_CONTAIN_EMPTY:
  1485. result = "密码不能包含空格"
  1486. break;
  1487. case .UNKNOWN:
  1488. result = "UNKNOWN"
  1489. break;
  1490. case .SUCCESS:
  1491. result = "SUCCESS"
  1492. break;
  1493. default:
  1494. result = "Network error"
  1495. }
  1496. return result
  1497. }
  1498. }