liujie
8 天以前 c1d4849a2cc28cc50c5405f2382a5e4bf008b891
MessagePushTravel/src/main/java/com/sinata/push/controller/NettyController.java
@@ -3,10 +3,12 @@
import com.alibaba.fastjson.JSON;
import com.sinata.push.util.ResultUtil;
import com.sinata.push.util.SpringUtil;
import com.sinata.push.util.applets.NettyWebSocketController;
import com.sinata.push.util.echo.NettyChannelMap;
import com.sinata.push.util.echo.NettyServerController;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -15,6 +17,7 @@
@RestController
@RequestMapping("/netty")
public class NettyController {
    /**
@@ -24,16 +27,17 @@
     */
    @ResponseBody
    @PostMapping("/sendMsgToClient")
    public String sendMsgToClient(Integer id, Integer type, String msg){
    public String sendMsgToClient(Integer id, Integer type, String msg,String bussinessType){
        System.out.println("推送参数:" + id + "---" + type + "---" + msg);
        if(type == 1){//用户端
            ChannelHandlerContext channel = NettyChannelMap.getData("Applets" + id);//小程序
            ChannelHandlerContext channel = NettyChannelMap.getData(bussinessType+":Applets" + id);//小程序
            if(null != channel){
                NettyWebSocketController.sendMsgToClient(channel, msg);
                return JSON.toJSONString(ResultUtil.success());
            }
            channel = NettyChannelMap.getData("USER" + id);
            channel = NettyChannelMap.getData(bussinessType+":USER" + id);
            if(null != channel){
                NettyServerController.sendMsgToClient(channel, msg);
               NettyServerController.sendMsgToClient(channel, msg);
                return JSON.toJSONString(ResultUtil.success());
            }
            return JSON.toJSONString(ResultUtil.error("推送失败-----用户id=" + id));
@@ -41,7 +45,8 @@
        }
        if(type == 2){//司机端
            ChannelHandlerContext channel = NettyChannelMap.getData("DRIVER" + id);
            System.out.println("长链接实例:" + JSON.toJSONString(NettyChannelMap.map));
            ChannelHandlerContext channel = NettyChannelMap.getData(bussinessType+":DRIVER" + id);
            if(null != channel){
                NettyServerController.sendMsgToClient(channel, msg);
                return JSON.toJSONString(ResultUtil.success());