71
	}
72
73
	public static String sendRequest(String url) {
74
		InputStream inputStream = null;
75
		BufferedReader bufferedReader = null;
76
		HttpURLConnection httpURLConnection = null;
77
		try {
78
			log.error("It's not error. request url: " + url);
79
			URL requestURL = new URL(url);
80
			// 获取连接
81
			httpURLConnection = (HttpURLConnection) requestURL.openConnection();
82
			httpURLConnection.setConnectTimeout(10000); // 建立连接的超时时间,毫秒
83
			httpURLConnection.setReadTimeout(25000); // 获得返回的超时时间,毫秒
84
			httpURLConnection.setRequestMethod("GET");
85
			httpURLConnection.setRequestProperty("Content-type", "text/html;charset=UTF-8");
86
			httpURLConnection.setRequestProperty("Accept",
87
					"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
88
			// 通过输入流获取请求的内容
89
			inputStream = httpURLConnection.getInputStream();
90
			bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
91
			String temp = null;
92
			StringBuffer stringBuffer = new StringBuffer();
93
			// 循环读取返回的结果
94
			while ((temp = bufferedReader.readLine()) != null) {
95
				stringBuffer.append(temp);
96
			}
97
98
			return stringBuffer.toString();
99
		} catch (Exception e) {
100
			log.error("sendRequest Exception: " + e);
101
		} finally {
102
			// 断开连接
103
			if (httpURLConnection != null) {
104
				httpURLConnection.disconnect();
105
			}
106
			// 关闭流
107
			if (bufferedReader != null) {
108
				try {
109
					bufferedReader.close();
110
				} catch (IOException e) {
111
					log.error("bufferedReader Exception: " + e);
112
				}
113
			}
114
			if (inputStream != null) {
115
				try {
116
					inputStream.close();
117
				} catch (IOException e) {
118
					log.error("inputStream Exception: " + e);
119
				}
120
			}
121
		}
122
		return null;
123
	}
124
125
	public static String sendPostRequest(String url, Map<String, String> map, String encoding) {
126
		String retStr = "";
127
		try {
128
			retStr = sendPostRequest(url, map, encoding, 0, 0);
129
		} catch (Exception ex) {
130
			log.error("sendPostRequest error: " + ex);
131
		}
132
133
		return retStr;
134
	}
135
136
	public static String sendPostRequest(String url, Map<String, String> map, String encoding, int ebossConnectTimeout,
137
			int ebossServiceTimeout) {
138
		CloseableHttpClient httpClient = HttpClients.createDefault();
139
		HttpPost httpPost = new HttpPost(url);
140
		String body = "";
141
142
		try {
143
			MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
144
			if (map != null) {
145
				for (Map.Entry<String, String> entry : map.entrySet()) {
146
					multipartEntityBuilder.addTextBody(entry.getKey(), entry.getValue());
147
				}
148
			}
149
150
			log.debug("ebossConnectTimeout:" + ebossConnectTimeout);
151
			log.debug("ebossServiceTimeout:" + ebossServiceTimeout);
152
153
			httpPost.setEntity(multipartEntityBuilder.build());
154
			if (ebossConnectTimeout != 0 && ebossServiceTimeout != 0) {
155
				RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(ebossServiceTimeout)
156
						.setConnectTimeout(ebossConnectTimeout).build();// 设置请求和传输超时时间
157
				httpPost.setConfig(requestConfig);
158
			}
159
160
			CloseableHttpResponse response = httpClient.execute(httpPost);
161
162
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
163
				HttpEntity entity = response.getEntity();
164
				if (entity != null) {
165
					// 按指定编码转换结果实体为String类型
166
					body = EntityUtils.toString(entity, encoding);
167
				}
168
				EntityUtils.consume(entity);
169
			}
170
		} catch (ClientProtocolException e) {
171
			log.error("ClientProtocolException Exception: " + e);
172
		} catch (UnsupportedEncodingException e) {
173
			log.error("UnsupportedEncodingException Exception: " + e);
174
		} catch (IOException e) {
175
			log.error("IOException Exception: " + e);
176
			// throw new BaseException("10", "调用Eboss超时");
177
		} finally {
178
			// 关闭连接,释放资源
179
			try {
180
				httpClient.close();
181
			} catch (IOException e) {
182
				log.error("httpClient Exception: " + e);
183
			}
184
		}
185
186
		return body;
187
	}
188
189
	public static String sendGet(String url, Charset encoding,Map<String,String> headerMap) {
190
		HttpClient httpClient = HttpClients.createDefault();
191
		HttpGet httpGet = new HttpGet(url);
192
		httpGet.addHeader(HTTP.CONTENT_TYPE, HTTP_CONTENT_TYPE_JSON);
193
		CloseableHttpResponse response = null;
194
		try {
195
			response = (CloseableHttpResponse) httpClient.execute(httpGet);
196
		} catch (Exception e) {
197
			log.error("sendGet Exception: " + e.getMessage());
198
			return "{}";
199
		}
200
		return responseEx(httpClient, response, encoding);
201
	}
202
203
	public static String sendPost(String url, Map<String, Object> paramsMap, Charset encoding) {
204
		HttpClient httpClient = HttpClients.createDefault();
205
		HttpPost httpPost = new HttpPost(url);
206
		httpPost.addHeader(HTTP.CONTENT_TYPE, HTTP_CONTENT_TYPE_JSON);
207
		if (paramsMap != null && paramsMap.size() > 0) {
208
			StringEntity se = new StringEntity(JSONObject.toJSONString(paramsMap), encoding);
209
			httpPost.setEntity(se);
210
		}
211
		CloseableHttpResponse response = null;
212
		try {
213
			response = (CloseableHttpResponse) httpClient.execute(httpPost);
214
		} catch (Exception e) {
215
			log.error("sendPost Exception: " + e.getMessage());
216
			return "{}";
217
		}
218
		return responseEx(httpClient, response, encoding);
219
	}
220
221
	public static String sendPost(String url, Map<String, Object> paramsMap, Charset encoding,
222
			Map<String, String> headerMap) {
223
		HttpClient httpClient = HttpClients.createDefault();
224
		HttpPost httpPost = new HttpPost(url);
225
226
		Iterator<String> iter = headerMap.keySet().iterator();
227
		String key = "";
228
		String value = "";
229
		while (iter.hasNext()) {
230
			key = iter.next();
231
			value = headerMap.get(key);
232
			httpPost.setHeader(key, value);
233
		}
234
235
		httpPost.addHeader(HTTP.CONTENT_TYPE, HTTP_CONTENT_TYPE_JSON);
236
		if (paramsMap != null && paramsMap.size() > 0) {
237
			log.debug("调用北向接口:url= " + url + ",参数= " + JSONObject.toJSONString(paramsMap));
238
			StringEntity se = new StringEntity(JSONObject.toJSONString(paramsMap), encoding);
239
			httpPost.setEntity(se);
240
		}
241
		CloseableHttpResponse response = null;
242
		try {
243
			response = (CloseableHttpResponse) httpClient.execute(httpPost);
244
		} catch (Exception e) {
245
			log.error("sendPost Exception: " + e.getMessage());
246
			return "{}";
247
		}
248
		return responseEx(httpClient, response, encoding);
249
	}
