|
@@ -91,17 +91,23 @@ final class TdwMoyaPlugin: PluginType {
|
91
|
91
|
// 插件,实现pluginType可以实现在网络请求前转菊花,请求完成结束转菊花,或者写日志等功能
|
92
|
92
|
struct NetworkPlugin: PluginType {
|
93
|
93
|
let userDefault=UserDefaults.standard
|
94
|
|
-
|
|
94
|
+
|
95
|
95
|
/// Called to modify a request before sending.(可进行数据加密等)
|
96
|
96
|
func prepare(_ request: URLRequest, target: TargetType) -> URLRequest {
|
97
|
97
|
var mRequest = request
|
98
|
98
|
let key = "XINGHUOLIAOYUAN7"
|
99
|
|
- let jsonString = AESEncryptor.aes_encrypt(request.httpBody!.toHexString(),aes_key: key)
|
100
|
|
-// mRequest.httpBody = jsonString.data(using: String.Encoding.utf8)
|
|
99
|
+// let jsonString = AESEncryptor.aes_encrypt(request.httpBody!.toHexString(),aes_key: key)
|
|
100
|
+ //TODO AES加密相关
|
|
101
|
+ let jsonString = aesEncryptData(request.httpBody,key.data(using: .utf8))
|
|
102
|
+
|
|
103
|
+// let jsonString = AESEncryptor.aes_encrypt(request.httpBody!.toHexString(),aes_key: key)
|
|
104
|
+ //TODO AES加密相关
|
|
105
|
+// let jsonString = aesEncryptString(String(data: request.httpBody!, encoding: String.Encoding.utf8) ?? "",key)
|
|
106
|
+ mRequest.httpBody = jsonString?.toHexString().data(using: .utf8)
|
101
|
107
|
print("""
|
102
|
108
|
#############↓网络请求参数↓#################
|
103
|
109
|
\(target.baseURL)\(target.path)
|
104
|
|
- \(jsonString ?? "无参数")
|
|
110
|
+ \(jsonString?.toHexString() ?? "无参数")
|
105
|
111
|
#############↑网络请求参数↑#################
|
106
|
112
|
""")
|
107
|
113
|
let userinfo = NSKeyedUnarchiver.unarchiveObject(with: userDefault.object(forKey: "userinfo") as! Data ) as! LoginUserInfo
|
|
@@ -123,28 +129,28 @@ struct NetworkPlugin: PluginType {
|
123
|
129
|
|
124
|
130
|
/// Called immediately before a request is sent over the network (or stubbed).(可进行网络等待,loading等)
|
125
|
131
|
func willSend(_ request: RequestType, target: TargetType) {
|
126
|
|
-// guard let target = target as? AccountService else { return }
|
127
|
|
-// let jsonData = try? JSONSerialization.data(withJSONObject: target.parameters, options: .prettyPrinted)
|
128
|
|
-// let jsonString = String(data: jsonData ?? Data(), encoding: .utf8)
|
129
|
|
-// print("""
|
130
|
|
-// #############↓网络请求参数↓#################
|
131
|
|
-// \(target.baseURL)\(target.path)
|
132
|
|
-// \(jsonString ?? "无参数")
|
133
|
|
-// #############↑网络请求参数↑#################
|
134
|
|
-// """)
|
|
132
|
+ // guard let target = target as? AccountService else { return }
|
|
133
|
+ // let jsonData = try? JSONSerialization.data(withJSONObject: target.parameters, options: .prettyPrinted)
|
|
134
|
+ // let jsonString = String(data: jsonData ?? Data(), encoding: .utf8)
|
|
135
|
+ // print("""
|
|
136
|
+ // #############↓网络请求参数↓#################
|
|
137
|
+ // \(target.baseURL)\(target.path)
|
|
138
|
+ // \(jsonString ?? "无参数")
|
|
139
|
+ // #############↑网络请求参数↑#################
|
|
140
|
+ // """)
|
135
|
141
|
|
136
|
142
|
}
|
137
|
|
-
|
|
143
|
+
|
138
|
144
|
/// Called after a response has been received, but before the MoyaProvider has invoked its completion handler.(loading结束等)
|
139
|
145
|
func didReceive(_ result: Result<Response, MoyaError>, target: TargetType) {
|
140
|
|
-
|
|
146
|
+
|
141
|
147
|
}
|
142
|
|
-
|
|
148
|
+
|
143
|
149
|
/// Called to modify a result before completion.(可进行数据解密等)
|
144
|
150
|
func process(_ result: Result<Response, MoyaError>, target: TargetType) -> Result<Response, MoyaError> {
|
145
|
151
|
return result
|
146
|
152
|
}
|
147
|
|
-
|
|
153
|
+
|
148
|
154
|
}
|
149
|
155
|
|
150
|
156
|
|
|
@@ -211,7 +217,7 @@ public class NetworkManaer{
|
211
|
217
|
|
212
|
218
|
// 错误处理 - 弹出错误信息
|
213
|
219
|
func failureHandle(failure: ((Int?, String) ->Void)? , stateCode: Int?, message: String) {
|
214
|
|
-// Alert.show(type: .error, text: message)
|
|
220
|
+ // Alert.show(type: .error, text: message)
|
215
|
221
|
//弹出错误信息
|
216
|
222
|
failure?(stateCode ,message)
|
217
|
223
|
}
|