SMSViewController.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // SMSViewController.swift
  3. // SocketChat
  4. //
  5. // Created by Justine on 16/5/31.
  6. // Copyright © 2016年 AppCoda. All rights reserved.
  7. //
  8. import UIKit
  9. import Alamofire
  10. class SMSViewController: UIViewController {
  11. @IBOutlet weak var mobile: UITextField!
  12. @IBOutlet weak var smscode: UITextField!
  13. let serverid = GET_SERVER_ID as! String
  14. let userid = GET_USER_ID as! Int
  15. let loginname = GET_USER_NAME as! String
  16. var afmobile:String?
  17. @IBAction func requireCode(sender: UIButton) {
  18. var remainingSeconds: Int = 60
  19. sender.enabled = false
  20. sender.setTitle(String(remainingSeconds), forState: UIControlState.Disabled)
  21. //请求验证码
  22. afmobile = trimstring(self.mobile.text!,trimchar: " ")
  23. /*待优化手机号匹配规则
  24. */
  25. let param:[String:AnyObject] = ["serverID":serverid,
  26. "loginName":loginname,
  27. "userID":userid,
  28. "mobile":self.afmobile!
  29. ]
  30. request(.POST, RequireSMSURL, parameters: param).responseJSON { (R) in
  31. guard R.result.error == nil else{
  32. print("弹窗提示验证码请求失败,请求错误")
  33. return
  34. }
  35. print("弹窗提示验证码发送成功")
  36. }
  37. }
  38. @IBAction func checkCode(sender: UIButton){
  39. let param:[String:AnyObject] = ["serverID":serverid,
  40. "loginName":loginname,
  41. "userID":userid,
  42. "mobile":self.mobile.text!,
  43. "code":self.smscode.text!
  44. ]
  45. //发送验证码到服务端比对 正确则RootView 反之AlertController
  46. request(.POST, CheckSMSURL, parameters: param).responseJSON { (R) in
  47. guard R.result.error == nil else{
  48. print("弹窗请求错误原因")
  49. print("请求出错")
  50. return
  51. }
  52. let data = R.result.value!
  53. print("弹窗提示登录成功,然后显示主界面")
  54. print(data["message"])
  55. self.mobile.resignFirstResponder()
  56. self.smscode.resignFirstResponder()
  57. APPDELEGATE.showRootViewContorller()
  58. }
  59. }
  60. func timer(times:Int){
  61. }
  62. override func viewDidLoad() {
  63. super.viewDidLoad()
  64. // Do any additional setup after loading the view.
  65. }
  66. override func didReceiveMemoryWarning() {
  67. super.didReceiveMemoryWarning()
  68. // Dispose of any resources that can be recreated.
  69. }
  70. /*
  71. // MARK: - Navigation
  72. // In a storyboard-based application, you will often want to do a little preparation before navigation
  73. override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
  74. // Get the new view controller using segue.destinationViewController.
  75. // Pass the selected object to the new view controller.
  76. }
  77. */
  78. }