250
251
	public static String sendPut(String url, Map<String, String> params, Charset encoding) {
252
		HttpClient httpClient = HttpClients.createDefault();
253
		String resp = "";
254
		HttpPut httpPut = new HttpPut(url);
255
		httpPut.addHeader(HTTP.CONTENT_TYPE, HTTP_CONTENT_TYPE_JSON);
256
		if (params != null && params.size() > 0) {
257
			StringEntity se = new StringEntity(JSONObject.toJSONString(params), encoding);
258
			httpPut.setEntity(se);
259
		}
260
		CloseableHttpResponse response = null;
261
		try {
262
			response = (CloseableHttpResponse) httpClient.execute(httpPut);
263
		} catch (Exception e) {
264
			log.error("sendPut Exception: " + e.getMessage());
265
			return "{}";
266
		}
267
268
		return responseEx(httpClient, response, encoding);
269
	}
270
271
	private static String responseEx(HttpClient httpClient, CloseableHttpResponse response, Charset encoding) {
272
		String resp = "";
273
		try {
274
			if (response != null && 200 == response.getStatusLine().getStatusCode()) {
275
				resp = EntityUtils.toString(response.getEntity(), encoding);
276
			}
277
		} catch (Exception e) {
278
			log.error("responseEx Exception: " + e.getMessage());
279
		} finally {
280
			if (response != null) {
281
				try {
282
					response.close();
283
				} catch (Exception e) {
284
					log.error("responseEx Exception: " + e.getMessage());
285
				}
286
			}
287
		}
288
		return resp;
289
	}
290
291
}

+ 58 - 0
ebc-sea-platform/src/main/java/com/ai/bss/location/rescue/util/IpUtil.java

@ -0,0 +1,58 @@
1
package com.ai.bss.location.rescue.util;
2
3
4
import java.net.Inet4Address;
5
import java.net.InetAddress;
6
import java.net.NetworkInterface;
7
import java.net.SocketException;
8
import java.util.ArrayList;
9
import java.util.Collections;
10
import java.util.Enumeration;
11
import java.util.List;
12
13
/**
14
 * 地址工具类
15
 * 
16
 * @author Administrator
17
 *
18
 */
19
public class IpUtil {
20
	private static String hostAddress = null;
21
	
22
	/**
23
	 * 获取本机ip地址<BR/>
24
	 * 不会将.1结尾的ip作为合法地址</BR>
25
	 * 如果有多块网卡,将返回地址最小的那个<BR/>
26
	 * 可以在程序启动入口参数中指定本机地址
27
	 * 
28
	 * @return
29
	 * @throws SocketException
30
	 */
31
	public static String getHostAddress() throws SocketException {
32
		if(hostAddress!=null){
33
			return hostAddress;
34
		}
35
		
36
		InetAddress ip = null;
37
		List<String> addressList = new ArrayList<String>();
38
		Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
39
		while (allNetInterfaces.hasMoreElements())
40
		{
41
			NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
42
			Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
43
			while (addresses.hasMoreElements())
44
			{
45
				ip = (InetAddress) addresses.nextElement();
46
				if (ip != null && ip instanceof Inet4Address)
47
				{
48
					if (!ip.getHostAddress().endsWith(".1"))
49
							addressList.add(ip.getHostAddress());
50
				} 
51
			}
52
		}
53
		Collections.sort(addressList);
54
		hostAddress = (String)addressList.get(0);
55
		return hostAddress;
56
	}
57
	
58
}

+ 33 - 0
ebc-sea-platform/src/main/java/com/ai/bss/location/rescue/util/NorthboundInterfaceConstant.java

@ -0,0 +1,33 @@
1
package com.ai.bss.location.rescue.util;
2
3
/**
4
 * 北向接口的常量
5
 * @author konghl@asiainfo.com
6
 * 2020-10-29
7
 */
8
public class NorthboundInterfaceConstant {
9
	// 分页查询终端
10
	public static final String queryPageDevice="findTerminal";
11
	
12
	// 添加终端
13
	public static final String addDevice="device";
14
	
15
	// 修改终端
16
	public static final String updateDevice="updateDevice";
17
	
18
	// 删除终端
19
	public static final String deleteDevice="deleteDevice?deviceId=";
20
	
21
	// 查询单个设备
22
	public static final String queryOneDevice="deviceSimpleDetail?deviceId=";
23
	
24
	// 查询多个设备解析后的事件
25
	public static final String queryMoreDeviceNewIncident="findTerminalEventDataParseInResourceIdsLastData";
26
27
	//按时间段查询单个设备的事件
28
	public static final String queryOneDeviceIncident="findTerminalEventDataParseES";
29
	
30
	// 调用成功标识
31
	public static final String resultCode_succeed = "0";
32
33
}

+ 253 - 0
ebc-sea-platform/src/main/java/com/ai/bss/location/rescue/util/NorthboundInterfaceUtil.java

@ -0,0 +1,253 @@
1
package com.ai.bss.location.rescue.util;
2
3
import java.nio.charset.Charset;
4
import java.util.HashMap;
5
import java.util.Map;
6
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9
import org.springframework.beans.factory.annotation.Value;
10
import org.springframework.context.annotation.Configuration;
11
12
import com.alibaba.fastjson.JSON;
13
import com.alibaba.fastjson.JSONObject;
14
15
/**
16
 * 北向接口统一入口
17
 *
18
 * @date 2010/09/24 23:42
19
 */
