优惠券swift版马甲包

NetWorkTool.swift 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // NetWorkTool.swift
  3. // MvpGoods
  4. //
  5. // Created by 小花 on 2019/3/18.
  6. // Copyright © 2019年 MVP. All rights reserved.
  7. //
  8. import UIKit
  9. import Alamofire
  10. import SwiftyJSON
  11. import AdSupport
  12. class NetWorkTool: NSObject {
  13. class func postRequest(url: String, param: [String: Any], success:@escaping(_ json: [String
  14. :JSON])->(),fail:@escaping(_ error: NSError)->()) {
  15. let uuidStr: String = ASIdentifierManager.shared().advertisingIdentifier.uuidString
  16. let header = ["source": CHANNEL_ID,
  17. "idfa": uuidStr]
  18. Alamofire
  19. .request(url, method: HTTPMethod.post ,parameters: param, encoding: URLEncoding.default, headers: header)
  20. .responseJSON { (response) in
  21. guard response.result.isSuccess else {
  22. //请求失败
  23. fail(response.error! as NSError)
  24. return
  25. }
  26. //请求成功
  27. if let json = response.result.value {
  28. let dict = JSON(json)
  29. let code = dict["errno"].intValue
  30. //判断状态码
  31. guard code == RETURN_OK else {
  32. let err = NSError()
  33. fail(err)
  34. return
  35. }
  36. if let data = dict.dictionary {
  37. success(data)
  38. }
  39. }
  40. }
  41. }
  42. class func getRequest(url: String, param: [String: Any], success:@escaping(_ json: [String
  43. :JSON])->(),fail:@escaping(_ error: NSError)->()) {
  44. let uuidStr: String = ASIdentifierManager.shared().advertisingIdentifier.uuidString
  45. let header = ["source": CHANNEL_ID,
  46. "idfa": uuidStr]
  47. Alamofire
  48. .request(url, method: HTTPMethod.get ,parameters: param, encoding: URLEncoding.default, headers: header)
  49. .responseJSON { (response) in
  50. guard response.result.isSuccess else {
  51. //请求失败
  52. fail(response.error! as NSError)
  53. return
  54. }
  55. //请求成功
  56. if let json = response.result.value {
  57. let dict = JSON(json)
  58. let code = dict["errno"].intValue
  59. //判断状态码
  60. guard code == RETURN_OK else {
  61. let err = NSError()
  62. fail(err)
  63. return
  64. }
  65. if let data = dict.dictionary {
  66. success(data)
  67. }
  68. }
  69. }
  70. }
  71. }