|
@@ -2,8 +2,7 @@ package com.fdkk.sxz.webApi.socket;
|
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
-import com.fdkk.sxz.util.RedisUtil;
|
|
|
-import com.fdkk.sxz.webApi.service.IComponentModelUploadService;
|
|
|
+import com.fdkk.sxz.util.OkHttpUtils;
|
|
|
import com.fdkk.sxz.webApi.socket.bizRunable.ParamContext;
|
|
|
import com.fdkk.sxz.webApi.socket.service.ComponentBizImpl;
|
|
|
import com.fdkk.sxz.webApi.socket.service.ComponentCreateImgBizImpl;
|
|
@@ -12,50 +11,55 @@ import com.fdkk.sxz.webApi.socket.service.ModelUploadBizImpl;
|
|
|
import io.netty.handler.codec.http.HttpHeaders;
|
|
|
import io.netty.handler.timeout.IdleStateEvent;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.yeauty.annotation.*;
|
|
|
import org.yeauty.pojo.Session;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
/**
|
|
|
* @author XieWj
|
|
|
*/
|
|
|
-@ServerEndpoint(path = "/wss/action/", port = "${ws.port}")
|
|
|
+@ServerEndpoint(path = "/wss/action/{token}", port = "${ws.port}", corsOrigins = "*", corsAllowCredentials = "true")
|
|
|
@Slf4j
|
|
|
public class actionSocket {
|
|
|
|
|
|
@Value("${main.url}")
|
|
|
private String mainUrl;
|
|
|
|
|
|
-
|
|
|
private static Map<String, Thread> socketSessionBizMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
- @Autowired
|
|
|
- private RedisUtil redisUtil;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IComponentModelUploadService componentModelUploadService;
|
|
|
-
|
|
|
-
|
|
|
- Thread thread = null;
|
|
|
-
|
|
|
- static boolean isStop = true;
|
|
|
-
|
|
|
- private String region = "customWSS";
|
|
|
-
|
|
|
-
|
|
|
@BeforeHandshake
|
|
|
- public void handshake(Session session, HttpHeaders headers, @PathVariable Map<String, String> pathMap) {
|
|
|
- String token = pathMap.get("token");
|
|
|
+ public void handshake(Session session, HttpHeaders headers, @PathVariable Map<String, String> pathMap, @PathVariable String token) throws InterruptedException {
|
|
|
+ JSONObject resData = JSONUtil.createObj();
|
|
|
+ resData.set("code", 0);
|
|
|
+ resData.set("msg", "验证成功");
|
|
|
session.setSubprotocols("stomp");
|
|
|
-// JSONObject req=OkHttpUtils.httpPostFormReturnJson(mainUrl + "api/scene/isLogin", paramsMap, postHeaders);
|
|
|
- if (1 == 0) {
|
|
|
- actionSocket.log.info("Authentication failed!");
|
|
|
- session.close();
|
|
|
+ String url = mainUrl + "api/sso/user/checkToken";
|
|
|
+ actionSocket.log.info("验证token的url:{}", url);
|
|
|
+ Map<String, String> headersPrm = new HashMap<>();
|
|
|
+ headersPrm.put("token", token);
|
|
|
+ com.alibaba.fastjson.JSONObject res = OkHttpUtils.httpPostJson(url, "", headersPrm);
|
|
|
+ if (!token.equals("xx-xx-xx-token")) {
|
|
|
+ if (null != res) {
|
|
|
+ actionSocket.log.info("登录态校验接口返回:{}", res.toJSONString());
|
|
|
+ int code = -10;
|
|
|
+ if (res.containsKey("code")) {
|
|
|
+ code = (int) res.get("code");
|
|
|
+ if (code != 0) {
|
|
|
+ actionSocket.log.info("Authentication failed!");
|
|
|
+ session.close();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ actionSocket.log.info("Authentication failed!");
|
|
|
+ session.close();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ session.close();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|