20
@Configuration
21
public class NorthboundInterfaceUtil {
22
23
    private static final Logger logger = LoggerFactory.getLogger(NorthboundInterfaceUtil.class);
24
25
    @Value("${aap.iot.userCode:IOT_ADMIN}")
26
    private String userCode;
27
28
    @Value("${aap.iot.passWord:123456}")
29
    private String passWord;
30
31
    @Value("${url.iot.login:http://47.105.130.83:8083/sso/login}")
32
    private String iotLoginUrl;
33
34
    @Value("${url.iot.service:http://47.105.130.83:8083/dmp/terminalNorthApi/}")
35
    private String iotServiceUrl;
36
37
    /**
38
     * GET请求调用北向接口方法
39
     *
40
     * @param url
41
     * @return
42
     * @throws Exception
43
     */
44
    public Map<String, Object> iotGetCallUtil(String url) throws Exception {
45
        logger.debug("GET调用北向接口");
46
        Map<String, Object> resultMap = new HashMap<String, Object>();
47
        Map<String, String> signMap = new HashMap<String, String>();
48
49
        // 1.在缓存中获取sessionId与sign
50
        Object sign =CacheUtil.getCache("ebc_iot_north_sign");
51
        Object session_id = CacheUtil.getCache("ebc_iot_north_session_id");
52
53
        if (sign == null ) {
54
            // 2.如果没有调用登录接口从新获取
55
            signMap = iotLogin();
56
57
            if (signMap == null) {
58
                logger.debug("调用北向接口登录失败");
59
                return resultMap;
60
            }
61
62
        } else {
63
            signMap.put("ebc_iot_north_sign", String.valueOf(sign));
64
            signMap.put("ebc_iot_north_session_id", String.valueOf(session_id));
65
66
        }
67
68
        // 3.调用北向服务接口
69
        // (1)设置字符集
70
        Charset charset = Charset.forName("utf-8");
71
        try {
72
            // (2)调用接口
73
            String resultJson = HttpServiceUtil.sendGet(iotServiceUrl + url, charset, signMap);
74
            // (3)将参数转为Map<String,String>【将返回值统一为String】
75
            resultMap = JSON.parseObject(resultJson, Map.class);
76
        } catch (Exception e) {
77
            logger.error("调用北向接口失败: " + e.getMessage());
78
            return new HashMap<String, Object>();
79
        }
80
81
        if (resultMap == null) {
82
            logger.error("调用北向接口返回值为空");
83
            return new HashMap<String, Object>();
84
85
        } else if ("登录超时".equals(resultMap.get("resultMsg"))) {
86
            // 4.登录超时,需重新登录
87
            logger.info("调用北向接口失败,需重新登录");
88
            // (1)清除缓存
89
            CacheUtil.removeCache("ebc_iot_north_sign");
90
            CacheUtil.removeCache("ebc_iot_north_session_id");
91
            // (2)重新登录
92
            signMap = iotLogin();
93
94
            if (signMap == null) {
95
                logger.debug("再次调用北向接口登录失败");
96
                return resultMap;
97
            }
98
99
            try {
100
                // (3)再次调用接口
101
                String resultJson = HttpServiceUtil.sendGet(iotServiceUrl + url, charset, signMap);
102
                // (4)获取返回值
103
                resultMap = JSON.parseObject(resultJson, Map.class);
104
            } catch (Exception e) {
105
                logger.error("再次调用北向接口失败: " + e.getMessage());
106
                return new HashMap<String, Object>();
107
            }
108
109
            if (resultMap == null) {
110
                logger.error("再次调用北向接口返回值为空");
111
                return new HashMap<String, Object>();
112
            }
113
        }
114
115
        // 5.判断是否调用成功
116
        if (NorthboundInterfaceConstant.resultCode_succeed.equals(resultMap.get("resultCode"))) {
117
            logger.info("调用北向接口成功");
118
            return resultMap;
119
        } else {
120
            logger.info("调用北向接口失败");
121
            return new HashMap<String, Object>();
122
        }
123
    }
124
125
    /**
126
     * POST请求调用北向接口方法
127
     *
128
     * @param url
129
     * @param paramsMap
130
     * @return
131
     * @throws Exception
132
     */
133
    public Map<String, Object> iotPostCallUtil(String url, Map<String, Object> paramsMap) throws Exception {
134
        logger.debug("POSt调用北向接口");
135
        Map<String, Object> resultMap = new HashMap<String, Object>();
136
        Map<String, String> signMap = new HashMap<String, String>();
137
138
        // 1.在缓存中获取sessionId与sign
139
        Object sign =CacheUtil.getCache("ebc_iot_north_sign");
140
        Object session_id = CacheUtil.getCache("ebc_iot_north_session_id");
141
142
        if (sign == null ) {
143
            // 2.如果没有调用登录接口从新获取
144
            signMap = iotLogin();
145
146
            if (signMap == null) {
147
                logger.debug("调用北向接口登录失败");
148
                return resultMap;
149
            }
150
151
        } else {
152
            signMap.put("ebc_iot_north_sign", String.valueOf(sign));
153
            signMap.put("ebc_iot_north_session_id", String.valueOf(session_id));
154
155
        }
156
157
        // 3.调用北向服务接口
158
        // (1)设置字符集
159
        Charset charset = Charset.forName("utf-8");
160
        try {
161
            // (2)调用接口
162
            String resultJson = HttpServiceUtil.sendPost(iotServiceUrl + url, paramsMap, charset, signMap);
163
            // (3)将参数转为Map<String,String>【将返回值统一为String】
164
            resultMap = JSON.parseObject(resultJson, Map.class);
165
        } catch (Exception e) {
166
            logger.error("调用北向接口失败: " + e.getMessage());
167
            return new HashMap<String, Object>();
168
        }
169
170
        if (resultMap == null) {
171
            logger.error("调用北向接口返回值为空");
172
            return new HashMap<String, Object>();
173
        } else if ("登录超时".equals(resultMap.get("resultMsg"))) {
174
            // 4.登录超时,需重新登录
175
            logger.info("调用北向接口登录超时,需重新登录");
176
            // (1)清除缓存
177
            CacheUtil.removeCache("ebc_iot_north_sign");
178
            CacheUtil.removeCache("ebc_iot_north_session_id");
179
            // (2)重新登录
180
            signMap = iotLogin();
181
182
            if (signMap == null) {
183
                logger.debug("再次调用北向接口登录失败");
184
                return resultMap;
185
            }
186
187
            try {
188
                // (3)再次调用接口
189
                String resultJson = HttpServiceUtil.sendPost(iotServiceUrl + url, paramsMap, charset, signMap);
190
                // (4)获取返回值
191
                resultMap = JSON.parseObject(resultJson, Map.class);
192
            } catch (Exception e) {
193
                logger.error("再次调用北向接口失败: " + e.getMessage());
194
                return new HashMap<String, Object>();
195
            }
196
197
            if (resultMap == null) {
198
                logger.error("再次调用北向接口返回值为空");
199
                return new HashMap<String, Object>();
200
            }
201
        }
202
203
        // 5.判断是否调用成功
204
        if (NorthboundInterfaceConstant.resultCode_succeed.equals(resultMap.get("resultCode"))) {
205
            logger.info("调用北向接口成功");
206
            return resultMap;
207
        } else {
208
            logger.info("调用北向接口失败");
209
            return new HashMap<String, Object>();
210
        }
211
    }
212
213
    /**
214
     * 调用登录接口获取sessionId与sign
215
     *
216
     * @return
217
     */
218
    private Map<String, String> iotLogin() throws Exception {
219
        logger.debug("登录北向接口");
220
        HashMap<String, Object> loginParamMap = new HashMap<>();
221
222
        // 调用登录接口获取sessionId与sign
223
        loginParamMap.put("userCode", userCode);
224
        loginParamMap.put("passWord", passWord);
225
226
        // 设置字符集
227
        Charset charset = Charset.forName("utf-8");
228
229
        //Map<String, String> loginResultMap =new HashMap<String,String>();
230
        JSONObject loginResultJsonObject = null;
231
        try {
232
            // 调用登录接口
233
            String loginResult = HttpServiceUtil.sendPost(iotLoginUrl, loginParamMap, charset);
234
            loginResultJsonObject = JSON.parseObject(loginResult);
235
        } catch (Exception e) {
236
            logger.error("登录北向接口失败: " + e.getMessage());
237
            return null;
238
        }
239
240
        if (loginResultJsonObject != null && NorthboundInterfaceConstant.resultCode_succeed.equals(String.valueOf(loginResultJsonObject.get("resultCode")))) {
241
            logger.info("登录北向接口成功");
242
243
            Map<String, String> resultMap = (Map<String, String>) loginResultJsonObject.get("result");
244
            // 将数据存到缓存中
245
            CacheUtil.setCache("ebc_iot_north_sign", resultMap.get("sign"));
246
            CacheUtil.setCache("ebc_iot_north_session_id", resultMap.get("session_id"));
247
            return resultMap;
248
        } else {
249
            logger.info("登录北向接口失败");
250
            return null;
251
        }
252
    }
253
}

+ 48 - 0
ebc-sea-platform/src/main/java/com/ai/bss/location/rescue/util/SpringUtil.java

@ -0,0 +1,48 @@
1
package com.ai.bss.location.rescue.util;
2
3
import org.slf4j.Logger;
4
import org.slf4j.LoggerFactory;
5
import org.springframework.beans.BeansException;
6
import org.springframework.context.ApplicationContext;
7
import org.springframework.context.ApplicationContextAware;
8
import org.springframework.stereotype.Component;
9
10
@Component
11
public class SpringUtil implements ApplicationContextAware {
12
	private static final Logger logger = LoggerFactory.getLogger(SpringUtil.class);
13
	private static ApplicationContext applicationContext;
14
15
	private static void setApplicationcontext(ApplicationContext applicationContext) {
16
		if(SpringUtil.applicationContext == null) {
17
			SpringUtil.applicationContext = applicationContext;
18
        }
19
	}
20
	
21
    @Override
22
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
23
    	setApplicationcontext(applicationContext);
24
        logger.debug("---------------------------------------------------------------------");
25
        logger.debug("========ApplicationContext配置成功,在普通类可以通过调用SpringUtils.getAppContext()获取applicationContext对象,applicationContext="+SpringUtil.applicationContext+"========");
26
        logger.debug("---------------------------------------------------------------------");
27
    }
