|
@ -1,5 +1,7 @@
|
1
|
1
|
package com.wade.mobile.func;
|
2
|
2
|
|
|
3
|
import java.io.File;
|
|
4
|
import java.io.InputStream;
|
3
|
5
|
import java.util.HashMap;
|
4
|
6
|
import java.util.HashSet;
|
5
|
7
|
import java.util.Map;
|
|
@ -8,6 +10,7 @@ import org.json.JSONArray;
|
8
|
10
|
|
9
|
11
|
import android.bluetooth.BluetoothAdapter;
|
10
|
12
|
import android.content.Intent;
|
|
13
|
import android.os.AsyncTask;
|
11
|
14
|
import android.os.Build;
|
12
|
15
|
import android.widget.Toast;
|
13
|
16
|
|
|
@ -31,9 +34,13 @@ import com.wade.mobile.safe.MobileSecurity;
|
31
|
34
|
import com.wade.mobile.util.BusinessCache;
|
32
|
35
|
import com.wade.mobile.util.Constant;
|
33
|
36
|
import com.wade.mobile.util.EscapeUnescape;
|
|
37
|
import com.wade.mobile.util.FileUtil;
|
34
|
38
|
import com.wade.mobile.util.FuncConstant;
|
|
39
|
import com.wade.mobile.util.Messages;
|
35
|
40
|
import com.wade.mobile.util.StringUtil;
|
|
41
|
import com.wade.mobile.util.Utility;
|
36
|
42
|
import com.wade.mobile.util.http.HttpTool;
|
|
43
|
import com.wade.mobile.util.http.UnirestUtil;
|
37
|
44
|
|
38
|
45
|
public class MobileNetWork extends Plugin {
|
39
|
46
|
private boolean hasSetSmsListener;
|
|
@ -192,34 +199,40 @@ public class MobileNetWork extends Plugin {
|
192
|
199
|
}
|
193
|
200
|
}
|
194
|
201
|
|
195
|
|
@SuppressWarnings({ "rawtypes", "static-access" })
|
|
202
|
@SuppressWarnings({ "static-access" })
|
196
|
203
|
private String requestBizData(String dataAction, IData param) throws Exception {
|
197
|
|
Map<String,String> postParam = new HashMap<String,String>();
|
198
|
|
postParam.put(Constant.Server.ACTION, dataAction);
|
|
204
|
Map<String,String> postData = transPostData(dataAction, param);
|
|
205
|
String encode = MobileConfig.getInstance().getEncode();
|
|
206
|
String dataUrl = HttpTool.toQueryString(postData);
|
|
207
|
dataUrl = HttpTool.urlEncode(dataUrl, encode);
|
|
208
|
String result = HttpTool.httpRequest(MobileConfig.getInstance().getRequestUrl(),
|
|
209
|
dataUrl, Constant.HTTP_POST);
|
199
|
210
|
if (ServerDataConfig.getInstance().isEncrypt(dataAction)) {
|
200
|
|
String paramData = param == null ? "{}" : param.toString();
|
|
211
|
result = MobileSecurity.responseDecrypt(result);
|
|
212
|
}
|
|
213
|
return result;
|
|
214
|
}
|
|
215
|
|
|
216
|
public Map<String, String> transPostData(String dataAction, IData dataParam) throws Exception {
|
|
217
|
// TODO Auto-generated method stub
|
|
218
|
Map<String, String> postData = new HashMap<String, String>();
|
|
219
|
postData.put(Constant.Server.ACTION, dataAction);
|
|
220
|
if (ServerDataConfig.isEncrypt(dataAction)) {
|
|
221
|
String paramData = dataParam == null ? "{}" : dataParam.toString();
|
201
|
222
|
/* 参数加密处理 */
|
202
|
223
|
String encryptData = MobileSecurity.requestEncrypt(paramData);
|
203
|
224
|
String key = MobileSecurity.getDesKey(context);
|
204
|
225
|
/* 将+号全部转换成-号 */
|
205
|
226
|
encryptData = encryptData.replace("+", "-");
|
206
|
227
|
key = key.replace("+", "-");
|
207
|
|
postParam.put(Constant.Server.DATA, encryptData);
|
208
|
|
postParam.put(Constant.Server.KEY, key);
|
|
228
|
postData.put(Constant.Server.DATA, encryptData);
|
|
229
|
postData.put(Constant.Server.KEY, key);
|
209
|
230
|
} else {
|
210
|
|
if (param != null) {
|
211
|
|
postParam.put(Constant.Server.DATA, param.toString());
|
|
231
|
if (dataParam != null) {
|
|
232
|
postData.put(Constant.Server.DATA, dataParam.toString());
|
212
|
233
|
}
|
213
|
234
|
}
|
214
|
|
|
215
|
|
String encode = MobileConfig.getInstance().getEncode();
|
216
|
|
String qs = HttpTool.toQueryString(postParam);
|
217
|
|
String data = HttpTool.urlEncode(qs, encode);
|
218
|
|
String result = HttpTool.httpRequest(MobileConfig.getInstance().getRequestUrl(), data, Constant.HTTP_POST);
|
219
|
|
if (ServerDataConfig.getInstance().isEncrypt(dataAction)) {
|
220
|
|
result = MobileSecurity.responseDecrypt(result);
|
221
|
|
}
|
222
|
|
return result;
|
|
235
|
return postData;
|
223
|
236
|
}
|
224
|
237
|
|
225
|
238
|
public void storageDataByThread(JSONArray param) throws Exception {
|
|
@ -292,16 +305,87 @@ public class MobileNetWork extends Plugin {
|
292
|
305
|
}
|
293
|
306
|
|
294
|
307
|
public void uploadWithServlet(JSONArray param) throws Exception {
|
295
|
|
|
296
|
308
|
JSONArray filePaths = param.getJSONArray(0);
|
297
|
309
|
String dataAction = param.getString(1);
|
298
|
|
String dataParam = param.getString(2);
|
|
310
|
IData dataParam = isNull(param.getString(2))?new DataMap():new DataMap(param.getString(2));
|
299
|
311
|
uploadWithServlet(filePaths, dataAction, dataParam);
|
300
|
312
|
}
|
301
|
313
|
|
302
|
|
public void uploadWithServlet(JSONArray filePaths, String dataAction, String dataParam) {
|
|
314
|
public void uploadWithServlet(final JSONArray filePaths, String dataAction, IData dataParam) throws Exception {
|
303
|
315
|
// TODO Auto-generated method stub
|
304
|
|
|
|
316
|
final Map<String, String> postData = transPostData(dataAction, dataParam);
|
|
317
|
final Map<String, Object> filePostData = new HashMap<String, Object>();
|
|
318
|
filePostData.putAll(postData);//先装载参数
|
|
319
|
new AsyncTask<String, Integer, String>() {
|
|
320
|
@Override
|
|
321
|
protected String doInBackground(String... arg0) {
|
|
322
|
// TODO Auto-generated method stub
|
|
323
|
String result = null;
|
|
324
|
try{
|
|
325
|
String filePath = null;
|
|
326
|
File file;
|
|
327
|
for(int i=0;i<filePaths.length();i++){
|
|
328
|
filePath = filePaths.getString(i);
|
|
329
|
file = new File(filePath);
|
|
330
|
if(!file.exists()){
|
|
331
|
Utility.error(Messages.FILE_NOT_EXIST+":"+filePath);
|
|
332
|
}
|
|
333
|
filePostData.put("FILE"+i, filePath);//再装载文件
|
|
334
|
}
|
|
335
|
result = UnirestUtil.uploadByPost(MobileConfig.getInstance().getRequestUrl(), filePostData);
|
|
336
|
}catch(Exception e){
|
|
337
|
MobileNetWork.this.error(e.getMessage());// 报错回调
|
|
338
|
}
|
|
339
|
return result;
|
|
340
|
}
|
|
341
|
|
|
342
|
@Override
|
|
343
|
protected void onPostExecute(String result) {
|
|
344
|
// TODO Auto-generated method stub
|
|
345
|
super.onPostExecute(result);
|
|
346
|
if (result != null) {
|
|
347
|
MobileNetWork.this.callback(result);// 正常回调
|
|
348
|
}
|
|
349
|
}
|
|
350
|
}.execute();
|
|
351
|
}
|
|
352
|
|
|
353
|
public void downloadWithServlet(JSONArray param) throws Exception {
|
|
354
|
String savePath = param.getString(0);
|
|
355
|
String dataAction = param.getString(1);
|
|
356
|
IData dataParam = param.getString(2)==null?new DataMap():new DataMap(param.getString(2));
|
|
357
|
downloadWithServlet(savePath, dataAction, dataParam);
|
|
358
|
}
|
|
359
|
|
|
360
|
public void downloadWithServlet(final String savePath, String dataAction, IData dataParam) throws Exception {
|
|
361
|
// TODO Auto-generated method stub
|
|
362
|
Map<String, String> tempPostData = transPostData(dataAction, dataParam);
|
|
363
|
final Map<String, Object> postData = new HashMap<String, Object>();
|
|
364
|
postData.putAll(tempPostData);
|
|
365
|
new AsyncTask<String, Integer, String>() {
|
|
366
|
@Override
|
|
367
|
protected String doInBackground(String... arg0) {
|
|
368
|
// TODO Auto-generated method stub
|
|
369
|
String result = null;
|
|
370
|
try{
|
|
371
|
InputStream in = UnirestUtil.downloadByPost(MobileConfig.getInstance().getRequestUrl(), postData);
|
|
372
|
FileUtil.writeFile(in, savePath);
|
|
373
|
result = "下载成功";
|
|
374
|
}catch(Exception e){
|
|
375
|
MobileNetWork.this.error(savePath + "异常:"+e.getMessage());// 报错回调
|
|
376
|
}
|
|
377
|
return result;
|
|
378
|
}
|
|
379
|
|
|
380
|
@Override
|
|
381
|
protected void onPostExecute(String result) {
|
|
382
|
// TODO Auto-generated method stub
|
|
383
|
super.onPostExecute(result);
|
|
384
|
if (result != null) {
|
|
385
|
MobileNetWork.this.callback(result);// 正常回调
|
|
386
|
}
|
|
387
|
}
|
|
388
|
}.execute();
|
305
|
389
|
}
|
306
|
390
|
|
307
|
391
|
public void uploadFile(JSONArray param) throws Exception {
|