|
|
@@ -5,6 +5,7 @@ import com.ydtech.config.SpringContextUtils;
|
|
|
import com.ydtech.modules.admin.constants.SystemType;
|
|
|
import com.ydtech.modules.admin.model.SysUser;
|
|
|
import com.ydtech.modules.admin.model.dto.IpInfoDto;
|
|
|
+import com.ydtech.modules.admin.model.dto.LocationResponse;
|
|
|
import com.ydtech.modules.admin.model.po.SysPcAddress;
|
|
|
import com.ydtech.modules.admin.service.SysPcAddressService;
|
|
|
import com.ydtech.modules.admin.service.SysUserService;
|
|
|
@@ -14,6 +15,7 @@ import org.springframework.stereotype.Component;
|
|
|
import javax.websocket.*;
|
|
|
import javax.websocket.server.PathParam;
|
|
|
import javax.websocket.server.ServerEndpoint;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
@@ -27,6 +29,10 @@ public class PCSocketServer {
|
|
|
|
|
|
private Session session;
|
|
|
|
|
|
+ public final static String URL = "https://api.map.baidu.com/location/ip?";
|
|
|
+
|
|
|
+ public final static String AK = "UuGafLbAJs9kYJsRg2cxCLwAscGZg1Jj";
|
|
|
+
|
|
|
private static Map<String, Session> sessionClientMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
/**静态变量,用来记录当前在线连接数*/
|
|
|
@@ -60,15 +66,16 @@ public class PCSocketServer {
|
|
|
public void onMessage(String message, Session session) {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(message);
|
|
|
String userId = jsonObject.getString("userId");
|
|
|
- String longitude = jsonObject.getString("lng");
|
|
|
- String latitude = jsonObject.getString("lat");
|
|
|
- String province = jsonObject.getString("prov");
|
|
|
- String city = jsonObject.getString("city");
|
|
|
- String district = jsonObject.getString("district");
|
|
|
+// String longitude = jsonObject.getString("lng");
|
|
|
+// String latitude = jsonObject.getString("lat");
|
|
|
+// String province = jsonObject.getString("prov");
|
|
|
+// String city = jsonObject.getString("city");
|
|
|
+// String district = jsonObject.getString("district");
|
|
|
String ip = jsonObject.getString("ip");
|
|
|
String systemType = jsonObject.getString("systemType");
|
|
|
- saveLocationData(userId, latitude, longitude,province,city,district,ip,systemType);
|
|
|
+ saveLocationData(userId,ip,systemType);
|
|
|
log.info("服务端收到PC用户消息:{} ,主体:{}", message, userId);
|
|
|
+
|
|
|
sendMessage("服务端已收到PC用户信息:" +message);
|
|
|
}
|
|
|
|
|
|
@@ -107,13 +114,28 @@ public class PCSocketServer {
|
|
|
this.session.getAsyncRemote().sendText(message);
|
|
|
}
|
|
|
|
|
|
- public void saveLocationData(String userId, String latitude, String longitude,
|
|
|
- String province,String city,String district,
|
|
|
+ public void saveLocationData(String userId,
|
|
|
String ip,String systemType) {
|
|
|
SysPcAddressService sysPcAddressService = SpringContextUtils.getBean(SysPcAddressService.class);
|
|
|
SysUserService sysUserService = SpringContextUtils.getBean(SysUserService.class);
|
|
|
if (SystemType.ST_1.getCode().equals(systemType)) {
|
|
|
try {
|
|
|
+ SearchHttpAK searchHttpAK = new SearchHttpAK();
|
|
|
+
|
|
|
+ Map params = new LinkedHashMap<String, String>();
|
|
|
+ params.put("ip", ip);
|
|
|
+ params.put("coor", "bd09ll");
|
|
|
+ params.put("ak", AK);
|
|
|
+
|
|
|
+ LocationResponse locationResponse = searchHttpAK.requestGetAK(URL, params);
|
|
|
+ String province = locationResponse.getContent().getAddressDetail().getProvince();
|
|
|
+ String city = locationResponse.getContent().getAddressDetail().getCity();
|
|
|
+ String district = locationResponse.getContent().getAddressDetail().getDistrict();
|
|
|
+
|
|
|
+ String longitude = locationResponse.getContent().getPoint().getX();
|
|
|
+ String latitude = locationResponse.getContent().getPoint().getY();
|
|
|
+
|
|
|
+
|
|
|
IpInfoDto ipInfoDto = new IpInfoDto();
|
|
|
ipInfoDto.setIp(ip);
|
|
|
ipInfoDto.setLng(longitude);
|
|
|
@@ -129,4 +151,10 @@ public class PCSocketServer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|