Commit 07670a4464aa81829d27e0af6fb95f051366d81c
1 parent
e616c08e
畅游通核销app: 1.增加日志上传服务器功能
Showing
27 changed files
with
1939 additions
and
2 deletions
AndroidManifest.xml
@@ -193,6 +193,11 @@ | @@ -193,6 +193,11 @@ | ||
193 | </intent-filter> | 193 | </intent-filter> |
194 | </receiver> | 194 | </receiver> |
195 | 195 | ||
196 | + <receiver | ||
197 | + android:name="com.ectrip.cyt.receiver.AlarmReceiver" | ||
198 | + android:enabled="true" | ||
199 | + android:exported="true" /> | ||
200 | + | ||
196 | <activity | 201 | <activity |
197 | android:name="android_serialport_api.print_tool.ConsoleActivity" | 202 | android:name="android_serialport_api.print_tool.ConsoleActivity" |
198 | android:screenOrientation="portrait" | 203 | android:screenOrientation="portrait" |
@@ -376,6 +381,8 @@ | @@ -376,6 +381,8 @@ | ||
376 | <category android:name="android.intent.category.DEFAULT" /> | 381 | <category android:name="android.intent.category.DEFAULT" /> |
377 | </intent-filter> | 382 | </intent-filter> |
378 | </service> | 383 | </service> |
384 | + <service android:name="com.ectrip.cyt.service.FtpParamerService" /> | ||
385 | + <service android:name="com.ectrip.cyt.service.UploadLogService" /> | ||
379 | <!-- | 386 | <!-- |
380 | <receiver android:name="com.eztlib.blu.BluetoothConnectActivityReceiver" > | 387 | <receiver android:name="com.eztlib.blu.BluetoothConnectActivityReceiver" > |
381 | <intent-filter> | 388 | <intent-filter> |
CYTAndroid4.0.iml
@@ -111,6 +111,13 @@ | @@ -111,6 +111,13 @@ | ||
111 | <orderEntry type="library" name="Gradle: D./desk file/work/CYTAndroid4.0/libs/zkandroididcardreader.jar" level="project" /> | 111 | <orderEntry type="library" name="Gradle: D./desk file/work/CYTAndroid4.0/libs/zkandroididcardreader.jar" level="project" /> |
112 | <orderEntry type="library" name="Gradle: D./desk file/work/CYTAndroid4.0/libs/iodev2.jar" level="project" /> | 112 | <orderEntry type="library" name="Gradle: D./desk file/work/CYTAndroid4.0/libs/iodev2.jar" level="project" /> |
113 | <orderEntry type="library" name="Gradle: D./desk file/work/CYTAndroid4.0/libs/decoderapijni.jar" level="project" /> | 113 | <orderEntry type="library" name="Gradle: D./desk file/work/CYTAndroid4.0/libs/decoderapijni.jar" level="project" /> |
114 | + <orderEntry type="library" name="Gradle: D./desk file/work/CYTAndroid4.0/libs/android-logging-log4j-1.0.3.jar" level="project" /> | ||
115 | + <orderEntry type="library" name="Gradle: D./desk file/work/CYTAndroid4.0/libs/log4j-1.2.17.jar" level="project" /> | ||
116 | + <orderEntry type="library" name="Gradle: D./desk file/work/CYTAndroid4.0/libs/zypos1.8.jar" level="project" /> | ||
117 | + <orderEntry type="library" name="Gradle: D./desk file/work/CYTAndroid4.0/libs/jsch-0.1.54.jar" level="project" /> | ||
114 | <orderEntry type="library" name="Gradle: D./desk file/work/CYTAndroid4.0/libs/bw_pos_sdk2.0.18.jar" level="project" /> | 118 | <orderEntry type="library" name="Gradle: D./desk file/work/CYTAndroid4.0/libs/bw_pos_sdk2.0.18.jar" level="project" /> |
119 | + <orderEntry type="library" name="Gradle: org.jetbrains:annotations-java5:15.0" level="project" /> | ||
120 | + <orderEntry type="library" name="Gradle: com.squareup.okhttp3:okhttp:3.6.0" level="project" /> | ||
121 | + <orderEntry type="library" name="Gradle: com.squareup.okio:okio:1.11.0" level="project" /> | ||
115 | </component> | 122 | </component> |
116 | </module> | 123 | </module> |
117 | \ No newline at end of file | 124 | \ No newline at end of file |
build.gradle
@@ -38,9 +38,12 @@ dependencies { | @@ -38,9 +38,12 @@ dependencies { | ||
38 | implementation files('libs\\android-logging-log4j-1.0.3.jar') | 38 | implementation files('libs\\android-logging-log4j-1.0.3.jar') |
39 | implementation files('libs\\log4j-1.2.17.jar') | 39 | implementation files('libs\\log4j-1.2.17.jar') |
40 | implementation files('libs\\zypos1.8.jar') | 40 | implementation files('libs\\zypos1.8.jar') |
41 | + implementation files('libs\\jsch-0.1.54.jar') | ||
42 | + implementation 'org.jetbrains:annotations-java5:15.0' | ||
41 | compileOnly files('external_libs/classes_2.1.11_20160907.jar') | 43 | compileOnly files('external_libs/classes_2.1.11_20160907.jar') |
42 | compileOnly files('external_libs/bw_odm_20160526.jar') | 44 | compileOnly files('external_libs/bw_odm_20160526.jar') |
43 | implementation files('libs/bw_pos_sdk2.0.18.jar') | 45 | implementation files('libs/bw_pos_sdk2.0.18.jar') |
46 | + implementation 'com.squareup.okhttp3:okhttp:3.6.0' | ||
44 | // implementation('com.android.support:support-v4:21.0.0') | 47 | // implementation('com.android.support:support-v4:21.0.0') |
45 | // implementation('com.android.support:appcompat-v7:21.0.0'){ // You should exclude one of them not both of them | 48 | // implementation('com.android.support:appcompat-v7:21.0.0'){ // You should exclude one of them not both of them |
46 | // exclude module: "support-v4" | 49 | // exclude module: "support-v4" |
libs/jsch-0.1.54.jar
0 → 100644
No preview for this file type
src/com/ectrip/cyt/bean/BaseRequest.java
0 → 100644
src/com/ectrip/cyt/bean/BaseResponse.java
0 → 100644
1 | +package com.ectrip.cyt.bean; | ||
2 | + | ||
3 | +/** | ||
4 | + * This is a base response data type of Action | ||
5 | + * Created by lingkitho on 2017/3/1. | ||
6 | + */ | ||
7 | +public class BaseResponse { | ||
8 | + | ||
9 | + /** | ||
10 | + * response code | ||
11 | + * 当核心的服务返回的数据为void或发成异常时,此字段才会赋值 | ||
12 | + */ | ||
13 | + private String code; | ||
14 | + | ||
15 | + /** | ||
16 | + * response message information | ||
17 | + * 当核心的服务返回的数据为void或发成异常时,此字段才会赋值 | ||
18 | + */ | ||
19 | + private String msg; | ||
20 | + | ||
21 | + /** | ||
22 | + * 核心的服务返回的数据 | ||
23 | + */ | ||
24 | + private Object data; | ||
25 | + | ||
26 | + public BaseResponse() { | ||
27 | + } | ||
28 | + | ||
29 | + public BaseResponse(Object data) { | ||
30 | + this.data = data; | ||
31 | + } | ||
32 | + | ||
33 | + public String getCode() { | ||
34 | + return code; | ||
35 | + } | ||
36 | + | ||
37 | + public void setCode(String code) { | ||
38 | + this.code = code; | ||
39 | + } | ||
40 | + | ||
41 | + public String getMsg() { | ||
42 | + return msg; | ||
43 | + } | ||
44 | + | ||
45 | + public void setMsg(String msg) { | ||
46 | + this.msg = msg; | ||
47 | + } | ||
48 | + | ||
49 | + public Object getData() { | ||
50 | + return data; | ||
51 | + } | ||
52 | + | ||
53 | + public void setData(Object data) { | ||
54 | + this.data = data; | ||
55 | + } | ||
56 | +} |
src/com/ectrip/cyt/bean/DataTranfer.java
0 → 100644
1 | +package com.ectrip.cyt.bean; | ||
2 | + | ||
3 | +/** | ||
4 | + * Created by lingkitho on 2017/3/2. | ||
5 | + */ | ||
6 | +public class DataTranfer { | ||
7 | + private String data; | ||
8 | + private String signed; | ||
9 | + private String securityType = "MD5"; | ||
10 | + private String method; | ||
11 | + | ||
12 | + | ||
13 | + public String getMethod() { | ||
14 | + return method; | ||
15 | + } | ||
16 | + | ||
17 | + public void setMethod(String method) { | ||
18 | + this.method = method; | ||
19 | + } | ||
20 | + | ||
21 | + public String getData() { | ||
22 | + return data; | ||
23 | + } | ||
24 | + | ||
25 | + public void setData(String data) { | ||
26 | + this.data = data; | ||
27 | + } | ||
28 | + | ||
29 | + public String getSigned() { | ||
30 | + return signed; | ||
31 | + } | ||
32 | + | ||
33 | + public void setSigned(String signed) { | ||
34 | + this.signed = signed; | ||
35 | + } | ||
36 | + | ||
37 | + public String getSecurityType() { | ||
38 | + return securityType; | ||
39 | + } | ||
40 | + | ||
41 | + public void setSecurityType(String securityType) { | ||
42 | + this.securityType = securityType; | ||
43 | + } | ||
44 | +} |
src/com/ectrip/cyt/bean/GetFtp.java
0 → 100644
1 | +package com.ectrip.cyt.bean; | ||
2 | + | ||
3 | +/** | ||
4 | + * 从后台获取FTP参数 | ||
5 | + * 006 | ||
6 | + * Created by lingkitho on 2017/3/2. | ||
7 | + */ | ||
8 | +public class GetFtp extends BaseRequest { | ||
9 | + private String accid; //园门ID | ||
10 | + | ||
11 | + private String mac; | ||
12 | + | ||
13 | + public String getMac() { | ||
14 | + return mac; | ||
15 | + } | ||
16 | + | ||
17 | + public void setMac(String mac) { | ||
18 | + this.mac = mac; | ||
19 | + } | ||
20 | + | ||
21 | + public String getAccid() { | ||
22 | + return accid; | ||
23 | + } | ||
24 | + | ||
25 | + public void setAccid(String accid) { | ||
26 | + this.accid = accid; | ||
27 | + } | ||
28 | +} |
src/com/ectrip/cyt/bean/ResultBean.java
0 → 100644
1 | +/** | ||
2 | + * ResultBean.java | ||
3 | + * | ||
4 | + * This file was auto-generated from WSDL | ||
5 | + * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. | ||
6 | + */ | ||
7 | + | ||
8 | +package com.ectrip.cyt.bean; | ||
9 | + | ||
10 | +import com.alibaba.fastjson.JSON; | ||
11 | + | ||
12 | +public class ResultBean implements java.io.Serializable { | ||
13 | + | ||
14 | + private int columnCount; | ||
15 | + | ||
16 | + private String[] columnName; | ||
17 | + | ||
18 | + private String[] columnNames; | ||
19 | + | ||
20 | + private int currentPage; | ||
21 | + | ||
22 | + private int eachPageNumber; | ||
23 | + | ||
24 | + private int endNum; | ||
25 | + | ||
26 | + private String[][] row; | ||
27 | + | ||
28 | + private int rowsCount; | ||
29 | + | ||
30 | + private java.util.Vector selectResult; | ||
31 | + | ||
32 | + private int startNum; | ||
33 | + | ||
34 | + private int totalNumber; | ||
35 | + | ||
36 | + private int totalPages; | ||
37 | + | ||
38 | + public ResultBean() { | ||
39 | + } | ||
40 | + | ||
41 | + public ResultBean( | ||
42 | + int columnCount, | ||
43 | + String[] columnName, | ||
44 | + String[] columnNames, | ||
45 | + int currentPage, | ||
46 | + int eachPageNumber, | ||
47 | + int endNum, | ||
48 | + String[][] row, | ||
49 | + int rowsCount, | ||
50 | + java.util.Vector selectResult, | ||
51 | + int startNum, | ||
52 | + int totalNumber, | ||
53 | + int totalPages) { | ||
54 | + this.columnCount = columnCount; | ||
55 | + this.columnName = columnName; | ||
56 | + this.columnNames = columnNames; | ||
57 | + this.currentPage = currentPage; | ||
58 | + this.eachPageNumber = eachPageNumber; | ||
59 | + this.endNum = endNum; | ||
60 | + this.row = row; | ||
61 | + this.rowsCount = rowsCount; | ||
62 | + this.selectResult = selectResult; | ||
63 | + this.startNum = startNum; | ||
64 | + this.totalNumber = totalNumber; | ||
65 | + this.totalPages = totalPages; | ||
66 | + } | ||
67 | + | ||
68 | + | ||
69 | + /** | ||
70 | + * Gets the columnCount value for this ResultBean. | ||
71 | + * | ||
72 | + * @return columnCount | ||
73 | + */ | ||
74 | + public int getColumnCount() { | ||
75 | + return columnCount; | ||
76 | + } | ||
77 | + | ||
78 | + | ||
79 | + /** | ||
80 | + * Sets the columnCount value for this ResultBean. | ||
81 | + * | ||
82 | + * @param columnCount | ||
83 | + */ | ||
84 | + public void setColumnCount(int columnCount) { | ||
85 | + this.columnCount = columnCount; | ||
86 | + } | ||
87 | + | ||
88 | + | ||
89 | + /** | ||
90 | + * Gets the columnName value for this ResultBean. | ||
91 | + * | ||
92 | + * @return columnName | ||
93 | + */ | ||
94 | + public String[] getColumnName() { | ||
95 | + return columnName; | ||
96 | + } | ||
97 | + | ||
98 | + | ||
99 | + /** | ||
100 | + * Sets the columnName value for this ResultBean. | ||
101 | + * | ||
102 | + * @param columnName | ||
103 | + */ | ||
104 | + public void setColumnName(String[] columnName) { | ||
105 | + this.columnName = columnName; | ||
106 | + } | ||
107 | + | ||
108 | + public String getColumnName(int i) { | ||
109 | + return this.columnName[i]; | ||
110 | + } | ||
111 | + | ||
112 | + public void setColumnName(int i, String _value) { | ||
113 | + this.columnName[i] = _value; | ||
114 | + } | ||
115 | + | ||
116 | + | ||
117 | + /** | ||
118 | + * Gets the columnNames value for this ResultBean. | ||
119 | + * | ||
120 | + * @return columnNames | ||
121 | + */ | ||
122 | + public String[] getColumnNames() { | ||
123 | + return columnNames; | ||
124 | + } | ||
125 | + | ||
126 | + | ||
127 | + /** | ||
128 | + * Sets the columnNames value for this ResultBean. | ||
129 | + * | ||
130 | + * @param columnNames | ||
131 | + */ | ||
132 | + public void setColumnNames(String[] columnNames) { | ||
133 | + this.columnNames = columnNames; | ||
134 | + } | ||
135 | + | ||
136 | + | ||
137 | + /** | ||
138 | + * Gets the currentPage value for this ResultBean. | ||
139 | + * | ||
140 | + * @return currentPage | ||
141 | + */ | ||
142 | + public int getCurrentPage() { | ||
143 | + return currentPage; | ||
144 | + } | ||
145 | + | ||
146 | + | ||
147 | + /** | ||
148 | + * Sets the currentPage value for this ResultBean. | ||
149 | + * | ||
150 | + * @param currentPage | ||
151 | + */ | ||
152 | + public void setCurrentPage(int currentPage) { | ||
153 | + this.currentPage = currentPage; | ||
154 | + } | ||
155 | + | ||
156 | + | ||
157 | + /** | ||
158 | + * Gets the eachPageNumber value for this ResultBean. | ||
159 | + * | ||
160 | + * @return eachPageNumber | ||
161 | + */ | ||
162 | + public int getEachPageNumber() { | ||
163 | + return eachPageNumber; | ||
164 | + } | ||
165 | + | ||
166 | + | ||
167 | + /** | ||
168 | + * Sets the eachPageNumber value for this ResultBean. | ||
169 | + * | ||
170 | + * @param eachPageNumber | ||
171 | + */ | ||
172 | + public void setEachPageNumber(int eachPageNumber) { | ||
173 | + this.eachPageNumber = eachPageNumber; | ||
174 | + } | ||
175 | + | ||
176 | + | ||
177 | + /** | ||
178 | + * Gets the endNum value for this ResultBean. | ||
179 | + * | ||
180 | + * @return endNum | ||
181 | + */ | ||
182 | + public int getEndNum() { | ||
183 | + return endNum; | ||
184 | + } | ||
185 | + | ||
186 | + | ||
187 | + /** | ||
188 | + * Sets the endNum value for this ResultBean. | ||
189 | + * | ||
190 | + * @param endNum | ||
191 | + */ | ||
192 | + public void setEndNum(int endNum) { | ||
193 | + this.endNum = endNum; | ||
194 | + } | ||
195 | + | ||
196 | + | ||
197 | + /** | ||
198 | + * Gets the row value for this ResultBean. | ||
199 | + * | ||
200 | + * @return row | ||
201 | + */ | ||
202 | + public String[][] getRow() { | ||
203 | + return row; | ||
204 | + } | ||
205 | + | ||
206 | + | ||
207 | + /** | ||
208 | + * Sets the row value for this ResultBean. | ||
209 | + * | ||
210 | + * @param row | ||
211 | + */ | ||
212 | + public void setRow(String[][] row) { | ||
213 | + this.row = row; | ||
214 | + } | ||
215 | + | ||
216 | + public String[] getRow(int i) { | ||
217 | + return this.row[i]; | ||
218 | + } | ||
219 | + | ||
220 | + public void setRow(int i, String[] _value) { | ||
221 | + this.row[i] = _value; | ||
222 | + } | ||
223 | + | ||
224 | + | ||
225 | + /** | ||
226 | + * Gets the rowsCount value for this ResultBean. | ||
227 | + * | ||
228 | + * @return rowsCount | ||
229 | + */ | ||
230 | + public int getRowsCount() { | ||
231 | + return rowsCount; | ||
232 | + } | ||
233 | + | ||
234 | + | ||
235 | + /** | ||
236 | + * Sets the rowsCount value for this ResultBean. | ||
237 | + * | ||
238 | + * @param rowsCount | ||
239 | + */ | ||
240 | + public void setRowsCount(int rowsCount) { | ||
241 | + this.rowsCount = rowsCount; | ||
242 | + } | ||
243 | + | ||
244 | + | ||
245 | + /** | ||
246 | + * Gets the selectResult value for this ResultBean. | ||
247 | + * | ||
248 | + * @return selectResult | ||
249 | + */ | ||
250 | + public java.util.Vector getSelectResult() { | ||
251 | + return selectResult; | ||
252 | + } | ||
253 | + | ||
254 | + | ||
255 | + /** | ||
256 | + * Sets the selectResult value for this ResultBean. | ||
257 | + * | ||
258 | + * @param selectResult | ||
259 | + */ | ||
260 | + public void setSelectResult(java.util.Vector selectResult) { | ||
261 | + this.selectResult = selectResult; | ||
262 | + } | ||
263 | + | ||
264 | + | ||
265 | + /** | ||
266 | + * Gets the startNum value for this ResultBean. | ||
267 | + * | ||
268 | + * @return startNum | ||
269 | + */ | ||
270 | + public int getStartNum() { | ||
271 | + return startNum; | ||
272 | + } | ||
273 | + | ||
274 | + | ||
275 | + /** | ||
276 | + * Sets the startNum value for this ResultBean. | ||
277 | + * | ||
278 | + * @param startNum | ||
279 | + */ | ||
280 | + public void setStartNum(int startNum) { | ||
281 | + this.startNum = startNum; | ||
282 | + } | ||
283 | + | ||
284 | + | ||
285 | + /** | ||
286 | + * Gets the totalNumber value for this ResultBean. | ||
287 | + * | ||
288 | + * @return totalNumber | ||
289 | + */ | ||
290 | + public int getTotalNumber() { | ||
291 | + return totalNumber; | ||
292 | + } | ||
293 | + | ||
294 | + | ||
295 | + /** | ||
296 | + * Sets the totalNumber value for this ResultBean. | ||
297 | + * | ||
298 | + * @param totalNumber | ||
299 | + */ | ||
300 | + public void setTotalNumber(int totalNumber) { | ||
301 | + this.totalNumber = totalNumber; | ||
302 | + } | ||
303 | + | ||
304 | + | ||
305 | + /** | ||
306 | + * Gets the totalPages value for this ResultBean. | ||
307 | + * | ||
308 | + * @return totalPages | ||
309 | + */ | ||
310 | + public int getTotalPages() { | ||
311 | + return totalPages; | ||
312 | + } | ||
313 | + | ||
314 | + | ||
315 | + /** | ||
316 | + * Sets the totalPages value for this ResultBean. | ||
317 | + * | ||
318 | + * @param totalPages | ||
319 | + */ | ||
320 | + public void setTotalPages(int totalPages) { | ||
321 | + this.totalPages = totalPages; | ||
322 | + } | ||
323 | + | ||
324 | + private Object __equalsCalc = null; | ||
325 | + | ||
326 | + public synchronized boolean equals(Object obj) { | ||
327 | + if (!(obj instanceof ResultBean)) return false; | ||
328 | + ResultBean other = (ResultBean) obj; | ||
329 | + if (obj == null) return false; | ||
330 | + if (this == obj) return true; | ||
331 | + if (__equalsCalc != null) { | ||
332 | + return (__equalsCalc == obj); | ||
333 | + } | ||
334 | + __equalsCalc = obj; | ||
335 | + boolean _equals; | ||
336 | + _equals = true && | ||
337 | + this.columnCount == other.getColumnCount() && | ||
338 | + ((this.columnName == null && other.getColumnName() == null) || | ||
339 | + (this.columnName != null && | ||
340 | + java.util.Arrays.equals(this.columnName, other.getColumnName()))) && | ||
341 | + ((this.columnNames == null && other.getColumnNames() == null) || | ||
342 | + (this.columnNames != null && | ||
343 | + java.util.Arrays.equals(this.columnNames, other.getColumnNames()))) && | ||
344 | + this.currentPage == other.getCurrentPage() && | ||
345 | + this.eachPageNumber == other.getEachPageNumber() && | ||
346 | + this.endNum == other.getEndNum() && | ||
347 | + ((this.row == null && other.getRow() == null) || | ||
348 | + (this.row != null && | ||
349 | + java.util.Arrays.equals(this.row, other.getRow()))) && | ||
350 | + this.rowsCount == other.getRowsCount() && | ||
351 | + ((this.selectResult == null && other.getSelectResult() == null) || | ||
352 | + (this.selectResult != null && | ||
353 | + this.selectResult.equals(other.getSelectResult()))) && | ||
354 | + this.startNum == other.getStartNum() && | ||
355 | + this.totalNumber == other.getTotalNumber() && | ||
356 | + this.totalPages == other.getTotalPages(); | ||
357 | + __equalsCalc = null; | ||
358 | + return _equals; | ||
359 | + } | ||
360 | + | ||
361 | + private boolean __hashCodeCalc = false; | ||
362 | + | ||
363 | + public synchronized int hashCode() { | ||
364 | + if (__hashCodeCalc) { | ||
365 | + return 0; | ||
366 | + } | ||
367 | + __hashCodeCalc = true; | ||
368 | + int _hashCode = 1; | ||
369 | + _hashCode += getColumnCount(); | ||
370 | + if (getColumnName() != null) { | ||
371 | + for (int i = 0; | ||
372 | + i < java.lang.reflect.Array.getLength(getColumnName()); | ||
373 | + i++) { | ||
374 | + Object obj = java.lang.reflect.Array.get(getColumnName(), i); | ||
375 | + if (obj != null && | ||
376 | + !obj.getClass().isArray()) { | ||
377 | + _hashCode += obj.hashCode(); | ||
378 | + } | ||
379 | + } | ||
380 | + } | ||
381 | + if (getColumnNames() != null) { | ||
382 | + for (int i = 0; | ||
383 | + i < java.lang.reflect.Array.getLength(getColumnNames()); | ||
384 | + i++) { | ||
385 | + Object obj = java.lang.reflect.Array.get(getColumnNames(), i); | ||
386 | + if (obj != null && | ||
387 | + !obj.getClass().isArray()) { | ||
388 | + _hashCode += obj.hashCode(); | ||
389 | + } | ||
390 | + } | ||
391 | + } | ||
392 | + _hashCode += getCurrentPage(); | ||
393 | + _hashCode += getEachPageNumber(); | ||
394 | + _hashCode += getEndNum(); | ||
395 | + if (getRow() != null) { | ||
396 | + for (int i = 0; | ||
397 | + i < java.lang.reflect.Array.getLength(getRow()); | ||
398 | + i++) { | ||
399 | + Object obj = java.lang.reflect.Array.get(getRow(), i); | ||
400 | + if (obj != null && | ||
401 | + !obj.getClass().isArray()) { | ||
402 | + _hashCode += obj.hashCode(); | ||
403 | + } | ||
404 | + } | ||
405 | + } | ||
406 | + _hashCode += getRowsCount(); | ||
407 | + if (getSelectResult() != null) { | ||
408 | + _hashCode += getSelectResult().hashCode(); | ||
409 | + } | ||
410 | + _hashCode += getStartNum(); | ||
411 | + _hashCode += getTotalNumber(); | ||
412 | + _hashCode += getTotalPages(); | ||
413 | + __hashCodeCalc = false; | ||
414 | + return _hashCode; | ||
415 | + } | ||
416 | + | ||
417 | + /** | ||
418 | + * 取到具体显示的字段值 Creation date: (2000-8-12 11:45:24) | ||
419 | + * | ||
420 | + * @param rownum int 行数 | ||
421 | + * @param colnum int 列数 | ||
422 | + * @return java.lang.String | ||
423 | + * @throws Exception The exception description. | ||
424 | + */ | ||
425 | + public String getResult(int rownum, int colnum) { | ||
426 | + | ||
427 | + if (selectResult.isEmpty()) { | ||
428 | + return ""; | ||
429 | + | ||
430 | + } else { | ||
431 | +// String[] tempRow = new Gson().fromJson((String) selectResult.elementAt(rownum),String[].class); | ||
432 | + String[] tempRow = JSON.parseObject(selectResult.elementAt(rownum).toString(),String[].class); | ||
433 | + return tempRow[colnum]; | ||
434 | + | ||
435 | + } | ||
436 | + | ||
437 | + } | ||
438 | + | ||
439 | + /** | ||
440 | + * 重载getResult()方法 通过行数、字段名取到值 | ||
441 | + */ | ||
442 | + public String getResult(int rownum, String columName) { | ||
443 | + int colnum = -1; | ||
444 | + String result = ""; | ||
445 | + for (int j = 0; j < columnCount; j++) { | ||
446 | + | ||
447 | + if (columnNames[j].equalsIgnoreCase(columName)) { | ||
448 | + colnum = j; | ||
449 | + break; | ||
450 | + } | ||
451 | + } | ||
452 | + | ||
453 | + if (colnum != -1) { | ||
454 | + // 有此字段 | ||
455 | + result = getResult(rownum, colnum); | ||
456 | + | ||
457 | + } | ||
458 | + | ||
459 | + return result; | ||
460 | + | ||
461 | + } | ||
462 | + | ||
463 | +} |
src/com/ectrip/cyt/constant/CallBackTypeConstant.java
0 → 100644
1 | +package com.ectrip.cyt.constant; | ||
2 | + | ||
3 | +/** | ||
4 | + * Created by dc on 2017/3/10. | ||
5 | + */ | ||
6 | + | ||
7 | +public class CallBackTypeConstant { | ||
8 | + | ||
9 | + | ||
10 | + | ||
11 | + | ||
12 | + public static final int DEVERROR = 9999; //标志为硬件错误 | ||
13 | + public static final int CLOSE = 9998; //标志关闭界面 | ||
14 | + public static final int PASSAGE = 10005; //标志闸机返回 | ||
15 | + public static final int PASSAGE_TEST = 20005; //标志闸机返回 | ||
16 | + public static final int CHECKTICKET = 24; //标志网络请求回调为检票 | ||
17 | + public static final int TICKETPASSIDINTPUT = 31; //标志网络请求回调为验证指纹 | ||
18 | + public static final int TICKETZWINTPUT = 30; //标志网络请求回调为登记指纹 | ||
19 | + public static final int CHECKFACE = 32; | ||
20 | + | ||
21 | + public static final int GETFEPPRARMETER = 27; //标识为FTP参数返回 | ||
22 | + | ||
23 | +} |
src/com/ectrip/cyt/constant/CheckTicketConstant.java
0 → 100644
1 | +package com.ectrip.cyt.constant; | ||
2 | + | ||
3 | +/** | ||
4 | + * Created by lingkitho on 2017/3/2. | ||
5 | + */ | ||
6 | +public class CheckTicketConstant { | ||
7 | + | ||
8 | + public static String IP; | ||
9 | + public static final String httphead = "http://"; | ||
10 | + public static final String action = "/checkTicket/excuteCheckTicket.action"; | ||
11 | + public static final String MD5KEY = "029124EDC5E180631627E3AE44108724"; | ||
12 | + public static final String CHECKTICKET = "C001"; //检票 | ||
13 | + public static final String GETMYID = "C002"; //根据MAC值,获取闸机ID | ||
14 | + public static final String GETSCENIC = "C003"; //获取景区服务商信息 | ||
15 | + public static final String GETSTATION = "C004"; //获取销售点信息 | ||
16 | + public static final String GETTICKET = "C005"; //获取票类型信息 | ||
17 | + public static final String GETFTP = "C006"; //从后台获取FTP参数 | ||
18 | + public static final String GETXPCS = "C007"; //从后台获取竹筏小票参数 | ||
19 | + public static final String GETZWCS = "C008"; //从后台获取指纹登记、验证参数 | ||
20 | + public static final String GETDAYTIMES = "C009"; //同步系统时间 | ||
21 | + public static final String GETRESULTBEAN = "C010"; //测试检票地址连接检票服务器是否正常 | ||
22 | + public static final String TICKETZWINTPUT = "C011"; //游客登记指纹时,登记成功后返回检票数据 | ||
23 | + public static final String TICKETPASSIDINTPUT = "C012"; //游客验证指纹时,验证成功后返回检票数据 | ||
24 | + public static final String CHECKEMPLOYEE = "C014"; //工作人员根据卡号,判断员工卡操作类型:是落杆或是入园 | ||
25 | + public static final String CHECKFANGXIN = "C015"; //工作人员根据卡号,判断是否是放行卡 | ||
26 | + public static final String EMPLOYEEINPUT = "C016"; //工作人员刷放行卡后,把信息返回 | ||
27 | + public static final String EMPLOYEEZWINPUT = "C017"; //工作人员登记指纹成功后,把信息返回 | ||
28 | + public static final String EMPLOYEEPASS = "C018"; //工作人员验证指纹后,把信息返回 | ||
29 | + public static final String CHANGEEMPLOYEECHANGERAFT = "C019"; //竹筏改签 | ||
30 | + public static final String CHECKIDENTITYCARD = "C020"; //导游验证身份证号 | ||
31 | + public static final String IDENTITYCARDZWINPUT = "C021"; //导游登记指纹后,返回信息 | ||
32 | + public static final String IDENTITYCARDPASS = "C022"; //导游验证指纹后,返回信息 | ||
33 | + public static final String STOPCHECKTICKETONETABLE = "C023"; //一票多人可暂停,第二次刷票暂停后,返回票信息(单表检票) | ||
34 | + public static final String STOPCHECKTICKET = "C024"; //一票多人可暂停,第二次刷票暂停后,返回票信息 | ||
35 | + public static final String LOCLOFFLINECHECKTICKET = "C025"; //IC卡离线检票,检票完成后,把检票纪录上传到服务器 | ||
36 | + public static final String ICCHECKWRITELOG = "C026"; //在对IC卡完成写的操作后,纪录日志 | ||
37 | + public static final String GETZHIWEN = "C027"; //根据IC卡号,获取指纹信息 | ||
38 | + public static final String GETWEBCONTANT = "C028"; //获取后台参数 | ||
39 | + public static final String AUTOMETHOD = "C029"; //新增调用方法(畅游通票号检票、获取园门剩余人数、统计入园人数,把人数返回) | ||
40 | + public static final String GETCHECKCOUNT = "C030"; //获取园门入园人数 | ||
41 | + public static final String GETESBACCESSEQUIPTAB = "C031"; //获取闸机中的指纹滑值参数 | ||
42 | + // public static final String QUERYTICKETPRICES ="C032"; //闸机上刷卡买票入园,获取闸机绑定的价格 | ||
43 | +// public static final String SAVECHECKTICKET ="C033"; //闸机上在支付设备上完成支付后,根据闸机ID、价格ID检票 | ||
44 | + public static final String UPDATESTATUS = "C034"; //把闸机上的所有硬件,是否正常的状态传到服务器 | ||
45 | + public static final String CHECKFACE = "C047"; //人脸识别 | ||
46 | +} |
src/com/ectrip/cyt/constant/ParamContants.java
@@ -16,4 +16,12 @@ public class ParamContants { | @@ -16,4 +16,12 @@ public class ParamContants { | ||
16 | public static String GET_SHIP_NAME = "GET_SHIP_NAME"; | 16 | public static String GET_SHIP_NAME = "GET_SHIP_NAME"; |
17 | public static String GET_SHIP_ID = "GET_SHIP_ID";// | 17 | public static String GET_SHIP_ID = "GET_SHIP_ID";// |
18 | public static String GET_PASS_TOTAL = "GET_PASS_TOTAL";// | 18 | public static String GET_PASS_TOTAL = "GET_PASS_TOTAL";// |
19 | + public static String SET_FPT_HOST = "SET_FPT_HOST";//FTP地址 | ||
20 | + public static String SET_FPT_USETR = "SET_FPT_USETR";//FTP用户 | ||
21 | + public static String SET_FPT_PASSWORD = "SET_FPT_PASSWORD";//FTP密码 | ||
22 | + public static String SET_mac = "SET_mac";//mac地址 | ||
23 | + public static String SET_FPT_PORT = "SET_FPT_PORT";//FTP端口 | ||
24 | + public static String SET_ip = "SET_ip";//ip地址 | ||
25 | + | ||
26 | + | ||
19 | } | 27 | } |
src/com/ectrip/cyt/exceptionsave/debug/ConfigureLog4J.java
@@ -28,7 +28,7 @@ public class ConfigureLog4J { | @@ -28,7 +28,7 @@ public class ConfigureLog4J { | ||
28 | // String needWriteMessage = myLogSdf.format(nowtime); | 28 | // String needWriteMessage = myLogSdf.format(nowtime); |
29 | //日志文件路径地址:SD卡下myc文件夹log文件夹的test文件 | 29 | //日志文件路径地址:SD卡下myc文件夹log文件夹的test文件 |
30 | String fileName = Environment.getExternalStorageDirectory() | 30 | String fileName = Environment.getExternalStorageDirectory() |
31 | - + File.separator + "ectripLOG" + File.separator + "log" | 31 | + + File.separator + "ectripLOG" + File.separator + "log_CYT" |
32 | + File.separator + "tdos.log"; | 32 | + File.separator + "tdos.log"; |
33 | //设置文件名 | 33 | //设置文件名 |
34 | logConfigurator.setFileName(fileName); | 34 | logConfigurator.setFileName(fileName); |
src/com/ectrip/cyt/receiver/AlarmReceiver.java
0 → 100644
1 | +package com.ectrip.cyt.receiver; | ||
2 | + | ||
3 | +import android.content.BroadcastReceiver; | ||
4 | +import android.content.Context; | ||
5 | +import android.content.Intent; | ||
6 | + | ||
7 | +import com.ectrip.cyt.service.FtpParamerService; | ||
8 | +import com.ectrip.cyt.service.UploadLogService; | ||
9 | +import com.ectrip.cyt.utils.LogUtil; | ||
10 | + | ||
11 | + | ||
12 | +public class AlarmReceiver extends BroadcastReceiver { | ||
13 | + | ||
14 | + public static final String ACTIION_UPLOAD = "UPLOAD"; | ||
15 | + public static final String ACTIION_FTPPARAMER = "FTPPARAMER"; | ||
16 | + | ||
17 | + @Override | ||
18 | + public void onReceive(Context context, Intent intent) { | ||
19 | + LogUtil.i("AlarmReceiver", "onReceive action = " + intent.getAction()); | ||
20 | + Intent intents; | ||
21 | + switch (intent.getAction()) { | ||
22 | + case ACTIION_UPLOAD: | ||
23 | + intents = new Intent(context, UploadLogService.class); | ||
24 | + context.startService(intents); | ||
25 | + break; | ||
26 | + case ACTIION_FTPPARAMER: | ||
27 | + intents = new Intent(context, FtpParamerService.class); | ||
28 | + context.startService(intents); | ||
29 | + break; | ||
30 | + default: | ||
31 | + break; | ||
32 | + } | ||
33 | + } | ||
34 | +} |
src/com/ectrip/cyt/service/FtpParamerService.java
0 → 100644
1 | +package com.ectrip.cyt.service; | ||
2 | + | ||
3 | +import android.annotation.SuppressLint; | ||
4 | +import android.app.Service; | ||
5 | +import android.content.Intent; | ||
6 | +import android.os.Handler; | ||
7 | +import android.os.IBinder; | ||
8 | +import android.os.Message; | ||
9 | +//import android.support.annotation.Nullable; | ||
10 | +import android.text.TextUtils; | ||
11 | + | ||
12 | +import com.ectrip.cyt.bean.GetFtp; | ||
13 | +import com.ectrip.cyt.bean.ResultBean; | ||
14 | +import com.ectrip.cyt.config.DevicTool; | ||
15 | +import com.ectrip.cyt.constant.CallBackTypeConstant; | ||
16 | +import com.ectrip.cyt.constant.CheckTicketConstant; | ||
17 | +import com.ectrip.cyt.constant.ParamContants; | ||
18 | +import com.ectrip.cyt.utils.LogUtil; | ||
19 | +import com.ectrip.cyt.utils.PreferenceUtils; | ||
20 | +import com.ectrip.trips.net.BasePostProtocol; | ||
21 | +import com.ectrip.trips.net.INetCallBack; | ||
22 | +import com.ectrip.trips.net.ModelTools; | ||
23 | + | ||
24 | + | ||
25 | +public class FtpParamerService extends Service { | ||
26 | + | ||
27 | + private String TAG = "FtpParamerService"; | ||
28 | + private String myId; | ||
29 | + private String accid; | ||
30 | + private String mac; | ||
31 | + private String url ; | ||
32 | + | ||
33 | + | ||
34 | +// private final int MSG_FTP_TIME = 1; | ||
35 | + private final int MSG_FTP_3721 = 2; | ||
36 | +// private final int MSG_FTP_8650 = 3; | ||
37 | +// private final int MSG_FTP_8612 = 4; | ||
38 | +// private final int MSG_FTP_SLCK = 5; | ||
39 | +// private final int MSG_FTP_ONE = 6; | ||
40 | + | ||
41 | + @SuppressLint("HandlerLeak") | ||
42 | + private Handler mHandle = new Handler() { | ||
43 | + @Override | ||
44 | + public void handleMessage(Message msg) { | ||
45 | + super.handleMessage(msg); | ||
46 | + switch (msg.what) { | ||
47 | + case MSG_FTP_3721: | ||
48 | + initFtp3721(); | ||
49 | + break; | ||
50 | + } | ||
51 | + } | ||
52 | + }; | ||
53 | + | ||
54 | + @Override | ||
55 | + public IBinder onBind(Intent intent) { | ||
56 | + | ||
57 | + return null; | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public void onCreate() { | ||
62 | + super.onCreate(); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public int onStartCommand(Intent intent, int flags, int startId) { | ||
67 | + initData(); | ||
68 | + mHandle.sendEmptyMessageDelayed(MSG_FTP_3721, 2500); | ||
69 | + | ||
70 | + | ||
71 | +// AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE); | ||
72 | +// int anHour = 5 * 60 * 1000; | ||
73 | +// long triggerAtTime = SystemClock.elapsedRealtime() + anHour; | ||
74 | +// Intent intent1 = new Intent(this, AlarmReceiver.class); | ||
75 | +// intent1.setAction(AlarmReceiver.ACTIION_CHECKDEV); | ||
76 | +// PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT); | ||
77 | +// manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pendingIntent); | ||
78 | + | ||
79 | + return super.onStartCommand(intent, flags, startId); | ||
80 | + } | ||
81 | + | ||
82 | + | ||
83 | + private void initData() { | ||
84 | + mac = PreferenceUtils.getString(this, ParamContants.SET_mac, ""); | ||
85 | + if(TextUtils.isEmpty(mac)){ | ||
86 | + mac = DevicTool.getInstance().getDevId(); | ||
87 | + PreferenceUtils.putString(this, ParamContants.SET_mac, mac); | ||
88 | + } | ||
89 | + String ip = PreferenceUtils.getString(this, ParamContants.SET_ip, ""); | ||
90 | + if (TextUtils.isEmpty(ip)) { | ||
91 | + return; | ||
92 | + } | ||
93 | + url = CheckTicketConstant.httphead + ip + CheckTicketConstant.action; | ||
94 | + } | ||
95 | + | ||
96 | + | ||
97 | + | ||
98 | + /** | ||
99 | + * 获取服务器参数,用于日志上传 | ||
100 | + */ | ||
101 | + private void initFtp3721() { | ||
102 | + GetFtp getFtp = new GetFtp(); | ||
103 | + getFtp.setAccid("3721"); //闸机ID | ||
104 | + getFtp.setMac(mac); | ||
105 | + new BasePostProtocol().loadMoreData(url, ModelTools.getParam(getFtp, CheckTicketConstant.GETFTP), new MainNetCallBack(CallBackTypeConstant.GETFEPPRARMETER)); | ||
106 | + } | ||
107 | + | ||
108 | + | ||
109 | + | ||
110 | + | ||
111 | + /** | ||
112 | + * 网络请求的回调 | ||
113 | + */ | ||
114 | + class MainNetCallBack implements INetCallBack { | ||
115 | + int type; | ||
116 | + | ||
117 | + public MainNetCallBack(int type) { | ||
118 | + this.type = type; | ||
119 | + } | ||
120 | + | ||
121 | + @Override | ||
122 | + public void onFailure(String error) { | ||
123 | + | ||
124 | + switch (type) { | ||
125 | + case CallBackTypeConstant.GETFEPPRARMETER: | ||
126 | + LogUtil.d(TAG, "【获取ftp参数失败 == 3721】"); | ||
127 | + break; | ||
128 | + default: | ||
129 | + LogUtil.d(TAG, error); | ||
130 | + break; | ||
131 | + } | ||
132 | + } | ||
133 | + | ||
134 | + @Override | ||
135 | + public void onSuccessed(String result) { | ||
136 | + LogUtil.d("HTTP", "【返回结果】" + result); | ||
137 | + switch (type) { | ||
138 | + case CallBackTypeConstant.GETFEPPRARMETER: | ||
139 | + getFtpParamer(result); | ||
140 | + break; | ||
141 | + default: | ||
142 | + break; | ||
143 | + } | ||
144 | + } | ||
145 | + | ||
146 | + | ||
147 | + @Override | ||
148 | + public void onPrepare() { | ||
149 | + } | ||
150 | + } | ||
151 | + | ||
152 | + | ||
153 | + | ||
154 | + private void getFtpParamer(String result) { | ||
155 | + try { | ||
156 | + ResultBean bean = ModelTools.parseRequest(result, ResultBean.class); | ||
157 | + String host = bean.getResult(0, 0); | ||
158 | + String port = bean.getResult(0, 1); | ||
159 | + String username = bean.getResult(0, 2); | ||
160 | + String password = bean.getResult(0, 3); | ||
161 | + if (!TextUtils.isEmpty(host) && !TextUtils.isEmpty(username) && !TextUtils.isEmpty(password) && host.length() > 1 && username.length() > 1 && password.length() > 1) { | ||
162 | + LogUtil.i(TAG, "【获取ftp参数正确】"); | ||
163 | + PreferenceUtils.putString(this,ParamContants.SET_FPT_HOST, host); | ||
164 | + PreferenceUtils.putString(this,ParamContants.SET_FPT_USETR, username); | ||
165 | + PreferenceUtils.putString(this,ParamContants.SET_FPT_PASSWORD, password); | ||
166 | + PreferenceUtils.putString(this,ParamContants.SET_FPT_PORT, port); | ||
167 | + } else { | ||
168 | + LogUtil.e(TAG, "【获取ftp参数失败!】"); | ||
169 | + } | ||
170 | + } catch (Exception e) { | ||
171 | + LogUtil.e(TAG, LogUtil.getExMsg(e)); | ||
172 | + } | ||
173 | + | ||
174 | + } | ||
175 | + | ||
176 | + | ||
177 | +} |
src/com/ectrip/cyt/service/UploadLogService.java
0 → 100644
1 | +package com.ectrip.cyt.service; | ||
2 | + | ||
3 | +import android.app.AlarmManager; | ||
4 | +import android.app.PendingIntent; | ||
5 | +import android.app.Service; | ||
6 | +import android.content.Intent; | ||
7 | +import android.os.Environment; | ||
8 | +import android.os.IBinder; | ||
9 | +import android.os.SystemClock; | ||
10 | +import android.text.TextUtils; | ||
11 | + | ||
12 | +import com.ectrip.cyt.config.MyApp; | ||
13 | +import com.ectrip.cyt.constant.ParamContants; | ||
14 | +import com.ectrip.cyt.receiver.AlarmReceiver; | ||
15 | +import com.ectrip.cyt.utils.FtpsTools; | ||
16 | +import com.ectrip.cyt.utils.LogUtil; | ||
17 | +import com.ectrip.cyt.utils.PreferenceUtils; | ||
18 | +import com.ectrip.cyt.utils.ThreadUtils; | ||
19 | + | ||
20 | + | ||
21 | +import java.io.File; | ||
22 | +import java.util.ArrayList; | ||
23 | +import java.util.List; | ||
24 | + | ||
25 | +public class UploadLogService extends Service { | ||
26 | + | ||
27 | + private String TAG = "UploadLogService"; | ||
28 | + | ||
29 | + @Override | ||
30 | + public IBinder onBind(Intent intent) { | ||
31 | + return null; | ||
32 | + } | ||
33 | + | ||
34 | + @Override | ||
35 | + public void onCreate() { | ||
36 | + super.onCreate(); | ||
37 | + } | ||
38 | + | ||
39 | + @Override | ||
40 | + public int onStartCommand(Intent intent, int flags, int startId) { | ||
41 | + ThreadUtils.getInstance().exeute(new MyRunnable()); | ||
42 | + | ||
43 | + AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE); | ||
44 | +// int anHour = 6 * 3600 * 1000; | ||
45 | + int anHour = 3 * 3600 * 1000; | ||
46 | +// int anHour = 120 * 1000; | ||
47 | + long triggerAtTime = SystemClock.elapsedRealtime() + anHour; | ||
48 | + Intent intent1 = new Intent(this, AlarmReceiver.class); | ||
49 | + intent1.setAction(AlarmReceiver.ACTIION_UPLOAD); | ||
50 | + PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT); | ||
51 | + manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pendingIntent); | ||
52 | + | ||
53 | + return super.onStartCommand(intent, flags, startId); | ||
54 | + } | ||
55 | + | ||
56 | + private class MyRunnable implements Runnable { | ||
57 | + @Override | ||
58 | + public void run() { | ||
59 | + try { | ||
60 | + Thread.sleep(30000); | ||
61 | + LogUtil.i(TAG, "【开始自动上传日记】"); | ||
62 | + String foldPath = Environment.getExternalStorageDirectory() | ||
63 | + + File.separator + "ectripLOG" + File.separator + "log_CYT" | ||
64 | + + File.separator; | ||
65 | + int countFile = FtpsTools.countFilesInFolder(foldPath); | ||
66 | + List<String> fileNames = new ArrayList<>(); | ||
67 | + if(countFile > 0){ | ||
68 | + fileNames.add(foldPath + "tdos.log"); | ||
69 | + for(int i=1;i<countFile;i++){ | ||
70 | + if(i >= 6){ | ||
71 | + break; | ||
72 | + } | ||
73 | + fileNames.add(foldPath + "tdos.log" + "." + i); | ||
74 | + } | ||
75 | + } | ||
76 | +// String fileName = Environment.getExternalStorageDirectory().getAbsolutePath() | ||
77 | +// + File.separator + "EctripAndroid" + File.separator + "log" | ||
78 | +// + File.separator + "check.log"; | ||
79 | + String host = PreferenceUtils.getString(MyApp.getInstance(), ParamContants.SET_FPT_HOST); | ||
80 | + String username = PreferenceUtils.getString(MyApp.getInstance(),ParamContants.SET_FPT_USETR); | ||
81 | + String password = PreferenceUtils.getString(MyApp.getInstance(),ParamContants.SET_FPT_PASSWORD); | ||
82 | + String mac = PreferenceUtils.getString(MyApp.getInstance(),ParamContants.SET_mac); | ||
83 | + String portStr = PreferenceUtils.getString(MyApp.getInstance(),ParamContants.SET_FPT_PORT); | ||
84 | + if (TextUtils.isEmpty(host) || TextUtils.isEmpty(username) || TextUtils.isEmpty(password) || TextUtils.isEmpty(mac)) { | ||
85 | + LogUtil.i(TAG, "【FTP参数不全】"); | ||
86 | + | ||
87 | + | ||
88 | + return; | ||
89 | + } | ||
90 | + int port; | ||
91 | + try { | ||
92 | + port = Integer.parseInt(portStr); | ||
93 | + } catch (Exception e) { | ||
94 | + port = 22; | ||
95 | + } | ||
96 | + FtpsTools.Sftp_server_multiple(fileNames, host, username, password, mac, port); | ||
97 | + | ||
98 | + } catch (Exception e) { | ||
99 | + e.printStackTrace(); | ||
100 | + } | ||
101 | + } | ||
102 | + } | ||
103 | +} |
src/com/ectrip/cyt/ui/MainActivity.java
@@ -16,6 +16,7 @@ import android.graphics.Bitmap; | @@ -16,6 +16,7 @@ import android.graphics.Bitmap; | ||
16 | import android.graphics.BitmapFactory; | 16 | import android.graphics.BitmapFactory; |
17 | import android.os.Build; | 17 | import android.os.Build; |
18 | import android.os.Bundle; | 18 | import android.os.Bundle; |
19 | +import android.os.Handler; | ||
19 | import android.text.InputType; | 20 | import android.text.InputType; |
20 | import android.text.TextUtils; | 21 | import android.text.TextUtils; |
21 | import android.util.DisplayMetrics; | 22 | import android.util.DisplayMetrics; |
@@ -45,17 +46,21 @@ import com.ectrip.cyt.constant.DeviceType; | @@ -45,17 +46,21 @@ import com.ectrip.cyt.constant.DeviceType; | ||
45 | import com.ectrip.cyt.constant.LogoType; | 46 | import com.ectrip.cyt.constant.LogoType; |
46 | import com.ectrip.cyt.constant.Module; | 47 | import com.ectrip.cyt.constant.Module; |
47 | import com.ectrip.cyt.constant.OrderCode; | 48 | import com.ectrip.cyt.constant.OrderCode; |
49 | +import com.ectrip.cyt.constant.ParamContants; | ||
48 | import com.ectrip.cyt.constant.SelectAction; | 50 | import com.ectrip.cyt.constant.SelectAction; |
49 | import com.ectrip.cyt.constant.constant; | 51 | import com.ectrip.cyt.constant.constant; |
50 | import com.ectrip.cyt.db.DbManager; | 52 | import com.ectrip.cyt.db.DbManager; |
51 | import com.ectrip.cyt.response.LoginResponse; | 53 | import com.ectrip.cyt.response.LoginResponse; |
54 | +import com.ectrip.cyt.service.FtpParamerService; | ||
52 | import com.ectrip.cyt.service.OrderRegularDelecteService; | 55 | import com.ectrip.cyt.service.OrderRegularDelecteService; |
56 | +import com.ectrip.cyt.service.UploadLogService; | ||
53 | import com.ectrip.cyt.shield_home.LockLayer.MToast; | 57 | import com.ectrip.cyt.shield_home.LockLayer.MToast; |
54 | import com.ectrip.cyt.utils.AESEncryptor; | 58 | import com.ectrip.cyt.utils.AESEncryptor; |
55 | import com.ectrip.cyt.utils.CommetryUtils; | 59 | import com.ectrip.cyt.utils.CommetryUtils; |
56 | import com.ectrip.cyt.utils.DenstityUtils; | 60 | import com.ectrip.cyt.utils.DenstityUtils; |
57 | import com.ectrip.cyt.utils.DesUtil; | 61 | import com.ectrip.cyt.utils.DesUtil; |
58 | import com.ectrip.cyt.utils.LogUtil; | 62 | import com.ectrip.cyt.utils.LogUtil; |
63 | +import com.ectrip.cyt.utils.PreferenceUtils; | ||
59 | import com.ectrip.cyt.utils.SharedPreferences2Obj; | 64 | import com.ectrip.cyt.utils.SharedPreferences2Obj; |
60 | import com.ectrip.trips.check.R; | 65 | import com.ectrip.trips.check.R; |
61 | import com.ectrip.trips.net.HttpHelper; | 66 | import com.ectrip.trips.net.HttpHelper; |
@@ -81,7 +86,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V | @@ -81,7 +86,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V | ||
81 | private TextView login; | 86 | private TextView login; |
82 | private TextView unlogin; | 87 | private TextView unlogin; |
83 | private TextView tv_username; | 88 | private TextView tv_username; |
84 | - | 89 | + private final Handler mHandler = new Handler(); |
85 | @Override | 90 | @Override |
86 | protected void onCreate(Bundle savedInstanceState) { | 91 | protected void onCreate(Bundle savedInstanceState) { |
87 | super.onCreate(savedInstanceState); | 92 | super.onCreate(savedInstanceState); |
@@ -93,6 +98,12 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V | @@ -93,6 +98,12 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V | ||
93 | regularDelecte(); | 98 | regularDelecte(); |
94 | typeJudgment(); | 99 | typeJudgment(); |
95 | LogUtil.e(TAG, "硬件序列号 : " + getSerialNumber() + ",型号 :" + Build.MODEL); | 100 | LogUtil.e(TAG, "硬件序列号 : " + getSerialNumber() + ",型号 :" + Build.MODEL); |
101 | + mHandler.postDelayed(new Runnable() { | ||
102 | + @Override | ||
103 | + public void run() { | ||
104 | + initService(); | ||
105 | + } | ||
106 | + }, 3000); | ||
96 | } | 107 | } |
97 | 108 | ||
98 | /** | 109 | /** |
@@ -116,6 +127,15 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V | @@ -116,6 +127,15 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V | ||
116 | 127 | ||
117 | } | 128 | } |
118 | 129 | ||
130 | + private void initService() { | ||
131 | + | ||
132 | + Intent ftp = new Intent(this, FtpParamerService.class); | ||
133 | + startService(ftp); | ||
134 | + | ||
135 | + Intent upLoad = new Intent(this, UploadLogService.class); | ||
136 | + startService(upLoad); | ||
137 | + } | ||
138 | + | ||
119 | 139 | ||
120 | /** | 140 | /** |
121 | * 获取硬件的序列号 | 141 | * 获取硬件的序列号 |
@@ -280,6 +300,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V | @@ -280,6 +300,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V | ||
280 | if (listConfig != null && listConfig.size() > 0) { | 300 | if (listConfig != null && listConfig.size() > 0) { |
281 | MyApp.getInstance().setServiceIp(listConfig.get(0).getEc_ip()); | 301 | MyApp.getInstance().setServiceIp(listConfig.get(0).getEc_ip()); |
282 | MyApp.getInstance().KeyStr = listConfig.get(0).getEc_identity(); | 302 | MyApp.getInstance().KeyStr = listConfig.get(0).getEc_identity(); |
303 | + setFtpUrl(listConfig.get(0).getEc_ip()); | ||
283 | try { | 304 | try { |
284 | String ec_signkey = AESEncryptor.decrypt(constant.decrypt, | 305 | String ec_signkey = AESEncryptor.decrypt(constant.decrypt, |
285 | listConfig.get(0).getEc_signkey()); | 306 | listConfig.get(0).getEc_signkey()); |
@@ -304,6 +325,12 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V | @@ -304,6 +325,12 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V | ||
304 | 325 | ||
305 | } | 326 | } |
306 | 327 | ||
328 | + private void setFtpUrl(String ec_ip) { | ||
329 | + int endIndex = ec_ip.trim().indexOf("/"); | ||
330 | + String url = ec_ip.trim().substring(0, endIndex); | ||
331 | + PreferenceUtils.putString(MyApp.getInstance(), ParamContants.SET_ip,url); | ||
332 | + } | ||
333 | + | ||
307 | private void initView() { | 334 | private void initView() { |
308 | gridView1 = (GridView) findViewById(R.id.gridView1); | 335 | gridView1 = (GridView) findViewById(R.id.gridView1); |
309 | adapter = new MainGridDataAdapter(MainActivity.this, initData()); | 336 | adapter = new MainGridDataAdapter(MainActivity.this, initData()); |
src/com/ectrip/cyt/ui/SettingsActivity.java
@@ -47,6 +47,7 @@ import antistatic.spinnerwheel.AbstractWheel; | @@ -47,6 +47,7 @@ import antistatic.spinnerwheel.AbstractWheel; | ||
47 | import com.ectrip.cyt.bean.ConfigBean; | 47 | import com.ectrip.cyt.bean.ConfigBean; |
48 | import com.ectrip.cyt.config.DevicTool; | 48 | import com.ectrip.cyt.config.DevicTool; |
49 | import com.ectrip.cyt.config.MyApp; | 49 | import com.ectrip.cyt.config.MyApp; |
50 | +import com.ectrip.cyt.constant.ParamContants; | ||
50 | import com.ectrip.cyt.constant.constant; | 51 | import com.ectrip.cyt.constant.constant; |
51 | import com.ectrip.cyt.db.DbManager; | 52 | import com.ectrip.cyt.db.DbManager; |
52 | import com.ectrip.cyt.shield_home.LockLayer.MToast; | 53 | import com.ectrip.cyt.shield_home.LockLayer.MToast; |
@@ -54,6 +55,7 @@ import com.ectrip.cyt.spinnerwheel.adapters.NumericWheelAdapter; | @@ -54,6 +55,7 @@ import com.ectrip.cyt.spinnerwheel.adapters.NumericWheelAdapter; | ||
54 | import com.ectrip.cyt.utils.AESEncryptor; | 55 | import com.ectrip.cyt.utils.AESEncryptor; |
55 | import com.ectrip.cyt.utils.CommetryUtils; | 56 | import com.ectrip.cyt.utils.CommetryUtils; |
56 | import com.ectrip.cyt.utils.LogUtil; | 57 | import com.ectrip.cyt.utils.LogUtil; |
58 | +import com.ectrip.cyt.utils.PreferenceUtils; | ||
57 | import com.ectrip.cyt.utils.SharedPreferences2Obj; | 59 | import com.ectrip.cyt.utils.SharedPreferences2Obj; |
58 | import com.ectrip.cyt.version.UpdateManager; | 60 | import com.ectrip.cyt.version.UpdateManager; |
59 | import com.ectrip.trips.check.R; | 61 | import com.ectrip.trips.check.R; |
src/com/ectrip/cyt/utils/DateUtils.java
@@ -6,6 +6,7 @@ import java.text.ParseException; | @@ -6,6 +6,7 @@ import java.text.ParseException; | ||
6 | import java.text.SimpleDateFormat; | 6 | import java.text.SimpleDateFormat; |
7 | import java.util.Calendar; | 7 | import java.util.Calendar; |
8 | import java.util.Date; | 8 | import java.util.Date; |
9 | +import java.util.Locale; | ||
9 | import java.util.TimeZone; | 10 | import java.util.TimeZone; |
10 | 11 | ||
11 | /** | 12 | /** |
@@ -681,4 +682,14 @@ public class DateUtils { | @@ -681,4 +682,14 @@ public class DateUtils { | ||
681 | public static String getDays() { | 682 | public static String getDays() { |
682 | return getTodayStr().substring(0, 10); | 683 | return getTodayStr().substring(0, 10); |
683 | } | 684 | } |
685 | + | ||
686 | + /** | ||
687 | + * 获取当前的时间 yyyy-MM-dd | ||
688 | + * @return | ||
689 | + */ | ||
690 | + public static String getCurrentDate() { | ||
691 | + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA); | ||
692 | + Date date = new Date(System.currentTimeMillis()); | ||
693 | + return format.format(date); | ||
694 | + } | ||
684 | } | 695 | } |
src/com/ectrip/cyt/utils/EncryptUtil.java
0 → 100644
1 | +package com.ectrip.cyt.utils; | ||
2 | + | ||
3 | + | ||
4 | +import java.io.UnsupportedEncodingException; | ||
5 | +import java.security.InvalidKeyException; | ||
6 | +import java.security.MessageDigest; | ||
7 | +import java.security.NoSuchAlgorithmException; | ||
8 | +import java.security.SecureRandom; | ||
9 | +import java.security.spec.InvalidKeySpecException; | ||
10 | + | ||
11 | +import javax.crypto.BadPaddingException; | ||
12 | +import javax.crypto.Cipher; | ||
13 | +import javax.crypto.IllegalBlockSizeException; | ||
14 | +import javax.crypto.NoSuchPaddingException; | ||
15 | +import javax.crypto.SecretKey; | ||
16 | +import javax.crypto.SecretKeyFactory; | ||
17 | +import javax.crypto.spec.DESedeKeySpec; | ||
18 | + | ||
19 | + | ||
20 | +/** | ||
21 | + * 基础加密算法类?当前支持des,md5码? | ||
22 | + * | ||
23 | + * @author huhaopeng | ||
24 | + */ | ||
25 | +public class EncryptUtil { | ||
26 | + | ||
27 | + /** | ||
28 | + * MD5值计码?p> | ||
29 | + * MD5的算法在RFC1321 中定码? | ||
30 | + * 在RFC 1321中,给出了Test suite用来码?码码你的实现是否正确码? | ||
31 | + * MD5 ("") = d41d8cd98f00b204e9800998ecf8427e | ||
32 | + * MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661 | ||
33 | + * MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72 | ||
34 | + * MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0 | ||
35 | + * MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b | ||
36 | + * @param str 源字符串 | ||
37 | + * @return md5码? | ||
38 | + */ | ||
39 | + public final static byte[] md5(String str) { | ||
40 | + try { | ||
41 | + byte[] res = str.getBytes("UTF-8"); | ||
42 | + MessageDigest mdTemp = MessageDigest.getInstance("MD5".toUpperCase()); | ||
43 | + mdTemp.update(res); | ||
44 | + byte[] hash = mdTemp.digest(); | ||
45 | + return hash; | ||
46 | + } catch (Exception e) { | ||
47 | + return null; | ||
48 | + } | ||
49 | + } | ||
50 | + | ||
51 | + //hex repr. of md5 | ||
52 | + public final static String MD5Hex(String input) { | ||
53 | + String s = null; | ||
54 | + char hexDigits[] = { // 用来将字节转换成 16 进制表示的字码? | ||
55 | + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', | ||
56 | + 'e', 'f'}; | ||
57 | + try { | ||
58 | + MessageDigest md = MessageDigest | ||
59 | + .getInstance("MD5"); | ||
60 | + md.update(input.getBytes("utf-8")); | ||
61 | + byte tmp[] = md.digest(); | ||
62 | + | ||
63 | + char str[] = new char[16 * 2]; | ||
64 | + | ||
65 | + int k = 0; | ||
66 | + for (int i = 0; i < 16; i++) { | ||
67 | + | ||
68 | + byte byte0 = tmp[i]; | ||
69 | + str[k++] = hexDigits[byte0 >>> 4 & 0xf]; | ||
70 | + str[k++] = hexDigits[byte0 & 0xf]; | ||
71 | + } | ||
72 | + s = new String(str); | ||
73 | + } catch (Exception e) { | ||
74 | + e.printStackTrace(); | ||
75 | + } | ||
76 | + return s; | ||
77 | + } | ||
78 | + | ||
79 | + // 加密后解码? | ||
80 | + public static String JM(byte[] inStr) { | ||
81 | + String newStr = new String(inStr); | ||
82 | + char[] a = newStr.toCharArray(); | ||
83 | + for (int i = 0; i < a.length; i++) { | ||
84 | + a[i] = (char) (a[i] ^ 't'); | ||
85 | + } | ||
86 | + String k = new String(a); | ||
87 | + return k; | ||
88 | + } | ||
89 | + | ||
90 | + | ||
91 | + | ||
92 | + | ||
93 | + | ||
94 | + | ||
95 | + | ||
96 | + /** | ||
97 | + * @param key 24位密码? | ||
98 | + * @param str 源字符串 | ||
99 | + * @return | ||
100 | + * @throws NoSuchAlgorithmException | ||
101 | + * @throws NoSuchPaddingException | ||
102 | + * @throws InvalidKeyException | ||
103 | + * @throws UnsupportedEncodingException | ||
104 | + * @throws InvalidKeySpecException | ||
105 | + * @throws IllegalBlockSizeException | ||
106 | + * @throws BadPaddingException | ||
107 | + */ | ||
108 | + public static byte[] des3Encrypt(String key, String str) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, UnsupportedEncodingException, InvalidKeySpecException, IllegalBlockSizeException, BadPaddingException { | ||
109 | + | ||
110 | + byte[] newkey = key.getBytes(); | ||
111 | + | ||
112 | + SecureRandom sr = new SecureRandom(); | ||
113 | + | ||
114 | + DESedeKeySpec dks = new DESedeKeySpec(newkey); | ||
115 | + | ||
116 | + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede"); | ||
117 | + | ||
118 | + SecretKey securekey = keyFactory.generateSecret(dks); | ||
119 | + | ||
120 | + Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding"); | ||
121 | + | ||
122 | + cipher.init(Cipher.ENCRYPT_MODE, securekey, sr); | ||
123 | + | ||
124 | + byte[] bt = cipher.doFinal(str.getBytes("utf-8")); | ||
125 | + | ||
126 | + return bt; | ||
127 | + } | ||
128 | + | ||
129 | + | ||
130 | + public final static String taoBaoMD5(String s) { | ||
131 | + char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', | ||
132 | + 'a', 'b', 'c', 'd', 'e', 'f'}; | ||
133 | + try { | ||
134 | + byte[] strTemp = s.getBytes("GBK"); | ||
135 | + MessageDigest mdTemp = MessageDigest.getInstance("MD5"); | ||
136 | + mdTemp.update(strTemp); | ||
137 | + byte[] md = mdTemp.digest(); | ||
138 | + int j = md.length; | ||
139 | + char str[] = new char[j * 2]; | ||
140 | + int k = 0; | ||
141 | + for (int i = 0; i < j; i++) { | ||
142 | + byte byte0 = md[i]; | ||
143 | + str[k++] = hexDigits[byte0 >>> 4 & 0xf]; | ||
144 | + str[k++] = hexDigits[byte0 & 0xf]; | ||
145 | + } | ||
146 | + return new String(str); | ||
147 | + } catch (Exception e) { | ||
148 | + return null; | ||
149 | + } | ||
150 | + } | ||
151 | +} | ||
152 | + |
src/com/ectrip/cyt/utils/FtpsTools.java
0 → 100644
1 | +package com.ectrip.cyt.utils; | ||
2 | + | ||
3 | +import com.jcraft.jsch.Channel; | ||
4 | +import com.jcraft.jsch.ChannelSftp; | ||
5 | +import com.jcraft.jsch.JSch; | ||
6 | +import com.jcraft.jsch.Session; | ||
7 | +import com.jcraft.jsch.SftpATTRS; | ||
8 | +import com.jcraft.jsch.SftpException; | ||
9 | + | ||
10 | +import java.io.File; | ||
11 | +import java.io.FileInputStream; | ||
12 | +import java.io.FileOutputStream; | ||
13 | +import java.util.List; | ||
14 | +import java.util.Properties; | ||
15 | +import java.util.Vector; | ||
16 | + | ||
17 | +/** | ||
18 | + * Created by dc on 2018/5/14. | ||
19 | + */ | ||
20 | + | ||
21 | +public class FtpsTools { | ||
22 | + private final static String TAG = FtpsTools.class.getSimpleName(); | ||
23 | + /** | ||
24 | + * 连接sftp服务器 | ||
25 | + * | ||
26 | + * @param host 主机 | ||
27 | + * @param port 端口 | ||
28 | + * @param username 用户名 | ||
29 | + * @param password 密码 | ||
30 | + * @return | ||
31 | + */ | ||
32 | + public ChannelSftp connect(String host, int port, String username, String password) { | ||
33 | + | ||
34 | + ChannelSftp sftp = null; | ||
35 | + try { | ||
36 | + JSch jsch = new JSch(); | ||
37 | + jsch.getSession(username, host, port); | ||
38 | + Session sshSession = jsch.getSession(username, host, port); | ||
39 | + LogUtil.d("FTP", "FTP创建Session"); | ||
40 | + sshSession.setPassword(password); | ||
41 | + Properties sshConfig = new Properties(); | ||
42 | + sshConfig.put("StrictHostKeyChecking", "no"); | ||
43 | + sshSession.setConfig(sshConfig); | ||
44 | + sshSession.connect(5000); | ||
45 | + LogUtil.d("FTP", "FTP创建连接"); | ||
46 | + Channel channel = sshSession.openChannel("sftp"); | ||
47 | + channel.connect(); | ||
48 | + sftp = (ChannelSftp) channel; | ||
49 | + LogUtil.d("FTP", "FTP连接成功"); | ||
50 | + } catch (Exception e) { | ||
51 | + LogUtil.d("FTP", "FTP连接失败-" + LogUtil.getExMsg(e)); | ||
52 | + } | ||
53 | + return sftp; | ||
54 | + } | ||
55 | + | ||
56 | + /** | ||
57 | + * 上传文件 | ||
58 | + * | ||
59 | + * @param directory 上传的目录 | ||
60 | + * @param uploadFile 要上传的文件 | ||
61 | + * @param sftp | ||
62 | + */ | ||
63 | + public void upload(String directory, String uploadFile, ChannelSftp sftp, String mac) { | ||
64 | + | ||
65 | + try { | ||
66 | + sftp.cd(directory); | ||
67 | + File file = new File(uploadFile); | ||
68 | + if (file.isFile()) { | ||
69 | +// String filename = mac + ".log"; //文件名为当前时间来保存 | ||
70 | + sftp.put(new FileInputStream(file), file.getName()); | ||
71 | + LogUtil.i("FtpsTools", "上传成功!"); | ||
72 | + } | ||
73 | + } catch (Exception e) { | ||
74 | + LogUtil.d("FTP", "FTP上传失败-" + LogUtil.getExMsg(e)); | ||
75 | + } | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * 下载文件 | ||
80 | + * | ||
81 | + * @param directory 下载目录 | ||
82 | + * @param downloadFile 下载的文件 | ||
83 | + * @param saveFile 存在本地的路径 | ||
84 | + * @param sftp | ||
85 | + */ | ||
86 | + public void download(String directory, String downloadFile, String saveFile, ChannelSftp sftp) { | ||
87 | + | ||
88 | + try { | ||
89 | + sftp.cd(directory); | ||
90 | + File file = new File(saveFile); | ||
91 | + sftp.get(downloadFile, new FileOutputStream(file)); | ||
92 | + } catch (Exception e) { | ||
93 | + e.printStackTrace(); | ||
94 | + } | ||
95 | + } | ||
96 | + | ||
97 | + /** | ||
98 | + * 删除文件 | ||
99 | + * | ||
100 | + * @param directory 要删除文件所在目录 | ||
101 | + * @param deleteFile 要删除的文件 | ||
102 | + * @param sftp | ||
103 | + */ | ||
104 | + public void delete(String directory, String deleteFile, ChannelSftp sftp) { | ||
105 | + | ||
106 | + try { | ||
107 | + sftp.cd(directory); | ||
108 | + sftp.rm(deleteFile); | ||
109 | + } catch (Exception e) { | ||
110 | + e.printStackTrace(); | ||
111 | + } | ||
112 | + } | ||
113 | + | ||
114 | + /** | ||
115 | + * 列出目录下的文件 | ||
116 | + * | ||
117 | + * @param directory 要列出的目录 | ||
118 | + * @param sftp | ||
119 | + * @return | ||
120 | + * @throws SftpException | ||
121 | + */ | ||
122 | + public Vector listFiles(String directory, ChannelSftp sftp) throws SftpException { | ||
123 | + | ||
124 | + return sftp.ls(directory); | ||
125 | + | ||
126 | + } | ||
127 | + | ||
128 | + //上传多个文件 | ||
129 | + public static void Sftp_server_multiple(List<String> files, String host, String username, String password, String mac, int port) { | ||
130 | + | ||
131 | + FtpsTools sf = new FtpsTools(); | ||
132 | + String directory = "/home/ectrip/"; | ||
133 | + String logPath = "EctripCYTLog"; | ||
134 | + String logPathDate = DateUtils.getCurrentDate(); | ||
135 | + ChannelSftp sftp = sf.connect(host, port, username, password); | ||
136 | + // 判断子目录文件夹是否存在,不存在即创建 | ||
137 | + SftpATTRS attrs = null; | ||
138 | + try { | ||
139 | + sftp.cd(directory); | ||
140 | + attrs = sftp.stat(logPath); | ||
141 | + } catch (Exception e) { | ||
142 | + LogUtil.e("FTP", "FTP连接目录失败1-" + LogUtil.getExMsg(e)); | ||
143 | + } | ||
144 | + try { | ||
145 | + LogUtil.i("FTP", "attrs 1 == " + attrs); | ||
146 | + if (attrs == null) { | ||
147 | + sftp.mkdir(logPath); //创建目录 | ||
148 | + LogUtil.d("FTP", "FTP创建目录成功"); | ||
149 | + } else { | ||
150 | + LogUtil.d("FTP", "已存在目录"); | ||
151 | + } | ||
152 | + } catch (Exception e) { | ||
153 | + LogUtil.e("FTP", "FTP创建目录失败-" + LogUtil.getExMsg(e)); | ||
154 | + } | ||
155 | + | ||
156 | + try { | ||
157 | + attrs = null; | ||
158 | + sftp.cd(logPath); | ||
159 | + attrs = sftp.stat(mac); | ||
160 | + } catch (Exception e) { | ||
161 | + LogUtil.d("FTP", "FTP连接目录失败2-" + LogUtil.getExMsg(e)); | ||
162 | + } | ||
163 | + | ||
164 | + try { | ||
165 | + LogUtil.i("FTP", "attrs 2 == " + attrs); | ||
166 | + if (attrs == null) { | ||
167 | + sftp.mkdir(mac); //创建目录 | ||
168 | + LogUtil.d("FTP", "FTP创建mac地址目录成功"); | ||
169 | + } else { | ||
170 | + LogUtil.d("FTP", "已存在mac地址目录"); | ||
171 | + } | ||
172 | + } catch (Exception e) { | ||
173 | + LogUtil.e("FTP", "FTP创建mac地址目录失败-" + LogUtil.getExMsg(e)); | ||
174 | + } | ||
175 | + | ||
176 | + try { | ||
177 | + attrs = null; | ||
178 | + sftp.cd(mac); | ||
179 | + attrs = sftp.stat(logPathDate); | ||
180 | + } catch (Exception e) { | ||
181 | + LogUtil.d("FTP", "FTP连接目录失败2-" + LogUtil.getExMsg(e)); | ||
182 | + } | ||
183 | + | ||
184 | + try { | ||
185 | + LogUtil.i("FTP", "attrs 3 == " + attrs); | ||
186 | + if (attrs == null) { | ||
187 | + sftp.mkdir(logPathDate); //创建目录 | ||
188 | + LogUtil.d("FTP", "FTP创建日期目录成功"); | ||
189 | + } else { | ||
190 | + LogUtil.d("FTP", "已存在日期目录"); | ||
191 | + } | ||
192 | + } catch (Exception e) { | ||
193 | + LogUtil.e("FTP", "FTP创建日期目录失败-" + LogUtil.getExMsg(e)); | ||
194 | + } | ||
195 | + | ||
196 | + directory = directory + logPath + File.separator + mac + File.separator +logPathDate; | ||
197 | + for (String file : files) { | ||
198 | + LogUtil.i("FTP","上传日志文件 :" + file); | ||
199 | + sf.upload(directory, file, sftp, mac);//上传文件到服务器 | ||
200 | + } | ||
201 | + | ||
202 | + } | ||
203 | + | ||
204 | + //上传文件 | ||
205 | + public static void Sftp_server(final String file, final String host, final String username, final String password, final String mac , final int port) { | ||
206 | + | ||
207 | + new Thread(new Runnable() { | ||
208 | + @Override | ||
209 | + public void run() { | ||
210 | + FtpsTools sf = new FtpsTools(); | ||
211 | + String directory = "/home/ectrip/"; | ||
212 | + String logPath = "EctripTScreenLog"; | ||
213 | + String uploadFile = file; | ||
214 | + ChannelSftp sftp = sf.connect(host, port, username, password); | ||
215 | + // 判断子目录文件夹是否存在,不存在即创建 | ||
216 | + SftpATTRS attrs = null; | ||
217 | + try { | ||
218 | + sftp.cd(directory); | ||
219 | + attrs = sftp.stat(logPath); | ||
220 | + } catch (Exception e) { | ||
221 | + LogUtil.d("FTP", "FTP创建目录失败-" + LogUtil.getExMsg(e)); | ||
222 | + } | ||
223 | + try { | ||
224 | + if (attrs == null) { | ||
225 | + sftp.mkdir(logPath); //创建目录 | ||
226 | + LogUtil.d("FTP", "FTP创建目录成功"); | ||
227 | + } else { | ||
228 | + LogUtil.d("FTP", "已存在目录"); | ||
229 | + } | ||
230 | + } catch (Exception e) { | ||
231 | + LogUtil.d("FTP", "FTP创建目录失败-" + LogUtil.getExMsg(e)); | ||
232 | + } | ||
233 | + directory = directory + logPath; | ||
234 | + sf.upload(directory, uploadFile, sftp, mac);//上传文件到服务器 | ||
235 | + } | ||
236 | + }).start(); | ||
237 | + } | ||
238 | + | ||
239 | + /** | ||
240 | + * 文件夹内文件的个数 | ||
241 | + * @param folderPath | ||
242 | + * @return | ||
243 | + * create by honceh 2023/9/1 | ||
244 | + */ | ||
245 | + public static int countFilesInFolder(String folderPath) { | ||
246 | + File folder = new File(folderPath); | ||
247 | + if (folder.isDirectory()) { | ||
248 | + File[] files = folder.listFiles(); | ||
249 | + if (files != null) { | ||
250 | + return files.length; | ||
251 | + } | ||
252 | + } | ||
253 | + return 0; | ||
254 | + } | ||
255 | + | ||
256 | +// /** | ||
257 | +// * 初始化ftp | ||
258 | +// */ | ||
259 | +// public static void initFTP() { | ||
260 | +// String[] params = {"FTTP", "3721"}; | ||
261 | +// String userId = DBUtils.queryData(ParameterContens.USER, null); | ||
262 | +// String password = DBUtils.queryData(ParameterContens.PWD, null); | ||
263 | +// Saleautoservice saleautoservice = new Saleautoservice(); | ||
264 | +// saleautoservice.setMd5Str(""); | ||
265 | +// saleautoservice.setUserId(userId); | ||
266 | +// saleautoservice.setPassword(password); | ||
267 | +// saleautoservice.setMethod(13); | ||
268 | +// saleautoservice.setParameters(params); | ||
269 | +// getFTPResult("saleautoservice", saleautoservice); | ||
270 | +// } | ||
271 | +// | ||
272 | +// private static void getFTPResult(String method, Object data) { | ||
273 | +// | ||
274 | +// APIService.getInstance().loadData(method, data, BaseSaleResponse.class, new OnResultListener<BaseSaleResponse>() { | ||
275 | +// @Override | ||
276 | +// public void onResult(BaseSaleResponse result) { | ||
277 | +// try { | ||
278 | +// if (result.getCode().equals("200")) { | ||
279 | +// ResultBean bean = JSON.parseObject(JSON.toJSONString(result.getData()), ResultBean.class); | ||
280 | +// ShowResultBean.show(bean); | ||
281 | +// //处理结果 | ||
282 | +// LogUtil.i(TAG, "000" + result.getMsg()); | ||
283 | +// String resultState = result.getMsg().toLowerCase(); | ||
284 | +// if (TextUtils.equals("success", resultState)) { | ||
285 | +// LogUtil.i(TAG, "获取ftp服务器数据成功"); | ||
286 | +// DBUtils.insertData(ParameterContens.SET_FPT_HOST, bean.getResult(0, "pmva")); | ||
287 | +// DBUtils.insertData(ParameterContens.SET_FPT_USETR, bean.getResult(0, "pmvc")); | ||
288 | +// DBUtils.insertData(ParameterContens.SET_FPT_PASSWORD, bean.getResult(0, "pmvd")); | ||
289 | +// DBUtils.insertData(ParameterContens.SET_FPT_PORT, bean.getResult(0, "pmvb")); | ||
290 | +// | ||
291 | +// } else { | ||
292 | +// LogUtil.i(TAG, "获取ftp服务器数据失败"); | ||
293 | +// } | ||
294 | +// } | ||
295 | +// } catch (Exception e) { | ||
296 | +// LogUtil.i(TAG, "获取ftp服务器数据异常"); | ||
297 | +// LogUtil.d("ResultBean", LogUtil.getExMsg(e)); | ||
298 | +// } | ||
299 | +// } | ||
300 | +// | ||
301 | +// @Override | ||
302 | +// public void onCompleted() { | ||
303 | +// | ||
304 | +// } | ||
305 | +// | ||
306 | +// @Override | ||
307 | +// public void onError(String error) { | ||
308 | +// LogUtil.d("ResultBean", error); | ||
309 | +// } | ||
310 | +// }); | ||
311 | +// } | ||
312 | + | ||
313 | +} |
src/com/ectrip/cyt/utils/SignTools.java
0 → 100644
1 | +package com.ectrip.cyt.utils; | ||
2 | + | ||
3 | + | ||
4 | +import com.ectrip.cyt.constant.CheckTicketConstant; | ||
5 | + | ||
6 | + | ||
7 | +/** | ||
8 | + * 签名工具 | ||
9 | + * Created by lingkitho on 2017/3/1. | ||
10 | + */ | ||
11 | +public class SignTools { | ||
12 | + | ||
13 | + /** | ||
14 | + * 签名 | ||
15 | + * @param data | ||
16 | + * @return | ||
17 | + */ | ||
18 | + public static String getSign(String data) { | ||
19 | + if(null != data) { | ||
20 | + return EncryptUtil.MD5Hex(data + CheckTicketConstant.MD5KEY); | ||
21 | + }else { | ||
22 | + return null; | ||
23 | + } | ||
24 | + } | ||
25 | + | ||
26 | + /** | ||
27 | + * 检查签名 | ||
28 | + * @param signKey | ||
29 | + * @param data | ||
30 | + * @return | ||
31 | + */ | ||
32 | + public static boolean chechSign(String signKey, String data){ | ||
33 | + return signKey.equals(getSign(data)); | ||
34 | + } | ||
35 | +} |
src/com/ectrip/cyt/utils/ThreadUtils.java
0 → 100644
1 | +package com.ectrip.cyt.utils; | ||
2 | + | ||
3 | +import java.util.concurrent.LinkedBlockingDeque; | ||
4 | +import java.util.concurrent.ThreadPoolExecutor; | ||
5 | +import java.util.concurrent.TimeUnit; | ||
6 | + | ||
7 | +public class ThreadUtils { | ||
8 | + private static ThreadPool instance; | ||
9 | + | ||
10 | + private ThreadUtils() { | ||
11 | + } | ||
12 | + | ||
13 | + public static ThreadPool getInstance() { | ||
14 | + if (instance == null) { | ||
15 | + synchronized (ThreadUtils.class) { | ||
16 | + if ((instance == null)) { | ||
17 | + int cpuCount = Runtime.getRuntime().availableProcessors(); // 获取cpu数量,即核数 | ||
18 | + int threadCount = cpuCount * 2 + 1; //线程池中线程的个数---cpu核数*2+1--性能最佳 | ||
19 | + LogUtil.i("ThreadUtils", "ThreadUtils count == " + threadCount); | ||
20 | + instance = new ThreadPool(threadCount, threadCount, 0L); | ||
21 | + | ||
22 | + } | ||
23 | + } | ||
24 | + } | ||
25 | + return instance; | ||
26 | + } | ||
27 | + | ||
28 | + public static class ThreadPool { | ||
29 | + private int corePoolSize; | ||
30 | + private int maximunPoolSize; | ||
31 | + private long keepAliveTime; | ||
32 | + | ||
33 | + private ThreadPoolExecutor executor; | ||
34 | + | ||
35 | + public ThreadPool(int corePoolSize, int maximunPoolSize, long keepAliveTime) { | ||
36 | + this.corePoolSize = corePoolSize; | ||
37 | + this.maximunPoolSize = maximunPoolSize; | ||
38 | + this.keepAliveTime = keepAliveTime; | ||
39 | + } | ||
40 | + | ||
41 | + public void exeute(Runnable runnable) { | ||
42 | + if (executor == null) { | ||
43 | + executor = new ThreadPoolExecutor(corePoolSize, | ||
44 | + maximunPoolSize, keepAliveTime, TimeUnit.SECONDS, | ||
45 | + new LinkedBlockingDeque<Runnable>(), | ||
46 | + new ThreadPoolExecutor.AbortPolicy()); | ||
47 | + | ||
48 | + } | ||
49 | + executor.execute(runnable); | ||
50 | + } | ||
51 | + | ||
52 | + public void cancel(Runnable r) { | ||
53 | + if (executor != null) { | ||
54 | + executor.getQueue().remove(r); | ||
55 | + } | ||
56 | + } | ||
57 | + | ||
58 | + public void close() { | ||
59 | + if (executor != null) { | ||
60 | + executor.shutdownNow(); | ||
61 | + } | ||
62 | + } | ||
63 | + } | ||
64 | +} |
src/com/ectrip/trips/net/BasePostProtocol.java
0 → 100644
1 | +package com.ectrip.trips.net; | ||
2 | + | ||
3 | +import android.os.Handler; | ||
4 | +import android.os.Message; | ||
5 | + | ||
6 | +import com.ectrip.cyt.utils.LogUtil; | ||
7 | + | ||
8 | +import java.io.IOException; | ||
9 | + | ||
10 | +import okhttp3.MediaType; | ||
11 | +import okhttp3.OkHttpClient; | ||
12 | +import okhttp3.Request; | ||
13 | +import okhttp3.RequestBody; | ||
14 | +import okhttp3.Response; | ||
15 | + | ||
16 | + | ||
17 | +public class BasePostProtocol { | ||
18 | + | ||
19 | + private String url; | ||
20 | + private String mParamsStr; | ||
21 | + private Handler mHandler = new Handler() { | ||
22 | + @Override | ||
23 | + public void handleMessage(Message msg) { | ||
24 | + super.handleMessage(msg); | ||
25 | + switch (msg.what) { | ||
26 | + case 100://成功 | ||
27 | + String result = (String) msg.obj; | ||
28 | + callback.onSuccessed(result); | ||
29 | + break; | ||
30 | + case 101://失败 | ||
31 | + String error = (String) msg.obj; | ||
32 | + callback.onFailure(error); | ||
33 | + LogUtil.d("HTTP", error); | ||
34 | + break; | ||
35 | + } | ||
36 | + | ||
37 | + } | ||
38 | + }; | ||
39 | + INetCallBack callback; | ||
40 | + | ||
41 | + /** | ||
42 | + * post 请求的方法 | ||
43 | + * | ||
44 | + * @param url 请求地址 | ||
45 | + * @param paramStr 参数 | ||
46 | + */ | ||
47 | + | ||
48 | + public void loadMoreData(String url, String paramStr, final INetCallBack call) { | ||
49 | + LogUtil.d("HTTP", "【请求地址】" + url); | ||
50 | + LogUtil.d("HTTP", "【请求参数】" + paramStr); | ||
51 | + mParamsStr = paramStr; | ||
52 | + this.url = url; | ||
53 | + callback = call; | ||
54 | + callback.onPrepare(); | ||
55 | + new Thread(new Runnable() { | ||
56 | + | ||
57 | + @Override | ||
58 | + public void run() { | ||
59 | + loadDataFromNet(); | ||
60 | + } | ||
61 | + }).start(); | ||
62 | + } | ||
63 | + | ||
64 | + private void loadDataFromNet() { | ||
65 | + try { | ||
66 | + OkHttpClient okHttpClient = OkHttpFactory.getOkHttpClient(); | ||
67 | + MediaType JSON = MediaType.parse("application/json; charset=utf-8"); | ||
68 | + RequestBody formBody = RequestBody.create(JSON, mParamsStr); | ||
69 | + Request request = new Request.Builder().url(url).post(formBody).build(); | ||
70 | + Response response; | ||
71 | + try { | ||
72 | + response = okHttpClient.newCall(request).execute(); | ||
73 | + if (response.isSuccessful()) { | ||
74 | + Message message = Message.obtain(); | ||
75 | + String result = response.body().string(); | ||
76 | + LogUtil.d("HTTP", result); | ||
77 | + message.obj = result; | ||
78 | + message.what = 100; | ||
79 | + mHandler.sendMessage(message); | ||
80 | + } else { | ||
81 | + Message message = Message.obtain(); | ||
82 | + String error = response.body().string(); | ||
83 | + LogUtil.d("HTTP", error); | ||
84 | + message.obj = error; | ||
85 | + message.what = 101; | ||
86 | + mHandler.sendMessage(message); | ||
87 | + } | ||
88 | + } catch (IOException e) { | ||
89 | + Message message = Message.obtain(); | ||
90 | + String error = LogUtil.getExMsg(e); | ||
91 | + LogUtil.d("HTTP", error); | ||
92 | + message.obj = error; | ||
93 | + message.what = 101; | ||
94 | + mHandler.sendMessage(message); | ||
95 | + } | ||
96 | + } catch (Exception e) { | ||
97 | + LogUtil.d("HTTP", LogUtil.getExMsg(e)); | ||
98 | + } | ||
99 | + | ||
100 | + } | ||
101 | + | ||
102 | +} |
src/com/ectrip/trips/net/INetCallBack.java
0 → 100644
src/com/ectrip/trips/net/ModelTools.java
0 → 100644
1 | +package com.ectrip.trips.net; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSON; | ||
4 | +import com.ectrip.cyt.bean.BaseRequest; | ||
5 | +import com.ectrip.cyt.bean.BaseResponse; | ||
6 | +import com.ectrip.cyt.bean.DataTranfer; | ||
7 | +import com.ectrip.cyt.utils.Base64; | ||
8 | +import com.ectrip.cyt.utils.LogUtil; | ||
9 | +import com.ectrip.cyt.utils.SignTools; | ||
10 | + | ||
11 | + | ||
12 | +/** | ||
13 | + * This is a tool class for Check Ticket Http | ||
14 | + * Created by lingkitho on 2017/3/1. | ||
15 | + */ | ||
16 | +public class ModelTools { | ||
17 | + | ||
18 | + /** | ||
19 | + * 解析请求体 - 将Http请求转换成Bean对象 | ||
20 | + * @param rawData 原始数据 | ||
21 | + * @param clazz 类模板 | ||
22 | + * @return Bean 对象 | ||
23 | + */ | ||
24 | + public static <T> T parseRequest(String rawData, Class<T> clazz) throws Exception { | ||
25 | + | ||
26 | + | ||
27 | + DataTranfer dataTranfer = null; | ||
28 | + String param;//请求数据 | ||
29 | + try { | ||
30 | + dataTranfer = JSON.parseObject(rawData,DataTranfer.class); | ||
31 | + if(null == dataTranfer){ | ||
32 | + throw new Exception("原始数据为空!"); | ||
33 | + } | ||
34 | + if(null == dataTranfer.getSigned()){ | ||
35 | + throw new Exception("签名为空!"); | ||
36 | + } | ||
37 | + boolean isOk = SignTools.chechSign(dataTranfer.getSigned(),dataTranfer.getData()); | ||
38 | + if(!isOk){ | ||
39 | + throw new Exception("签名验证失败!"); | ||
40 | + } | ||
41 | + | ||
42 | + } catch (Exception e) { | ||
43 | + throw new Exception("原始数据json格式不正确!"+ LogUtil.getExMsg(e)); | ||
44 | + } | ||
45 | + try { | ||
46 | + byte[] requestDataJson = Base64.decode(dataTranfer.getData()); | ||
47 | + param = new String(requestDataJson); | ||
48 | + } catch (Exception e) { | ||
49 | + throw new Exception("请求数据解密失败!请勿篡改数据。请检查参数!"); | ||
50 | + } | ||
51 | + if(null != param && param.length()>0) { | ||
52 | + try { | ||
53 | + BaseResponse response = JSON.parseObject(param,BaseResponse.class); | ||
54 | + if(response != null && response.getData() != null){ | ||
55 | + T obj = JSON.parseObject(response.getData().toString(), clazz); | ||
56 | + LogUtil.i("CHECK","【请求数据返回成功】ResultBean="+response.getData().toString()); | ||
57 | + if(null == obj){ | ||
58 | + throw new Exception("转换后的请求实体为null,请检查参数"); | ||
59 | + } | ||
60 | + return obj; | ||
61 | + } | ||
62 | + return null; | ||
63 | + } catch (Exception e) { | ||
64 | + throw new Exception("json实体转换错误。请检查参数,且确保参数与接口对应"); | ||
65 | + } | ||
66 | + }else{ | ||
67 | + return null; | ||
68 | + } | ||
69 | + } | ||
70 | + | ||
71 | + public static BaseResponse parseRequestFace(String rawData) throws Exception { | ||
72 | + BaseResponse response = null; | ||
73 | + | ||
74 | + DataTranfer dataTranfer = null; | ||
75 | + String param;//请求数据 | ||
76 | + try { | ||
77 | + dataTranfer = JSON.parseObject(rawData,DataTranfer.class); | ||
78 | + if(null == dataTranfer){ | ||
79 | + throw new Exception("原始数据为空!"); | ||
80 | + } | ||
81 | + if(null == dataTranfer.getSigned()){ | ||
82 | + throw new Exception("签名为空!"); | ||
83 | + } | ||
84 | + boolean isOk = SignTools.chechSign(dataTranfer.getSigned(),dataTranfer.getData()); | ||
85 | + if(!isOk){ | ||
86 | + throw new Exception("签名验证失败!"); | ||
87 | + } | ||
88 | + | ||
89 | + } catch (Exception e) { | ||
90 | + throw new Exception("原始数据json格式不正确!"+ LogUtil.getExMsg(e)); | ||
91 | + } | ||
92 | + try { | ||
93 | + byte[] requestDataJson = Base64.decode(dataTranfer.getData()); | ||
94 | + param = new String(requestDataJson); | ||
95 | + } catch (Exception e) { | ||
96 | + throw new Exception("请求数据解密失败!请勿篡改数据。请检查参数!"); | ||
97 | + } | ||
98 | + if(null != param && param.length()>0) { | ||
99 | + try { | ||
100 | + response = JSON.parseObject(param,BaseResponse.class); | ||
101 | +// if(response != null && response.getData() != null){ | ||
102 | +//// T obj = JSON.parseObject(response.getData().toString(), clazz); | ||
103 | +//// T obj = (T)response.getData(); | ||
104 | +// LogUtil.i("CHECK","【请求数据返回成功】ResultBean="+response.getData().toString()); | ||
105 | +// if(null == obj){ | ||
106 | +// throw new Exception("转换后的请求实体为null,请检查参数"); | ||
107 | +// } | ||
108 | +// return obj; | ||
109 | +// } | ||
110 | + return response; | ||
111 | + } catch (Exception e) { | ||
112 | + throw new Exception("json实体转换错误。请检查参数,且确保参数与接口对应"); | ||
113 | + } | ||
114 | + }else{ | ||
115 | + return null; | ||
116 | + } | ||
117 | + } | ||
118 | + | ||
119 | + | ||
120 | + /** | ||
121 | + * 解析请求体 - 将Http请求转换成Bean对象 | ||
122 | + * @param rawData 原始数据 | ||
123 | + * @param clazz 类模板 | ||
124 | + * @return Bean 对象 | ||
125 | + */ | ||
126 | + public static <T> T parseBaseRequest(String rawData, Class<T> clazz) throws Exception { | ||
127 | + | ||
128 | + DataTranfer dataTranfer = null; | ||
129 | + String param;//请求数据 | ||
130 | + try { | ||
131 | + dataTranfer = JSON.parseObject(rawData,DataTranfer.class); | ||
132 | + if(null == dataTranfer){ | ||
133 | + throw new Exception("原始数据为空!"); | ||
134 | + } | ||
135 | + if(null == dataTranfer.getSigned()){ | ||
136 | + throw new Exception("签名为空!"); | ||
137 | + } | ||
138 | + boolean isOk = SignTools.chechSign(dataTranfer.getSigned(),dataTranfer.getData()); | ||
139 | + if(!isOk){ | ||
140 | + throw new Exception("签名验证失败!"); | ||
141 | + } | ||
142 | + | ||
143 | + } catch (Exception e) { | ||
144 | + throw new Exception("原始数据json格式不正确!"+ LogUtil.getExMsg(e)); | ||
145 | + } | ||
146 | + try { | ||
147 | + byte[] requestDataJson = Base64.decode(dataTranfer.getData()); | ||
148 | + param = new String(requestDataJson); | ||
149 | + } catch (Exception e) { | ||
150 | + throw new Exception("请求数据解密失败!请勿篡改数据。请检查参数!"); | ||
151 | + } | ||
152 | + if(null != param && param.length()>0) { | ||
153 | + try { | ||
154 | + T obj = JSON.parseObject(param, clazz); | ||
155 | + if(null == obj){ | ||
156 | + throw new Exception("转换后的请求实体为null,请检查参数"); | ||
157 | + } | ||
158 | + return obj; | ||
159 | + } catch (Exception e) { | ||
160 | + throw new Exception("json实体转换错误。请检查参数,且确保参数与接口对应"); | ||
161 | + } | ||
162 | + }else{ | ||
163 | + return null; | ||
164 | + } | ||
165 | + } | ||
166 | + | ||
167 | + public static String getParam (BaseRequest data , String method){ | ||
168 | + String dataJson = JSON.toJSONString(data);//将请求的实体转换成json字符串 | ||
169 | + String dataBase64 = Base64.encode(dataJson.getBytes());//将字符串进行base64加密 | ||
170 | + String signed = SignTools.getSign(dataBase64);//获得签名 | ||
171 | + DataTranfer dataTranfer = new DataTranfer();//封装到body的实体 | ||
172 | + dataTranfer.setData(dataBase64);//将base64的加密串作为data | ||
173 | + dataTranfer.setSigned(signed);//设置签名 | ||
174 | + dataTranfer.setMethod(method);//设置方法名 | ||
175 | + | ||
176 | + String param = JSON.toJSONString(dataTranfer); | ||
177 | + return param; | ||
178 | + } | ||
179 | + public static String getParamFace (String dataBase64 , String method){ | ||
180 | + String signed = SignTools.getSign(dataBase64);//获得签名 | ||
181 | + DataTranfer dataTranfer = new DataTranfer();//封装到body的实体 | ||
182 | + dataTranfer.setData(dataBase64);//将base64的加密串作为data | ||
183 | + dataTranfer.setSigned(signed);//设置签名 | ||
184 | + dataTranfer.setMethod(method);//设置方法名 | ||
185 | + | ||
186 | + String param = JSON.toJSONString(dataTranfer); | ||
187 | + return param; | ||
188 | + } | ||
189 | +} |
src/com/ectrip/trips/net/OkHttpFactory.java
0 → 100644
1 | +package com.ectrip.trips.net; | ||
2 | + | ||
3 | + | ||
4 | +import java.util.concurrent.TimeUnit; | ||
5 | + | ||
6 | +import okhttp3.OkHttpClient; | ||
7 | + | ||
8 | +public class OkHttpFactory { | ||
9 | + | ||
10 | + static OkHttpClient mOkHttpClient; | ||
11 | + | ||
12 | + | ||
13 | + public static OkHttpClient getOkHttpClient() { | ||
14 | + if (mOkHttpClient == null) { | ||
15 | + synchronized (OkHttpFactory.class) { | ||
16 | + if (mOkHttpClient == null) { | ||
17 | + mOkHttpClient = new OkHttpClient.Builder().connectTimeout(300, TimeUnit.SECONDS).build(); | ||
18 | + } | ||
19 | + } | ||
20 | + } | ||
21 | + return mOkHttpClient; | ||
22 | + } | ||
23 | +} |