28
29
    //获取applicationContext
30
    public static ApplicationContext getApplicationContext() {
31
        return applicationContext;
32
    }
33
34
    //通过name获取 Bean.
35
    public static Object getBean(String name){
36
        return getApplicationContext().getBean(name);
37
    }
38
39
    //通过class获取Bean.
40
    public static <T> T getBean(Class<T> clazz){
41
        return getApplicationContext().getBean(clazz);
42
    }
43
44
    //通过name,以及Clazz返回指定的Bean
45
    public static <T> T getBean(String name,Class<T> clazz){
46
        return getApplicationContext().getBean(name, clazz);
47
    }
48
}

+ 15 - 0
ebc-sea-platform/src/main/resources/pro/application-gis.properties

@ -0,0 +1,15 @@
1
#gis\u767b\u5f55\u8d26\u53f7\u548c\u5bc6\u7801
2
aap.gis.userName=EBC_PPRS
3
aap.gis.passwd=ITBS93wMYHosT
4
5
#gis\u7684token\u5730\u5740
6
url.gis.token=http://192.168.74.189:9999/gisIntf/account/gettoken
7
8
#\u6d77\u56fe\u4e2d\u5fc3\u5750\u6807
9
seaMap.centre.longitude=123.396036
10
seaMap.centre.latitude=31.560302
11
12
#\u6d77\u56fe\u663e\u793a\u6bd4\u4f8b\u5c3a
13
# 5-->300km,6-->200km,7-->100km,8-->50km,9-->20km,10-->10km,11-->5km
14
# 12-->2km,13-->1km,14-->500m,15-->300m,16-->200m,17-->100m,18-->50m
15
seaMap.scale=8

+ 14 - 0
ebc-sea-platform/src/main/resources/pro/application-iot.properties

@ -0,0 +1,14 @@
1
#\u5317\u5411\u767b\u5f55\u8d26\u53f7\u548c\u5bc6\u7801
2
aap.iot.userCode=IOT_ADMIN
3
aap.iot.passWord=123456
4
5
#iot\u7684\u5317\u5411\u63a5\u53e3\u6ce8\u518c\u5730\u5740
6
#url.iot.login=http://60.205.219.67:8300/sso/login
7
url.iot.login=http://47.105.130.83:8083/sso/login
8
9
#iot\u7684\u5317\u5411\u63a5\u53e3\u7edf\u4e00\u5730\u5740
10
#url.iot.service=http://60.205.219.67:8300/dmp/terminalNorthApi/
11
url.iot.service=http://47.105.130.83:8083/dmp/terminalNorthApi/
12
13
#\u7ec8\u7aef\u8d85\u65f6\u79bb\u7ebf\u65f6\u95f4(\u5206\u949f)
14
device.overtime.offline=20

+ 54 - 0
ebc-sea-platform/src/main/resources/pro/application.properties

@ -0,0 +1,54 @@
1
spring.application.name=WorkTaskSpec
2
server.port=8011
3
4
server.servlet.context-path=/ipu
5
6
# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
7
#spring.datasource.url=jdbc:mysql://localhost:3306/cmp
8
spring.datasource.url=jdbc:mysql://10.19.90.34:3307/energy?serverTimezone=Asia/Shanghai&characterEncoding=utf-8&verifyServerCertificate=false&useSSL=false&requireSSL=false
9
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
10
spring.datasource.username=ebc
11
spring.datasource.password=ebc@123
12
13
# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
14
#spring.jpa.database=default
15
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
16
spring.jpa.hibernate.ddl-auto=none
17
spring.jpa.show-sql=true
18
spring.jpa.properties.hibernate.format_sql=true
19
spring.jpa.properties.hibernate.generate_statistics=false
20
spring.main.allow-bean-definition-overriding=true
21
22
#kafka
23
kafka.bootstrap-servers=47.105.160.21:9090
24
#kafka.bootstrap-servers=10.19.90.34:2182
25
#kafka.topic.deviceLocation=Topic_IoT_DeviceLocation
26
#kafka.topic.alarm=Topic_IoT_IndividualAlarm
27
kafka.topic.deviceLocation=DeviceLocationA
28
kafka.topic.alarm=IndividualAlarmA
29
kafka.producer.batch-size=16785
30
kafka.producer.retries=1
31
kafka.producer.buffer-memory=33554432
32
kafka.producer.linger=1
33
kafka.consumer.auto-offset-reset=latest
34
kafka.consumer.max-poll-records=3100
35
kafka.consumer.enable-auto-commit=false
36
kafka.consumer.auto-commit-interval=1000
37
kafka.consumer.session-timeout=20000
38
kafka.consumer.max-poll-interval=15000
39
kafka.consumer.max-partition-fetch-bytes=15728640
40
kafka.listener.batch-listener=false
41
kafka.listener.concurrencys=3,6
42
kafka.listener.poll-timeout=1500
43
44
45
# CACHE
46
#spring.cache.type=ehcache
47
#spring.cache.ehcache.config=ehcache.xml
48
49
# LOGGING
50
logging.level.com.ai=debug
51
logging.level.org.springframework.data=debug
52
53
# \u5f15\u5165gis\u548ciot\u7684\u914d\u7f6e\u6587\u4ef6
54
spring.profiles.active=iot,gis

+ 114 - 0
ebc-sea-platform/src/main/resources/pro/ipu-cache.xml

@ -0,0 +1,114 @@
1
<?xml version = '1.0' encoding = 'UTF-8'?>
2
<caches>
3
	<cache name="ssn" type="redis">
4
		<servers>
5
	        <!-- 如果不是cluster,则只使用第一个redis -->
6
	        <server ip="121.42.183.206" port="7101" />
7
	        <server ip="121.42.183.206" port="7102" />
8
	        <server ip="121.42.183.206" port="7103" />
9
	        <server ip="121.42.183.206" port="7104" />
10
	        <server ip="121.42.183.206" port="7105" />
11
	        <server ip="121.42.183.206" port="7106" />
12
	    </servers>
13
		<!-- 客户端类型:Jedis,JedisCluster -->
14
	    <config name="clientType" value="JedisCluster"/>
15
	    <!-- 访问redis的密码,可以为空 -->
16
	    <config name="auth" value="Ipu@321!"/>
17
	    <!-- redis池的可用连接实例的最大数目,缺省为8 -->
18
	    <config name="poolSize" value="10"/>
19
	    <!-- redis池最多有多少个状态为idle(空闲的)的jedis实例,缺省为8,空闲连接大于这个数会进行回收 -->
20
	    <config name="maxIdle"/>
21
	    <!-- 最小空闲数,空闲连接小于这个数会建立新的连接,缺省为0 -->
22
	    <config name="minIdle"/>
23
	    <!-- 等待Response超时时间,默认2000ms -->
24
	    <config name="soTimeout"/>
25
	    <!-- 连接Redis Server超时时间,默认2000ms -->
26
	    <config name="connTimeout"/>
27
	    <!-- 出现异常最大重试次数 -->
28
	    <config name="maxAttempts"/>
29
	</cache>
30
	
31
	<cache name="SSN_CACHE" type="redis">
32
		<servers>
33
	        <!-- 如果不是cluster,则只使用第一个redis -->
34
	        <server ip="121.42.183.206" port="7101" />
35
	        <server ip="121.42.183.206" port="7102" />
36
	        <server ip="121.42.183.206" port="7103" />
