NewScanViewController.swift 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // NewScanViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2016/12/22.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import Alamofire
  10. import AlamofireImage
  11. import AlamofireObjectMapper
  12. import ObjectMapper
  13. import CocoaLumberjack
  14. class NewScanViewController: LBXScanViewController {
  15. var callbackResult: ((String)->Void)? = nil
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18. DDLogDebug("viewdid load................................")
  19. self.title = "扫一扫"
  20. }
  21. override func didReceiveMemoryWarning() {
  22. super.didReceiveMemoryWarning()
  23. // Dispose of any resources that can be recreated.
  24. }
  25. //扫码结果
  26. override func handleCodeResult(arrayResult: [LBXScanResult]) {
  27. for result:LBXScanResult in arrayResult
  28. {
  29. print(result.strScanned ?? "")
  30. }
  31. let result:LBXScanResult = arrayResult[0]
  32. if callbackResult != nil {
  33. callbackResult?(result.strScanned ?? "")
  34. self.popVC()
  35. }else {
  36. let url = NSURL(string: result.strScanned!)
  37. //会议签到功能
  38. var isMeetingCheck = false
  39. let allU = url?.absoluteString
  40. if allU != nil && allU!.contains("/checkin") && allU!.contains("x_meeting_assemble_control") {
  41. isMeetingCheck = true
  42. }
  43. if(isMeetingCheck) {//会议签到
  44. self.meetingCheck(url: allU!)
  45. }else {
  46. let query = url?.query
  47. let querys = query?.split("&")
  48. var meta = ""
  49. querys?.forEach { (e) in
  50. let name = e.split("=")[0]
  51. if name == "meta" {
  52. meta = e.split("=")[1]
  53. }
  54. }
  55. if meta != "" {//登录O2OA
  56. let account = O2AuthSDK.shared.myInfo()
  57. let loginURL = AppDelegate.o2Collect.generateURLWithAppContextKey(LoginContext.loginContextKey, query: LoginContext.scanCodeAuthActionQuery, parameter: ["##meta##":meta as AnyObject])
  58. let tokenName = O2AuthSDK.shared.tokenName()
  59. AF.request(loginURL!, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: [tokenName:(account?.token)!]).responseJSON(completionHandler: { (response) in
  60. switch response.result {
  61. case .success(let val):
  62. DispatchQueue.main.async {
  63. DDLogDebug(String(describing:val))
  64. let alertController = UIAlertController(title: "扫描结果", message: "PC端登录成功", preferredStyle: .alert)
  65. let okAction = UIAlertAction(title: "确定", style: .default) {
  66. action in
  67. self.popVC()
  68. }
  69. alertController.addAction(okAction)
  70. self.presentVC(alertController)
  71. }
  72. case .failure(let err):
  73. DispatchQueue.main.async {
  74. DDLogError(err.localizedDescription)
  75. let alertController = UIAlertController(title: "扫描结果", message: "PC端登录失败", preferredStyle: .alert)
  76. let okAction = UIAlertAction(title: "确定", style: .destructive) {
  77. action in
  78. self.popVC()
  79. }
  80. alertController.addAction(okAction)
  81. self.presentVC(alertController)
  82. }
  83. }
  84. })
  85. } else {//其他扫描结果
  86. let alertController = UIAlertController(title: "扫描结果", message: result.strScanned!, preferredStyle: .alert)
  87. let okAction = UIAlertAction(title: "确定", style: .default) {
  88. action in
  89. self.popVC()
  90. }
  91. alertController.addAction(okAction)
  92. self.presentVC(alertController)
  93. }
  94. }
  95. }
  96. }
  97. //会议签到
  98. func meetingCheck(url: String) {
  99. let account = O2AuthSDK.shared.myInfo()
  100. let tokenName = O2AuthSDK.shared.tokenName()
  101. AF.request(url, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: [tokenName:(account?.token)!]).responseJSON(completionHandler: {(response) in
  102. switch response.result {
  103. case .success(let val):
  104. DispatchQueue.main.async {
  105. DDLogDebug(String(describing:val))
  106. let alertController = UIAlertController(title: "提示", message: "签到成功", preferredStyle: .alert)
  107. let okAction = UIAlertAction(title: "确定", style: .default) {
  108. action in
  109. self.popVC()
  110. }
  111. alertController.addAction(okAction)
  112. self.presentVC(alertController)
  113. }
  114. case .failure(let err):
  115. DispatchQueue.main.async {
  116. DDLogError(err.localizedDescription)
  117. let alertController = UIAlertController(title: "提示", message: "签到失败", preferredStyle: .alert)
  118. let okAction = UIAlertAction(title: "确定", style: .destructive) {
  119. action in
  120. self.popVC()
  121. }
  122. alertController.addAction(okAction)
  123. self.presentVC(alertController)
  124. }
  125. }
  126. })
  127. }
  128. }