当前位置: 首页 > news >正文

做网站的后台开发需要会些什么有什么好的推广平台

做网站的后台开发需要会些什么,有什么好的推广平台,公司管理系统包括,做网站的工资高SpringBoot实现即时通讯 功能简述 好友管理群组管理聊天模式:私聊、群聊消息类型:系统消息、文本、语音、图片、视频会话列表、发送消息、接收消息 核心代码 package com.qiangesoft.im.core;import com.alibaba.fastjson2.JSONObject; import com.q…

SpringBoot实现即时通讯

功能简述

  • 好友管理
  • 群组管理
  • 聊天模式:私聊、群聊
  • 消息类型:系统消息、文本、语音、图片、视频
  • 会话列表、发送消息、接收消息

核心代码

package com.qiangesoft.im.core;import com.alibaba.fastjson2.JSONObject;
import com.qiangesoft.im.constant.ChatTypeEnum;
import com.qiangesoft.im.constant.ImMessageBodyTypeEnum;
import com.qiangesoft.im.service.IImGroupUserService;
import com.qiangesoft.im.util.SpringUtil;
import com.qiangesoft.im.pojo.dto.PingDTO;
import com.qiangesoft.im.pojo.vo.PongVO;
import com.qiangesoft.im.pojo.vo.ImMessageVO;
import com.qiangesoft.im.pojo.dto.ImMessageDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;/*** 聊天会话** @author qiangesoft* @date 2023-08-30*/
@Slf4j
@ServerEndpoint("/ws/im/{userId}")
@Component
public class ImWebSocketServer {/*** concurrent包的线程安全Set,用来存放每个客户端对应的WebSocket对象。*/private static final ConcurrentHashMap<Long, ImWebSocketServer> WEBSOCKET_MAP = new ConcurrentHashMap<>();/*** 与某个客户端的连接会话,需要通过它来给客户端发送数据*/private Session session;/*** 连接建立成功调用的方法:用map存客户端对应的WebSocket对象*/@OnOpenpublic void onOpen(Session session, @PathParam("userId") Long userId) {this.session = session;if (WEBSOCKET_MAP.containsKey(userId)) {WEBSOCKET_MAP.remove(userId);WEBSOCKET_MAP.put(userId, this);} else {WEBSOCKET_MAP.put(userId, this);}log.info("User [{}] connection opened=====>", userId);PongVO pongVO = new PongVO();pongVO.setType(ImMessageBodyTypeEnum.SUCCESS.getCode());pongVO.setContent("连接成功");pongVO.setTimestamp(System.currentTimeMillis());doSendMessage(JSONObject.toJSONString(pongVO));}/*** 收到客户端消息后调用的方法*/@OnMessagepublic void onMessage(Session session, @PathParam("userId") Long userId, String message) {log.info("User [{}] send a message, content is [{}]", userId, message);PingDTO pingDTO = null;try {pingDTO = JSONObject.parseObject(message, PingDTO.class);} catch (Exception e) {log.error("消息解析失败");e.printStackTrace();}if (pingDTO == null || !ImMessageBodyTypeEnum.PING.getCode().equals(pingDTO.getType())) {sendInValidMessage();return;}PongVO pongVO = new PongVO();pongVO.setType(ImMessageBodyTypeEnum.PONG.getCode());pongVO.setContent("已收到消息~");pongVO.setTimestamp(System.currentTimeMillis());doSendMessage(JSONObject.toJSONString(pongVO));}/*** 连接关闭调用的方法*/@OnClosepublic void onClose(Session session, @PathParam("userId") Long userId) {close(session, userId);log.info("User {} connection is closed<=====", userId);}/*** 报错** @param session* @param error*/@OnErrorpublic void onError(Session session, Throwable error) {error.printStackTrace();}/*** 指定的userId服务端向客户端发送消息*/public static void sendMessage(ImMessageDTO message) {String chatType = message.getChatType();if (ChatTypeEnum.GROUP.getCode().equals(chatType)) {sendGroupMessage(message);}if (ChatTypeEnum.PERSON.getCode().equals(chatType)) {sendPersonMessage(message);}}/*** 指定的userId服务端向客户端发送消息*/public static void offline(Long userId) {ImWebSocketServer webSocketServer = WEBSOCKET_MAP.get(userId);if (webSocketServer != null) {PongVO pongVO = new PongVO();pongVO.setType(ImMessageBodyTypeEnum.OFFLINE.getCode());pongVO.setContent("设备被挤下线");pongVO.setTimestamp(System.currentTimeMillis());webSocketServer.doSendMessage(JSONObject.toJSONString(pongVO));close(webSocketServer.session, userId);}}/*** 自定义关闭** @param session* @param userId*/public static void close(Session session, Long userId) {if (WEBSOCKET_MAP.containsKey(userId)) {try {session.close();} catch (IOException e) {e.printStackTrace();}WEBSOCKET_MAP.remove(userId);}}/*** 获取在线用户信息** @return*/public static Map<Long, ImWebSocketServer> getOnlineUser() {return WEBSOCKET_MAP;}/*** 发送无效消息*/private void sendInValidMessage() {PongVO pongVO = new PongVO();pongVO.setType(ImMessageBodyTypeEnum.FAIL.getCode());pongVO.setContent("无效消息");pongVO.setTimestamp(System.currentTimeMillis());doSendMessage(JSONObject.toJSONString(pongVO));}/*** 发送群组消息** @param message*/private static void sendGroupMessage(ImMessageDTO message) {Long receiverId = message.getReceiverId();IImGroupUserService groupUserService = SpringUtil.getBean(IImGroupUserService.class);List<Long> userIdList = groupUserService.listUserIdByGroupId(receiverId);MessageHandlerService messageHandlerService = SpringUtil.getBean(MessageHandlerService.class);ImMessageVO messageVO = messageHandlerService.buildVo(message);PongVO pongVO = new PongVO();pongVO.setType(ImMessageBodyTypeEnum.MESSAGE.getCode());pongVO.setContent(messageVO);pongVO.setTimestamp(System.currentTimeMillis());String messageStr = JSONObject.toJSONString(pongVO);for (Long userId : userIdList) {ImWebSocketServer webSocketServer = WEBSOCKET_MAP.get(userId);if (webSocketServer != null) {if (!userId.equals(message.getSenderId())) {webSocketServer.doSendMessage(messageStr);}}}}/*** 发送私聊消息** @param message*/private static void sendPersonMessage(ImMessageDTO message) {Long receiverId = message.getReceiverId();ImWebSocketServer webSocketServer = WEBSOCKET_MAP.get(receiverId);if (webSocketServer != null) {MessageHandlerService messageHandlerService = SpringUtil.getBean(MessageHandlerService.class);ImMessageVO messageVO = messageHandlerService.buildVo(message);PongVO pongVO = new PongVO();pongVO.setType(ImMessageBodyTypeEnum.MESSAGE.getCode());pongVO.setContent(messageVO);pongVO.setTimestamp(System.currentTimeMillis());webSocketServer.doSendMessage(JSONObject.toJSONString(pongVO));}}/*** 实现服务器推送到对应的客户端*/private void doSendMessage(String message) {try {this.session.getBasicRemote().sendText(message);} catch (IOException e) {e.printStackTrace();}}
}
http://www.yidumall.com/news/92818.html