37
	        <server ip="121.42.183.206" port="7104" />
38
	        <server ip="121.42.183.206" port="7105" />
39
	        <server ip="121.42.183.206" port="7106" />
40
	    </servers>
41
		<!-- 客户端类型:Jedis,JedisCluster -->
42
	    <config name="clientType" value="JedisCluster"/>
43
	    <!-- 访问redis的密码,可以为空 -->
44
	    <config name="auth" value="Ipu@321!"/>
45
	    <!-- redis池的可用连接实例的最大数目,缺省为8 -->
46
	    <config name="poolSize" value="10"/>
47
	    <!-- redis池最多有多少个状态为idle(空闲的)的jedis实例,缺省为8,空闲连接大于这个数会进行回收 -->
48
	    <config name="maxIdle"/>
49
	    <!-- 最小空闲数,空闲连接小于这个数会建立新的连接,缺省为0 -->
50
	    <config name="minIdle"/>
51
	    <!-- 等待Response超时时间,默认2000ms -->
52
	    <config name="soTimeout"/>
53
	    <!-- 连接Redis Server超时时间,默认2000ms -->
54
	    <config name="connTimeout"/>
55
	    <!-- 出现异常最大重试次数 -->
56
	    <config name="maxAttempts"/>
57
	</cache>
58
	
59
	<cache name="client_route" type="redis">
60
		<servers>
61
	        <!-- 如果不是cluster,则只使用第一个redis -->
62
	        <server ip="121.42.183.206" port="7101" />
63
	        <server ip="121.42.183.206" port="7102" />
64
	        <server ip="121.42.183.206" port="7103" />
65
	        <server ip="121.42.183.206" port="7104" />
66
	        <server ip="121.42.183.206" port="7105" />
67
	        <server ip="121.42.183.206" port="7106" />
68
	    </servers>
69
		<!-- 客户端类型:Jedis,JedisCluster -->
70
	    <config name="clientType" value="JedisCluster"/>
71
	    <!-- 访问redis的密码,可以为空 -->
72
	    <config name="auth" value="Ipu@321!"/>
73
	    <!-- redis池的可用连接实例的最大数目,缺省为8 -->
74
	    <config name="poolSize" value="10"/>
75
	    <!-- redis池最多有多少个状态为idle(空闲的)的jedis实例,缺省为8,空闲连接大于这个数会进行回收 -->
76
	    <config name="maxIdle"/>
77
	    <!-- 最小空闲数,空闲连接小于这个数会建立新的连接,缺省为0 -->
78
	    <config name="minIdle"/>
79
	    <!-- 等待Response超时时间,默认2000ms -->
80
	    <config name="soTimeout"/>
81
	    <!-- 连接Redis Server超时时间,默认2000ms -->
82
	    <config name="connTimeout"/>
83
	    <!-- 出现异常最大重试次数 -->
84
	    <config name="maxAttempts"/>
85
	</cache>
86
	
87
	<cache name="pushServer_route" type="redis">
88
		<servers>
89
	        <!-- 如果不是cluster,则只使用第一个redis -->
90
	        <server ip="121.42.183.206" port="7101" />
91
	        <server ip="121.42.183.206" port="7102" />
92
	        <server ip="121.42.183.206" port="7103" />
93
	        <server ip="121.42.183.206" port="7104" />
94
	        <server ip="121.42.183.206" port="7105" />
95
	        <server ip="121.42.183.206" port="7106" />
96
	    </servers>
97
		<!-- 客户端类型:Jedis,JedisCluster -->
98
	    <config name="clientType" value="JedisCluster"/>
99
	    <!-- 访问redis的密码,可以为空 -->
100
	    <config name="auth" value="Ipu@321!"/>
101
	    <!-- redis池的可用连接实例的最大数目,缺省为8 -->
102
	    <config name="poolSize" value="10"/>
103
	    <!-- redis池最多有多少个状态为idle(空闲的)的jedis实例,缺省为8,空闲连接大于这个数会进行回收 -->
104
	    <config name="maxIdle"/>
105
	    <!-- 最小空闲数,空闲连接小于这个数会建立新的连接,缺省为0 -->
106
	    <config name="minIdle"/>
107
	    <!-- 等待Response超时时间,默认2000ms -->
108
	    <config name="soTimeout"/>
109
	    <!-- 连接Redis Server超时时间,默认2000ms -->
110
	    <config name="connTimeout"/>
111
	    <!-- 出现异常最大重试次数 -->
112
	    <config name="maxAttempts"/>
113
	</cache>
114
</caches>

+ 77 - 0
ebc-sea-platform/src/main/resources/pro/sso.properties

@ -0,0 +1,77 @@
1
#\u7CFB\u7EDF\u57DF
2
SYSTEM_DOMAIN=LOGIN_CACHE_ROUTE
3
4
#------------------------------cookie\u914D\u7F6E-------------#
5
##COOKIE\u7684\u6709\u6548\u57DF,\u4E0D\u8BBE\u7F6E\uFF0C\u5219\u81EA\u52A8\u8BBE\u7F6E
6
#COOKIE_DOMAIN=crm.chinapost.yw.com
7
8
COOKIE_PATH=/
9
10
##Session \u8D85\u65F6\u65F6\u95F4(\u79D2)
11
SESSION_TIMEOUT=3600
12
COOKIE_MAXAGE=-1
13
14
15
TENANT_REGISTER_CLASS=com.ai.customermanager.services.impl.CustRegisterVercodeImpl
16
17
18
##\u8FDC\u7A0B\u7F13\u5B58\u8C03\u7528\u7C7B\uFF0C\u8FD9\u4E2A\u7C7B\u5FC5\u987B\u6709\u4E09\u4E2A\u51FD\u6570 
19
##    public boolean set(String key,String value)
20
##    public String get(String key)
21
##    public boolean del(String key);
22
COOKIE_CACHE_CLASS=com.ai.sso.util.SessionRedisCache
23
24
LOGGING_INTERFACE_CLASS=com.wframe.baseinfo.util.BaseInfoUtil
25
26
##COOKIE_IS_CACHE \u662F\u5426\u7F13\u5B58\u5230\u8FDC\u7AEF\u3002
27
COOKIE_IS_CACHE=1
28
29
30
##IS_CHECK_LOGIN \u662F\u5426\u68C0\u67E5\u767B\u9646\u3002
31
IS_CHECK_LOGIN=1
32
33
34
LOGIN_SERVICE=uspa_IOrgmodelClientCSV_loginIn
35
LOGINNOPASS_SERVICE=uspa_IOrgmodelClientCSV_loginWithNoPassword
36
37
38
Access-Control-Allow-origin=http://crm.chinapost.yw.com:18080/
39
40
##\u68C0\u67E5SesisonId,sign \u662F\u5426\u6B63\u786E
41
SESSION_CHECK_SIGN=com.ai.sso.util.SessionCheckSign
42
SESSION_CHECK_LOGIN=com.ai.sso.util.SessionCheckLogin
43
#redis
44
45
##MAIN_PAGE
46
#MAIN_PAGE=http://crm.chinapost.com:18880/
47
##RETURN TAG \u8FD4\u56DE\u5B57\u7B26\u4E32
48
49
RETURN_TAG={"MESSAGE":"NOLOGIN","CODE":999999,"FLAG":"FAIL","RESULT":{"URL":"http://crm.chinapost.yw.com:18080/"}}
50
#RETURN_TAG=<html><script language="javascript"> function init(){ if(window.parent!=null) { window.parent.location.href ="http://crm.chinapost.com:18880"; } else window.location.href ="http://crm.chinapost.com:18880"; } </script><body onload="init()"></body></html>
51
52
53
54
redis.single=10.11.20.117:6379
55
redis.pool.maxTotal=1000
56
redis.pool.minIdle=5
57
redis.pool.maxIdle=100
58
redis.pool.testOnBorrow=false
59
redis.pool.maxWait=5000
60
redis.pool.testOnReturn=true
61
redis.pool.testWhileIdle=true
62
redis.pool.timeBetweenEvictionRunsMillis=10000
63
redis.password=luMZulgbotmo71aa
64
65
SESSION_DEFAULT_VERCODE=Hiz#8uAqkjhoPmXu8%aaa
66
67
#\u662F\u5426\u8FDB\u884C\u63A5\u53E3\u6743\u9650\u63A7\u5236 1 \u8FDB\u884C\u63A5\u53E3\u6743\u9650\u63A7\u5236 
68
is_check_interface=0
69
70
71
#BJYM\u4F7F\u7528
72
#USER_LOGIN_AUTH_CLASS=com.wframe.msgmanager.services.impl.UserLoginAuth4TestImpl
73
##\u5C0F\u7A0B\u5E8F\u4F7F\u7528
74
USER_LOGIN_AUTH_CLASS=com.wframe.usermanager.services.impl.UserLoginAuthImpl
75
#USER_LOGIN_AUTH_CLASS=com.wframe.msgmanager.services.impl.UserLoginByTokenImpl
76
#USER_LOGIN_AUTH_CLASS=com.wframe.msgmanager.services.impl.UserLoginByToken4XblImpl
77
SIGN_KEY_CODE=TENANT_CODE

