| | |
| | | |
| | | 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; |
| | |
| | | @RestController |
| | | @RequestMapping("/netty") |
| | | public class NettyController { |
| | | |
| | | @Autowired |
| | | private NettyServerController nettyServerController; |
| | | |
| | | @Autowired |
| | | private NettyWebSocketController nettyWebSocketController; |
| | | |
| | | |
| | | /** |
| | |
| | | if(type == 1){//用户端 |
| | | ChannelHandlerContext channel = NettyChannelMap.getData("Applets" + id);//小程序 |
| | | if(null != channel){ |
| | | NettyWebSocketController.sendMsgToClient(channel, msg); |
| | | nettyWebSocketController.sendMsgToClient(channel, msg); |
| | | return JSON.toJSONString(ResultUtil.success()); |
| | | } |
| | | channel = NettyChannelMap.getData("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)); |
| | |
| | | if(type == 2){//司机端 |
| | | ChannelHandlerContext channel = NettyChannelMap.getData("DRIVER" + id); |
| | | if(null != channel){ |
| | | NettyServerController.sendMsgToClient(channel, msg); |
| | | nettyServerController.sendMsgToClient(channel, msg); |
| | | return JSON.toJSONString(ResultUtil.success()); |
| | | } |
| | | return JSON.toJSONString(ResultUtil.error("推送失败-----司机id=" + id)); |