@@ -8,6 +8,7 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload; | |||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
import org.apache.http.Header; | import org.apache.http.Header; | ||||
import org.apache.http.HttpEntity; | import org.apache.http.HttpEntity; | ||||
import org.apache.http.HttpHeaders; | |||||
import org.apache.http.auth.AuthScope; | import org.apache.http.auth.AuthScope; | ||||
import org.apache.http.auth.UsernamePasswordCredentials; | import org.apache.http.auth.UsernamePasswordCredentials; | ||||
import org.apache.http.client.CredentialsProvider; | import org.apache.http.client.CredentialsProvider; | ||||
@@ -21,6 +22,7 @@ import org.apache.http.impl.client.CloseableHttpClient; | |||||
import org.apache.http.impl.client.HttpClients; | import org.apache.http.impl.client.HttpClients; | ||||
import org.apache.http.message.BasicHeader; | import org.apache.http.message.BasicHeader; | ||||
import org.apache.http.util.EntityUtils; | import org.apache.http.util.EntityUtils; | ||||
import org.apache.logging.log4j.util.Base64Util; | |||||
import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
@@ -30,7 +32,8 @@ import org.springframework.web.bind.annotation.RequestMapping; | |||||
import org.springframework.web.bind.annotation.RequestMethod; | import org.springframework.web.bind.annotation.RequestMethod; | ||||
import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
import com.aliyun.openservices.shade.com.alibaba.fastjson.JSONObject; | |||||
import com.alibaba.fastjson.JSON; | |||||
import com.alibaba.fastjson.JSONObject; | |||||
import com.iformall.annotation.AuthIgnore; | import com.iformall.annotation.AuthIgnore; | ||||
import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
import com.iformall.haikang.HKHttpClientInstanceFactory; | import com.iformall.haikang.HKHttpClientInstanceFactory; | ||||
@@ -48,7 +51,9 @@ import java.io.IOException; | |||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.io.InputStreamReader; | import java.io.InputStreamReader; | ||||
import java.nio.charset.StandardCharsets; | import java.nio.charset.StandardCharsets; | ||||
import java.util.HashMap; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | |||||
import java.util.UUID; | import java.util.UUID; | ||||
/** | /** | ||||
@@ -112,6 +117,8 @@ public class HaiKangController { | |||||
Integer peopleNum = rtd.getInteger("peopleNum"); | Integer peopleNum = rtd.getInteger("peopleNum"); | ||||
if (null != peopleNum) { | if (null != peopleNum) { | ||||
peopleNumberFactory.setPeopleNumber(ip, peopleNum); | peopleNumberFactory.setPeopleNumber(ip, peopleNum); | ||||
//Integer peopleNumber = peopleNumberFactory.getPeopleNumber(); | |||||
//todengxiang(peopleNumber); | |||||
}else { | }else { | ||||
logger.info("unValid response:"+baowen); | logger.info("unValid response:"+baowen); | ||||
} | } | ||||
@@ -158,6 +165,76 @@ public class HaiKangController { | |||||
} | } | ||||
} | } | ||||
// @AuthIgnore | |||||
// @GetMapping("/todengdegntest") | |||||
// public ResultData todengdegntest() { | |||||
// todengxiang(99); | |||||
// return new ResultData(); | |||||
// } | |||||
// | |||||
// private void todengxiang(Integer peopleNum) { | |||||
// todengxiangPost("119.23.61.190", "5006", null, null, "723900001916", peopleNum); | |||||
// } | |||||
// | |||||
// /** | |||||
// * 灯箱显示 | |||||
// * @param request | |||||
// * @param response | |||||
// * @throws ServletException | |||||
// * @throws IOException | |||||
// */ | |||||
// private void todengxiangPost(String ip,String port,String appkey,String appSecret,String sn,Integer peopleNum) { | |||||
// if (null == peopleNum) { | |||||
// peopleNum = 0; | |||||
// } | |||||
// CloseableHttpClient httpClient = httpFactory.getIpHttpClient(ip, null, null); | |||||
// HttpPost httpPost = new HttpPost("http://"+ip+":"+port+"/api/v1/device/cmd"); | |||||
// httpPost.setHeader(HttpHeaders.AUTHORIZATION,"Basic "+Base64Util.encode(appkey+":"+appSecret)); | |||||
// httpPost.addHeader("Content-Type", "application/json"); | |||||
// Map param = new HashMap(); | |||||
// //平台上设备 IMEI 或者设备序列号, 多个设备用逗号分隔 | |||||
// param.put("cmd_did", sn); | |||||
// //读取命令 , ‘W’ 写入命令 | |||||
// param.put("cmd_rw", "W"); | |||||
// //下发命令内容,json 字符串,命令内容可能不一样 | |||||
// Map content = new HashMap(); | |||||
// //操作, 下发 | |||||
// content.put("op", "set_dp"); | |||||
// //数据点名称 | |||||
// content.put("name", "hum"); | |||||
// content.put("value", peopleNum); | |||||
// param.put("cmd_content", JSON.toJSONString(content)); | |||||
// //描述信息 | |||||
// param.put("cmd_desc", "区域实时人数写入"); | |||||
// | |||||
// StringEntity entity = new StringEntity(JSON.toJSONString(param), StandardCharsets.UTF_8); | |||||
// httpPost.setEntity(entity); | |||||
// CloseableHttpResponse response = null; | |||||
// try { | |||||
// // 执行请求 | |||||
// response = httpClient.execute(httpPost); | |||||
// String ret = EntityUtils.toString(response.getEntity()); | |||||
// logger.debug("todengxiang response:"+ret); | |||||
// } catch (Exception e) { | |||||
// e.printStackTrace(); | |||||
// } finally { | |||||
// if (null != response) { | |||||
// try { | |||||
// response.close(); | |||||
// } catch (IOException e) { | |||||
// logger.error("todengxiang error.",e); | |||||
// } | |||||
// } | |||||
// try { | |||||
// httpClient.close(); | |||||
// } catch (IOException e) { | |||||
// logger.error("todengxiang error.",e); | |||||
// } | |||||
// | |||||
// } | |||||
// } | |||||
/** | /** | ||||
* 1. 获取设备系统能力集GET /ISAPI/System/capabilities; | * 1. 获取设备系统能力集GET /ISAPI/System/capabilities; | ||||
2. 判断是否支持事件订阅isSupportSubscribeEvent存在且为true; | 2. 判断是否支持事件订阅isSupportSubscribeEvent存在且为true; | ||||
@@ -157,6 +157,10 @@ video: | |||||
maxPoolSize: 20 | maxPoolSize: 20 | ||||
queueCapacity: 1000 | queueCapacity: 1000 | ||||
namePrefix: aliyun-video-upload | namePrefix: aliyun-video-upload | ||||
tcp: | |||||
server: | |||||
port: 9010 | |||||
jasypt: | jasypt: | ||||
encryptor: | encryptor: | ||||
@@ -54,15 +54,6 @@ spring: | |||||
filehost: homec | filehost: homec | ||||
filedomain: https://yuanqizhijia.oss-accelerate.aliyuncs.com | filedomain: https://yuanqizhijia.oss-accelerate.aliyuncs.com | ||||
haikang: | |||||
netsdk: | |||||
libdir: C:\project\bjAirport\bjairService | |||||
deviceIp: 192.168.2.200 | |||||
loginUser: admin | |||||
password: wushikeji001 | |||||
listenIp: 192.168.2.103 | |||||
listenPort: 1500 | |||||
mail: | mail: | ||||
host: smtp.exmail.qq.com | host: smtp.exmail.qq.com | ||||
@@ -137,6 +128,10 @@ video: | |||||
maxPoolSize: 20 | maxPoolSize: 20 | ||||
queueCapacity: 1000 | queueCapacity: 1000 | ||||
namePrefix: aliyun-video-upload | namePrefix: aliyun-video-upload | ||||
tcp: | |||||
server: | |||||
port: 9010 | |||||
fm: | fm: | ||||
exception: false | exception: false | ||||
@@ -3,6 +3,7 @@ package com.iformall.haikang; | |||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.concurrent.ConcurrentHashMap; | import java.util.concurrent.ConcurrentHashMap; | ||||
import org.apache.commons.lang3.StringUtils; | |||||
import org.apache.http.auth.AuthScope; | import org.apache.http.auth.AuthScope; | ||||
import org.apache.http.auth.UsernamePasswordCredentials; | import org.apache.http.auth.UsernamePasswordCredentials; | ||||
import org.apache.http.client.CredentialsProvider; | import org.apache.http.client.CredentialsProvider; | ||||
@@ -35,16 +36,23 @@ public class HKHttpClientInstanceFactory { | |||||
} | } | ||||
private CloseableHttpClient generateHttpClient(String ip,String name,String password) { | private CloseableHttpClient generateHttpClient(String ip,String name,String password) { | ||||
CredentialsProvider credsProvider = new BasicCredentialsProvider(); | |||||
credsProvider.setCredentials( | |||||
new AuthScope(ip, AuthScope.ANY_PORT), | |||||
new UsernamePasswordCredentials(name, password)); | |||||
// 创建一个使用认证凭据的CloseableHttpClient | |||||
CloseableHttpClient httpClient = HttpClients.custom() | |||||
.setDefaultCredentialsProvider(credsProvider) | |||||
.build(); | |||||
return httpClient; | |||||
if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(password)) { | |||||
CredentialsProvider credsProvider = new BasicCredentialsProvider(); | |||||
credsProvider.setCredentials( | |||||
new AuthScope(ip, AuthScope.ANY_PORT), | |||||
new UsernamePasswordCredentials(name, password)); | |||||
// 创建一个使用认证凭据的CloseableHttpClient | |||||
CloseableHttpClient httpClient = HttpClients.custom() | |||||
.setDefaultCredentialsProvider(credsProvider) | |||||
.build(); | |||||
return httpClient; | |||||
}else { | |||||
CloseableHttpClient httpClient = HttpClients.custom() | |||||
.build(); | |||||
return httpClient; | |||||
} | |||||
} | } | ||||
} | } |
@@ -0,0 +1,60 @@ | |||||
package com.iformall.haikang; | |||||
import java.io.BufferedReader; | |||||
import java.io.IOException; | |||||
import java.io.InputStreamReader; | |||||
import java.io.PrintWriter; | |||||
import java.net.Socket; | |||||
import javax.annotation.PostConstruct; | |||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.springframework.beans.factory.annotation.Value; | |||||
import org.springframework.stereotype.Component; | |||||
@Component | |||||
public class TcpClient { | |||||
private final Logger log = LoggerFactory.getLogger(this.getClass()); | |||||
// @Value("${tcp.server.host}") | |||||
// private String host; | |||||
// | |||||
// @Value("${tcp.server.port}") | |||||
// private int port; | |||||
// | |||||
// private Socket socket; | |||||
// private PrintWriter out; | |||||
// private BufferedReader in; | |||||
// | |||||
// @PostConstruct | |||||
// public void connect() { | |||||
// try { | |||||
// socket = new Socket(host, port); | |||||
// out = new PrintWriter(socket.getOutputStream(), true); | |||||
// in = new BufferedReader(new InputStreamReader(socket.getInputStream())); | |||||
// log.info("Connected to TCP server at {}:{}", host, port); | |||||
// } catch (IOException e) { | |||||
// log.error("Connection failed: {}", e.getMessage()); | |||||
// } | |||||
// } | |||||
// | |||||
// public String sendMessage(String message) { | |||||
// try { | |||||
// out.println(message); | |||||
// return in.readLine(); | |||||
// } catch (IOException e) { | |||||
// log.error("Failed to send message: {}", e.getMessage()); | |||||
// return null; | |||||
// } | |||||
// } | |||||
// | |||||
// public void disconnect() { | |||||
// try { | |||||
// if (socket != null) socket.close(); | |||||
// } catch (IOException e) { | |||||
// log.error("Failed to disconnect: {}", e.getMessage()); | |||||
// } | |||||
// } | |||||
} |
@@ -0,0 +1,145 @@ | |||||
package com.iformall.haikang; | |||||
import java.io.BufferedReader; | |||||
import java.io.IOException; | |||||
import java.io.InputStreamReader; | |||||
import java.io.PrintWriter; | |||||
import java.net.ServerSocket; | |||||
import java.net.Socket; | |||||
import java.util.HashMap; | |||||
import java.util.Map; | |||||
import javax.annotation.PostConstruct; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.beans.factory.annotation.Value; | |||||
import org.springframework.stereotype.Component; | |||||
import com.alibaba.fastjson.JSON; | |||||
import com.alibaba.fastjson.JSONArray; | |||||
import com.alibaba.fastjson.JSONObject; | |||||
@Component | |||||
public class TcpServer { | |||||
private final Logger log = LoggerFactory.getLogger(this.getClass()); | |||||
@Value("${tcp.server.port}") // Configure port in application.properties | |||||
private int port; | |||||
@Autowired | |||||
HKPeopleNumberFactory peopleNumberFactory; | |||||
@PostConstruct | |||||
public void start() { | |||||
new Thread(() -> { | |||||
try (ServerSocket serverSocket = new ServerSocket(port)) { | |||||
log.info("TCP Server started on port {}", port); | |||||
while (true) { | |||||
Socket clientSocket = serverSocket.accept(); | |||||
log.info("New client connected: {}", clientSocket.getInetAddress()); | |||||
// Handle client in a new thread | |||||
new Thread(() -> handleClient(clientSocket)).start(); | |||||
} | |||||
} catch (IOException e) { | |||||
log.error("TCP Server error: {}", e.getMessage()); | |||||
} | |||||
}).start(); | |||||
} | |||||
private void handleClient(Socket clientSocket) { | |||||
try ( | |||||
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); | |||||
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true) | |||||
) { | |||||
String message; | |||||
while ((message = in.readLine()) != null) { | |||||
log.info("Received: {}", message); | |||||
// | |||||
handleMessage(out, message); | |||||
// Echo back to client | |||||
//out.println("Server: " + message); | |||||
} | |||||
} catch (IOException e) { | |||||
log.error("Client connection error: {}", e.getMessage()); | |||||
} finally { | |||||
try { | |||||
clientSocket.close(); | |||||
} catch (IOException e) { | |||||
log.error("Failed to close socket: {}", e.getMessage()); | |||||
} | |||||
} | |||||
} | |||||
//编号2代表需要等待时长,编号3代表当前排队人数,编号4代表当前场内出租车,编号5代表在途出租车 | |||||
private static final int[] types = new int[] {2,3,4,5}; | |||||
private void handleMessage(PrintWriter out,String message) { | |||||
if (StringUtils.isBlank(message)) { | |||||
return; | |||||
} | |||||
JSONObject mo = JSON.parseObject(message); | |||||
if (null == mo) { | |||||
return; | |||||
} | |||||
String func = mo.getString("func"); | |||||
//心跳 | |||||
if ("KeepOnline".equals(func)) { | |||||
String dest = mo.getString("dest"); | |||||
String source = mo.getString("source"); | |||||
mo.put("dest", source); | |||||
mo.put("source", dest); | |||||
mo.put("func", "AckKeepOnline"); | |||||
JSONArray datas = new JSONArray(); | |||||
Map dm = new HashMap(); | |||||
dm.put("node", "OK"); | |||||
datas.add(dm); | |||||
mo.put("data", datas); | |||||
out.println(JSON.toJSONString(mo)); | |||||
//给灯箱发送 | |||||
for (int i = 0 ; i < types.length ; i++) { | |||||
JSONObject dxobj = new JSONObject(); | |||||
dxobj.put("dest", source); | |||||
dxobj.put("source", dest); | |||||
dxobj.put("func", "ControlData"); | |||||
JSONArray datas1 = new JSONArray(); | |||||
Map dm1 = new HashMap(); | |||||
dm1.put("node", generateNode(types[i])); | |||||
datas1.add(dm1); | |||||
dxobj.put("data", datas); | |||||
out.println(JSON.toJSONString(dxobj)); | |||||
} | |||||
} | |||||
} | |||||
//编号2代表需要等待时长,编号3代表当前排队人数,编号4代表当前场内出租车,编号5代表在途出租车 | |||||
private String generateNode(int type) { | |||||
StringBuffer sb = new StringBuffer("0-5-").append(type).append("-"); | |||||
int value = 0; | |||||
switch (type) { | |||||
case 2: | |||||
value = 1;//查询等待时长 | |||||
break; | |||||
case 3: | |||||
value = peopleNumberFactory.getPeopleNumber();;//查询当前排队人数 | |||||
break; | |||||
case 4: | |||||
value = 1;//查询场内出租车 | |||||
break; | |||||
case 5: | |||||
value = 1;//查询在途出租车 | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
sb.append(value).append("-0-1-0"); | |||||
return sb.toString(); | |||||
} | |||||
} |