相关文章:

  • 做网站可以在哪儿接活英文谷歌seo
  • blog建设网站南昌seo排名外包
  • 网站建设与网络编辑课程心得夸克搜索引擎入口
  • 电商网站推广方法珠海优化seo
  • 手机网站设计制作公司国家优化防控措施
  • 哪个网站用div做的好长春网站制作企业
  • 国外html5模板网站化妆品推广软文
  • 手机如何创建公众号seo现在还有前景吗
  • 做配资网站多少钱google官方入口
  • 广告公司网站首页深圳百度总部
  • 深圳个性化建网站服务商seo薪酬水平
  • 昆明云南微网站制作专业网站seo推广
  • 做设计兼职的网站有哪些天津百度推广开户
  • 山西建设网站深圳网络品牌推广公司
  • 徐州专业建站公司手机网站排名优化软件
  • 武汉seo优化大全seo交流群
  • 商城网站建设需要it培训机构培训费用
  • 做课内教学网站网站入口百度
  • 做视频网站 许可证教育机构加盟
  • 咸阳做企业网站如何规划企业网络推广方案
  • 老外做汉字网站百度关键词优化是什么意思
  • 诗敏家具网站是谁做的seo对网站优化
  • 怎样用虚拟主机建网站企业邮箱账号
  • 上海工商信息查询官网网站优化搜索排名
  • wordpress b站播放dz论坛如何seo
  • 毕业设计做网站要求俄罗斯搜索引擎浏览器
  • 免费php模板网站建个网站费用多少
  • 电子商务网站开发项目广州网站建设
  • 太原网站制作案例app推广拉新工作可靠吗
  • 免费外贸网站模板瑞昌网络推广