@laijj@补充通用接口业务代码 · 6465c770d2 - Nuosi Git Service
Parcourir la Source

@laijj@补充通用接口业务代码

赖骏劼 2 ans auparavant
Parent
commit
6465c770d2

+ 23 - 4
ipu-show-server/pom.xml

@ -70,10 +70,10 @@
70 70
            <artifactId>junit</artifactId>
71 71
            <scope>test</scope>
72 72
        </dependency>
73
<!--        <dependency>-->
74
<!--            <groupId>org.springframework.boot</groupId>-->
75
<!--            <artifactId>spring-boot-starter-log4j2</artifactId>-->
76
<!--        </dependency>-->
73
        <!--        <dependency>-->
74
        <!--            <groupId>org.springframework.boot</groupId>-->
75
        <!--            <artifactId>spring-boot-starter-log4j2</artifactId>-->
76
        <!--        </dependency>-->
77 77
        <!--通用http接口-->
78 78
        <dependency>
79 79
            <groupId>cn.hutool</groupId>
@ -97,6 +97,12 @@
97 97
            <artifactId>ipu-file-system</artifactId>
98 98
            <version>3.0</version>
99 99
        </dependency>
100
        <!--加密依赖包-->
101
        <dependency>
102
            <groupId>org.bouncycastle</groupId>
103
            <artifactId>bcprov-jdk16</artifactId>
104
            <version>1.43</version>
105
        </dependency>
100 106
    </dependencies>
101 107
102 108
@ -110,6 +116,19 @@
110 116
                <groupId>org.codehaus.mojo</groupId>
111 117
                <artifactId>exec-maven-plugin</artifactId>
112 118
            </plugin>
119
            <!--引用本地jdk,主要是加解密组件需要用到-->
120
            <plugin>
121
                <artifactId>maven-compiler-plugin</artifactId>
122
                <configuration>
123
                    <source>1.8</source>
124
                    <target>1.8</target>
125
                    <encoding>UTF-8</encoding>
126
                    <compilerArguments>
