package cn.mb.cloud.gateway.controller;
|
|
|
import cn.mb.cloud.gateway.auth.ResultUtil;
|
import cn.mb.cloud.gateway.util.applets.NettyWebSocketController;
|
import cn.mb.cloud.gateway.util.echo.NettyChannelMap;
|
import cn.mb.cloud.gateway.util.echo.NettyServerController;
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import io.netty.channel.ChannelHandlerContext;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
@RestController
|
@RequestMapping("/netty")
|
public class NettyController {
|
|
|
/** 3.4.5.6
|
* 向客户端推送消息
|
* @param id
|
* @param msg
|
*/
|
@ResponseBody
|
@GetMapping("/sendMsgToClient")
|
public String sendMsgToClient(String id, Integer type, String msg){
|
System.out.println(id+"|"+type+"|"+msg+"!!!!!!!!");
|
if(true){//用户端
|
String[] split = id.split("_");
|
ChannelHandlerContext channel = NettyChannelMap.getData("USER" + split[0]);
|
if(null != channel){
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("code", 200);
|
jsonObject.put("msg", "SUCCESS");
|
jsonObject.put("method", "CLASS");
|
Map<String, Object> map = new HashMap<>();
|
jsonObject.put("data", map);
|
NettyServerController.sendMsgToClient(channel, jsonObject.toJSONString());
|
return JSON.toJSONString(ResultUtil.success());
|
}
|
return JSON.toJSONString(ResultUtil.error("推送失败-----用户id=" + id));
|
|
}
|
return JSON.toJSONString(ResultUtil.error("推送失败"));
|
}
|
}
|