12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- //
- // NetWorkTool.swift
- // MvpGoods
- //
- // Created by 小花 on 2019/3/18.
- // Copyright © 2019年 MVP. All rights reserved.
- //
- import UIKit
- import Alamofire
- import SwiftyJSON
- import AdSupport
- class NetWorkTool: NSObject {
- class func postRequest(url: String, param: [String: Any], success:@escaping(_ json: [String
- :JSON])->(),fail:@escaping(_ error: NSError)->()) {
-
- let uuidStr: String = ASIdentifierManager.shared().advertisingIdentifier.uuidString
- let header = ["source": CHANNEL_ID,
- "idfa": uuidStr]
- Alamofire
- .request(url, method: HTTPMethod.post ,parameters: param, encoding: URLEncoding.default, headers: header)
-
- .responseJSON { (response) in
- guard response.result.isSuccess else {
- //请求失败
- fail(response.error! as NSError)
- return
- }
-
- //请求成功
- if let json = response.result.value {
- let dict = JSON(json)
- let code = dict["errno"].intValue
- //判断状态码
- guard code == RETURN_OK else {
-
- let err = NSError()
- fail(err)
- return
- }
-
- if let data = dict.dictionary {
-
- success(data)
- }
-
- }
- }
- }
-
-
- class func getRequest(url: String, param: [String: Any], success:@escaping(_ json: [String
- :JSON])->(),fail:@escaping(_ error: NSError)->()) {
-
- let uuidStr: String = ASIdentifierManager.shared().advertisingIdentifier.uuidString
- let header = ["source": CHANNEL_ID,
- "idfa": uuidStr]
- Alamofire
- .request(url, method: HTTPMethod.get ,parameters: param, encoding: URLEncoding.default, headers: header)
-
- .responseJSON { (response) in
- guard response.result.isSuccess else {
- //请求失败
- fail(response.error! as NSError)
- return
- }
-
- //请求成功
- if let json = response.result.value {
- let dict = JSON(json)
- let code = dict["errno"].intValue
- //判断状态码
- guard code == RETURN_OK else {
-
- let err = NSError()
- fail(err)
- return
- }
-
- if let data = dict.dictionary {
-
- success(data)
- }
-
- }
- }
- }
- }
|