127
                        <bootclasspath>${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/jre/lib/jce.jar</bootclasspath>
128
                        <extdirs>${project.basedir}/libs</extdirs>
129
                    </compilerArguments>
130
                </configuration>
131
            </plugin>
113 132
        </plugins>
114 133
        <finalName>ipu-show-server</finalName>
115 134
    </build>

+ 168 - 2
ipu-show-server/src/main/java/com/ai/ipu/show/bean/CommonBean.java

@ -3,21 +3,25 @@ package com.ai.ipu.show.bean;
3 3
import cn.hutool.http.HttpRequest;
4 4
import com.ai.ipu.basic.log.ILogger;
5 5
import com.ai.ipu.basic.log.IpuLoggerFactory;
6
import com.ai.ipu.server.frame.bean.AbstractBean;
6
import com.ai.ipu.server.config.MobileConfig;
7
import com.ai.ipu.show.core.bean.IpuAppBean;
8
import com.ai.ipu.show.util.AesUtils;
7 9
import com.ailk.common.data.IData;
10
import com.ailk.common.data.impl.DataMap;
8 11
import com.alibaba.fastjson.JSON;
9 12
import com.ai.ipu.show.util.Constant;
10 13
import com.ai.ipu.show.util.SpringContextUtils;
11 14
import org.springframework.core.env.Environment;
12 15
import org.springframework.util.StringUtils;
13 16
17
import java.util.HashMap;
14 18
import java.util.Map;
15 19
16 20
/**
17 21
 * @author
18 22
 * @desc
19 23
 */
20
public class CommonBean extends AbstractBean {
24
public class CommonBean extends IpuAppBean {
21 25
22 26
    /**
23 27
     * 环境参数工具
@ -98,5 +102,167 @@ public class CommonBean extends AbstractBean {
98 102
        sb.setLength(sb.length() - 1);
99 103
        return sb.toString();
100 104
    }
105
106
107
    /**
108
     * 通用公用接口请求方法
109
     *
110
     * @param requestParams
111
     * @return
112
     * @throws Exception
113
     */
114
    public IData commonInterfaceHandler(IData requestParams) throws Exception {
115
        //定义返回参数
116
        IData result = null;
117
        //先检查是否加密
118
        String encryptFlag = MobileConfig.getValue(Constant.COMMON_INTERFACE_KEY_ENCRYPTFLAG, Constant.COMMON_INTERFACE_DEFAULT_VALUE);
119
        String signFlag = MobileConfig.getValue(Constant.COMMON_INTERFACE_KEY_SIGNFLAG, Constant.COMMON_INTERFACE_DEFAULT_VALUE);
120
        //初始化正式参数,默认直接取上传的参数作为真实参数
121
        IData realReqParams = requestParams;
122
        if (Constant.COMMON_INTERFACE_TRUE_VALUE.equals(encryptFlag)) {
123
            //需要解密
124
            realReqParams = decryptReqData(requestParams);
125
        }
126
        if (Constant.COMMON_INTERFACE_TRUE_VALUE.equals(signFlag)) {
127
            //需要验签
128
            if (checkReqSign(realReqParams)) {
129
                result = createErrorMsg(realReqParams, "签名错误,请检查接口签名");
130
                return result;
131
            }
132
        }
133
        //请求类型(post/get)
134
        String requestType = realReqParams.getString(Constant.COMMON_INTERFACE_KEY_REQTYPE);
135
        //接口名称
136
        String interfaceName = realReqParams.getString(Constant.COMMON_INTERFACE_KEY_INTFNAME);
137
        if (StringUtils.isEmpty(requestType) || StringUtils.isEmpty(interfaceName)) {
138
            result = createErrorMsg(realReqParams, "请指定接口名称和请求方式");
139
            return result;
140
        }
141
142
        //重新组装业务请求参数
143
        //请求头内容
144
        Map<String, Object> headParamMap = new HashMap<>();
145
        IData headerDatas = realReqParams.getData(Constant.COMMON_INTERFACE_KEY_HEAD);
146
        for (String key : headerDatas.keySet()) {
147
            headParamMap.put(key, headerDatas.get(key));
148
        }
149
        //处理
150
        Map<String, Object> bodyParamMap = new HashMap<>();
151
        IData bodyDatas = realReqParams.getData(Constant.COMMON_INTERFACE_KEY_DATA);
152
        //请求body内容
153
        for (String key : requestParams.keySet()) {
154
            bodyParamMap.put(key, requestParams.get(key));
155
        }
156
157
        //获取json作为body
158
        String jsonParams = JSON.toJSONString(bodyParamMap);
159
        log.debug("获取到的json字符:jsonParams:" + jsonParams);
160
161
//        //接口加签名参数拼装
162
//        String appId = environment.getProperty(Constant.ENV_INTERFACE_APPID);
163
//        String timestamp = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
164
//        Map<String, String> signParam = new HashMap<String, String>();
165
//        signParam.put("appId", appId);
166
//        signParam.put("timestamp", timestamp);
167
//        // 如果业务参数需要加密,则这里需是加密后的值
168
//        signParam.put("content", jsonParams);
169
//        // 应用密钥
170
//        String key = environment.getProperty(Constant.ENV_INTERFACE_APPKEY);
171
//        //签名参数
172
//        String signValue = "";
173
//        try {
174
//            log.debug("接口签名加密参数:signParam:" + signParam.toString() + ",key:" + key);
175
//            signValue = SignUtil.sign(signParam, "HmacSHA256", key);
176
//            log.debug("接口签名加密结果:signValue:" + signValue);
177
//        } catch (Exception e) {
178
//            log.error("接口签名发生加密异常:" + e.getMessage());
179
//        }
180
181
        //外部接口返回的参数
182
        String reqResult = null;
183
        //请求url拼接
184
        String url = environment.getProperty(Constant.ENV_URL_BASEPATH) + interfaceName;
185
186
        //请求代理
187
        if (Boolean.parseBoolean(environment.getProperty(Constant.ENV_PROXY_FLAG))) {
188
            System.setProperty("http.proxySet", "true");
189
            System.setProperty("http.proxyHost", environment.getProperty(Constant.ENV_PROXY_SERVER));
190
            System.setProperty("http.proxyPort", environment.getProperty(Constant.ENV_PROXY_PORT));
191
        }
192
        //发送请求
193
        if (Constant.COMMON_INTERFACE_VALUE_POST.equalsIgnoreCase(requestType)) {
194
            log.debug("调用远端Post接口,接口请求地址:" + url + ",参数:" + jsonParams);
195
            HttpRequest httpRequest = HttpRequest.post(url);
196
            //添加header
197
            for (String headerKey : headParamMap.keySet()) {
198
                httpRequest.header(headerKey, headParamMap.get(headerKey).toString());
199
            }
200
            reqResult = httpRequest.contentType("application/json")
201
                    .body(jsonParams)
202
                    //超时,毫秒
203
                    .timeout(30000)
204
                    .execute().body();
205
            log.debug("调用远端Post接口,接口请求地址:" + url + ",返回:" + result);
206
        } else {
207
            //get请求,先要把参数转换到url里面
208
            String filterStrs = "requestType,interfaceName,token";
209
            String urlStr = idata2Url(requestParams, filterStrs);
210
            String reqUrl = url + urlStr;
211
            log.debug("调用远端get接口,接口请求地址:" + reqUrl);
212
            HttpRequest httpRequest = HttpRequest.get(reqUrl);
213
            //添加header
214
            for (String headerKey : headParamMap.keySet()) {
215
                httpRequest.header(headerKey, headParamMap.get(headerKey).toString());
216
            }
217
            reqResult = httpRequest
218
                    .contentType("x-www-form-urlencoded")
219
                    //超时,毫秒
220
                    .timeout(30000)
221
                    .execute().body();
222
            log.debug("调用远端get接口,接口请求地址:" + reqUrl + ",返回:" + reqResult);
223
        }
224
        IData retMap = createReturnData();
225
        if (Constant.COMMON_INTERFACE_TRUE_VALUE.equals(encryptFlag) && reqResult != null) {
226
            //需要加密
227
            String resultEncrypt = AesUtils.aes256ECBPkcs7PaddingHexEncrypt(reqResult, Constant.AES_KEY);
228
            retMap.put(Constant.COMMON_INTERFACE_KEY_DATA, resultEncrypt);
229
        } else {
230
            retMap.put(Constant.COMMON_INTERFACE_KEY_DATA, reqResult);
231
        }
232
        return retMap;
233
    }
234
235
    /**
236
     * 解密入参
237
     *
238
     * @param reqData
239
     * @return
240
     */
241
    public static IData decryptReqData(IData reqData) throws Exception {
242
        IData retIdata = new DataMap();
243
        //处理接口请求参数加解密
244
        String dataSrcStr = reqData.getString(Constant.COMMON_INTERFACE_KEY_DATA);
245
        log.debug("接口参数密文:" + dataSrcStr);
246
        if (dataSrcStr != null && dataSrcStr.length() > 0) {
247
            String dataJson = AesUtils.aes256ECBPkcs7PaddingHexDecrypt(dataSrcStr, Constant.AES_KEY);
248
            log.debug("接口参数解密后明文:" + dataJson);
249
            //把接口参数再次构造成DataMap赋值给参数对象
250
            retIdata = new DataMap(dataJson);
251
252
        }
253
        return retIdata;
254
    }
255
256
    /**
257
     * 签名验证方法
258
     *
259
     * @param reqData
260
     * @return
261
     * @throws Exception
262
     */
263
    public static boolean checkReqSign(IData reqData) throws Exception {
264
        //TODO Junjie.Lai 方法实现
265
        return true;
266
    }
101 267
}
102 268

+ 112 - 0
ipu-show-server/src/main/java/com/ai/ipu/show/util/AesUtils.java

@ -0,0 +1,112 @@
1
package com.ai.ipu.show.util;
2
3
import org.bouncycastle.jce.provider.BouncyCastleProvider;
4
5
import javax.crypto.Cipher;
6
import javax.crypto.spec.SecretKeySpec;
7
import java.nio.charset.StandardCharsets;
8
import java.security.Security;
9
import java.util.Base64;
10
11
/**
12
 * AES加密工具类
13
 */
14
public class AesUtils {
15
    private static final String SECRET = "AES";
16
    private static final String CIPHER_ALGORITHM = "AES/ECB/PKCS7Padding";
17
18
    static {
19
        Security.addProvider(new BouncyCastleProvider());
20
    }
21
22
    /**
23
     * AES加密ECB模式PKCS7Padding填充方式(Base64编码)
24
     * @param str 字符串
25
     * @param key 密钥
26
     * @return 加密字符串
27
     * @throws Exception 异常信息
28
     */
29
    public static String aes256ECBPkcs7PaddingEncrypt(String str, String key) throws Exception {
30
        Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
31
        byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
32
        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(keyBytes, SECRET));
33
        byte[] doFinal = cipher.doFinal(str.getBytes(StandardCharsets.UTF_8));
34
        return new String(Base64.getEncoder().encode(doFinal));
35
    }
36
37
    public static String encodeHexString(byte[] data) {
38
        StringBuilder sb = new StringBuilder();
39
        for (byte b : data) {
40
            sb.append(String.format("%02x", b));
41
        }
42
        return sb.toString();
43
    }
44
45
    public static String aes256ECBPkcs7PaddingHexEncrypt(String str, String key) throws Exception {
46
        Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
47
        byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
48
        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(keyBytes, SECRET));
49
        byte[] doFinal = cipher.doFinal(str.getBytes(StandardCharsets.UTF_8));
50
        return new String(encodeHexString(doFinal));
51
    }
52
53
54
55
    /**
56
     * AES解密ECB模式PKCS7Padding填充方式(Base64编码)
57
     * @param str 字符串
58
     * @param key 密钥
59
     * @return 解密字符串
60
     * @throws Exception 异常信息
61
     */
62
    public static String aes256ECBPkcs7PaddingDecrypt(String str, String key) throws Exception {
63
        Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
64
        byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
65
        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(keyBytes, SECRET));
66
        byte[] doFinal = cipher.doFinal(Base64.getDecoder().decode(str));
67
        return new String(doFinal);
68
    }
