NewScanViewController.swift 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. AF.request(loginURL!, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: ["x-token":(account?.token)!]).responseJSON(completionHandler: { (response) in
  59. switch response.result {
  60. case .success(let val):
  61. DispatchQueue.main.async {
  62. DDLogDebug(String(describing:val))
  63. let alertController = UIAlertController(title: "扫描结果", message: "PC端登录成功", preferredStyle: .alert)
  64. let okAction = UIAlertAction(title: "确定", style: .default) {
  65. action in
  66. self.popVC()
  67. }
  68. alertController.addAction(okAction)
  69. self.presentVC(alertController)
  70. }
  71. case .failure(let err):
  72. DispatchQueue.main.async {
  73. DDLogError(err.localizedDescription)
  74. let alertController = UIAlertController(title: "扫描结果", message: "PC端登录失败", preferredStyle: .alert)
  75. let okAction = UIAlertAction(title: "确定", style: .destructive) {
  76. action in
  77. self.popVC()
  78. }
  79. alertController.addAction(okAction)
  80. self.presentVC(alertController)
  81. }
  82. }
  83. })
  84. }else {//其他扫描结果
  85. let alertController = UIAlertController(title: "扫描结果", message: result.strScanned!, preferredStyle: .alert)
  86. let okAction = UIAlertAction(title: "确定", style: .default) {
  87. action in
  88. self.popVC()
  89. }
  90. alertController.addAction(okAction)
  91. self.presentVC(alertController)
  92. }
  93. }
  94. }
  95. }
  96. //会议签到
  97. func meetingCheck(url: String) {
  98. let account = O2AuthSDK.shared.myInfo()
  99. AF.request(url, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: ["x-token":(account?.token)!]).responseJSON(completionHandler: {(response) in
  100. switch response.result {
  101. case .success(let val):
  102. DispatchQueue.main.async {
  103. DDLogDebug(String(describing:val))
  104. let alertController = UIAlertController(title: "提示", message: "签到成功", preferredStyle: .alert)
  105. let okAction = UIAlertAction(title: "确定", style: .default) {
  106. action in
  107. self.popVC()
  108. }
  109. alertController.addAction(okAction)
  110. self.presentVC(alertController)
  111. }
  112. case .failure(let err):
  113. DispatchQueue.main.async {
  114. DDLogError(err.localizedDescription)
  115. let alertController = UIAlertController(title: "提示", message: "签到失败", preferredStyle: .alert)
  116. let okAction = UIAlertAction(title: "确定", style: .destructive) {
  117. action in
  118. self.popVC()
  119. }
  120. alertController.addAction(okAction)
  121. self.presentVC(alertController)
  122. }
  123. }
  124. })
  125. }
  126. }