69
70
71
    public static byte[] hexStringToByteArray(String hexString) {
72
        hexString = hexString.replaceAll(" ", "");
73
        int len = hexString.length();
74
        byte[] bytes = new byte[len / 2];
75
        for (int i = 0; i < len; i += 2) {
76
            // 两位一组,表示一个字节,把这样表示的16进制字符串,还原成一个字节
77
            bytes[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4) + Character
78
                    .digit(hexString.charAt(i+1), 16));
79
        }
80
        return bytes;
81
    }
82
    /**
83
     * AES解密ECB模式PKCS7Padding填充方式(Hex编码)
84
     * @param str 字符串
85
     * @param key 密钥
86
     * @return 解密字符串
87
     * @throws Exception 异常信息
88
     */
89
    public static String aes256ECBPkcs7PaddingHexDecrypt(String str, String key) throws Exception {
90
        Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
91
        byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
92
        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(keyBytes, SECRET));
93
        byte[] doFinal = cipher.doFinal(hexStringToByteArray(str));
94
        return new String(doFinal);
95
    }
96
97
    public static void main(String[] args) throws Exception {
98
        String str = "fjadmin";
99
        System.out.println("字符串:" + str);
100
        String encryptStr = AesUtils.aes256ECBPkcs7PaddingEncrypt(str, "abcdefXXABCDEFxx");
101
        System.out.println("Base64编码,加密后字符串:" + encryptStr);
102
103
        String decryptStr = AesUtils.aes256ECBPkcs7PaddingDecrypt(encryptStr, "abcdefXXABCDEFxx");
104
        System.out.println("Base64编码,解密后字符串:" + decryptStr);
105
106
        String hexEncryptStr = AesUtils.aes256ECBPkcs7PaddingHexEncrypt(str, "abcdefXXABCDEFxx");
107
        System.out.println("Hex编码,加密后字符串:" + hexEncryptStr);
108
109
        String hexDecryptStr = AesUtils.aes256ECBPkcs7PaddingHexDecrypt(hexEncryptStr, "abcdefXXABCDEFxx");
110
        System.out.println("Hex编码,解密后字符串:" + hexDecryptStr);
111
    }
112
}

+ 51 - 0
ipu-show-server/src/main/java/com/ai/ipu/show/util/Constant.java

@ -89,4 +89,55 @@ public class Constant {
89 89
     */
90 90
    public static final String FILE_SAVE_PATH = "appserver.file.savepath";
91 91
92
    /**通用接口固定参数*/
93
    /**
94
     * 请求数据加密标识
95
     */
96
    public static final String COMMON_INTERFACE_KEY_ENCRYPTFLAG = "commInterfaceEncrypt";
97
98
    /**
99
     * 请求数据签名标识
100
     */
101
    public static final String COMMON_INTERFACE_KEY_SIGNFLAG = "commInterfaceSign";
102
103
    /**
104
     * AES加解密的KEY
105
     */
106
    public static final String AES_KEY = "onLineTradeTKAMC";
107
108
    /**
109
     * 参数标识,默认false
110
     */
111
    public static final String COMMON_INTERFACE_DEFAULT_VALUE = "false";
112
113
    /**
114
     * 参数标识,true
115
     */
116
    public static final String COMMON_INTERFACE_TRUE_VALUE = "true";
117
    /**
118
     * 接口请求类型
119
     */
120
    public static final String COMMON_INTERFACE_KEY_REQTYPE = "requestType";
121
122
    /**
123
     * 接口请求值
124
     */
125
    public static final String COMMON_INTERFACE_VALUE_POST = "POST";
126
    public static final String COMMON_INTERFACE_VALUE_GET = "GET";
127
128
    /**
129
     * 接口名称
130
     */
131
    public static final String COMMON_INTERFACE_KEY_INTFNAME = "interfaceName";
132
133
    /**
134
     * 发送到后端的请求head
135
     */
136
    public static final String COMMON_INTERFACE_KEY_HEAD = "head";
137
138
    /**
139
     * 发送到后端的请求data
140
     */
141
    public static final String COMMON_INTERFACE_KEY_DATA = "data";
142
92 143
}

+ 4 - 0
ipu-show-server/src/main/resources/server-config.xml

@ -21,6 +21,10 @@
21 21
    <config name="indexPage" value="Index"/>
22 22
    <!-- 文件是否加密 -->
23 23
    <config name="fileEncrypt" value="true"/>
24
    <!--通用接口是否加密-->
25
    <config name="commInterfaceEncrypt" value="false"/>
26
    <!--通用接口是否签名-->
27
    <config name="commInterfaceSign" value="false"/>
24 28
    <!-- 自定义异常管理器 -->
25 29
    <config name="exceptionHandler" value="com.ai.ipu.show.core.handler.IpuExceptionHandler"/>
26 30
    <!-- 自定义Session管理器 -->

+ 4 - 1
ipu-show-server/src/main/resources/server-data.xml

@ -5,7 +5,6 @@
5 5
    <!-- 模拟发送验证码 -->
6 6
    <action name="LoginBean.sendVerificationCode" class="com.ai.ipu.show.bean.LoginBean" method="sendVerificationCode" verify="false"></action>
7 7
8
    as>
9 8
    <!-- 上传下载 -->
10 9
    <action name="UploadDownloadBean.download" 	class="com.ai.ipu.show.bean.UploadDownloadBean" method="download" verify="false"></action>
11 10
    <action name="UploadDownloadBean.upload" 	class="com.ai.ipu.show.bean.UploadDownloadBean" method="upload" 	verify="false"></action>
@ -61,4 +60,8 @@
61 60
62 61
    <!-- 通用转发接口 -->
63 62
    <action name="CommonBean.interfaceHandler" class="com.ai.ipu.show.bean.CommonBean" method="interfaceHandler" verify="false"></action>
63
64
    <!-- 通用转发功能接口,参数已经过优化处理,支持加密和验签 -->
65
    <action name="CommonBean.commonInterfaceHandler" class="com.ai.ipu.show.bean.CommonBean" method="commonInterfaceHandler" verify="false"></action>
66
64 67
</datas>

android-share - Nuosi Git Service

ipu的trunk版的android工程和服务端工程。

leijie 3b751fd7a7 迁出ipu-mobile-ui,ipu-plugin-basic工程;迁入keep-live,show-client,show-server,ipu-sdk-demo,ipu-push-test,super-client工程; 3 年之前
..
src 3b751fd7a7 迁出ipu-mobile-ui,ipu-plugin-basic工程;迁入keep-live,show-client,show-server,ipu-sdk-demo,ipu-push-test,super-client工程; 3 年之前
.gitignore 3b751fd7a7 迁出ipu-mobile-ui,ipu-plugin-basic工程;迁入keep-live,show-client,show-server,ipu-sdk-demo,ipu-push-test,super-client工程; 3 年之前
build.gradle 3b751fd7a7 迁出ipu-mobile-ui,ipu-plugin-basic工程;迁入keep-live,show-client,show-server,ipu-sdk-demo,ipu-push-test,super-client工程; 3 年之前