下载资源后端资源详情
chatcode.zip
大小:23.4KB
价格:27积分
下载量:0
评分:
5.0
上传者:m0_59799878
更新日期:2025-09-22

微信小程序+springboot及时聊天(通讯)代码

资源文件列表(大概)

文件名
大小
chatcode/
-
chatcode/springboot/
-
chatcode/springboot/chat/
-
chatcode/springboot/chat/config/
-
chatcode/springboot/chat/config/WebSocketConfig.java
1.15KB
chatcode/springboot/chat/controller/
-
chatcode/springboot/chat/controller/ChatController.java
2.22KB
chatcode/springboot/chat/entry/
-
chatcode/springboot/chat/entry/ChatMessage.java
242B
chatcode/springboot/chat/mini/
-
chatcode/springboot/chat/mini/config/
-
chatcode/springboot/chat/mini/config/MiniWebSocketConfig.java
440B
chatcode/springboot/chat/mini/controller/
-
chatcode/springboot/chat/mini/controller/MiniWebSocketController.java
2.81KB
chatcode/springboot/chat/mini/mapper/
-
chatcode/springboot/chat/mini/mapper/SessionPool.java
5.79KB
chatcode/springboot/chat/mini/mapper/WebSocketEndPoint.java
2.84KB
chatcode/springboot/constans/
-
chatcode/springboot/constans/Constans.java
312B
chatcode/springboot/redis/
-
chatcode/springboot/redis/config/
-
chatcode/springboot/redis/config/RedisConfig.java
1.75KB
chatcode/springboot/redis/mapper/
-
chatcode/springboot/redis/mapper/RedisUtils.java
3.62KB
chatcode/springboot/redis/tool/
-
chatcode/springboot/redis/tool/SufferVariable.java
584B
chatcode/springboot/tool/
-
chatcode/springboot/tool/Result.java
1.04KB
chatcode/wx_mini_code/
-
chatcode/wx_mini_code/chat/
-
chatcode/wx_mini_code/chat/chat.js
10.19KB
chatcode/wx_mini_code/chat/chat.json
31B
chatcode/wx_mini_code/chat/chat.wxml
4.83KB
chatcode/wx_mini_code/chat/chat.wxss
7.41KB
chatcode/wx_mini_code/rpromise/
-
chatcode/wx_mini_code/rpromise/request.js
703B
chatcode/wx_mini_code/rpromise/uploadfile.js
787B
chatcode/wx_mini_code/tool/
-
chatcode/wx_mini_code/tool/form/
-
chatcode/wx_mini_code/tool/form/form.js
5.4KB

资源内容介绍

1.微信小程序ws通讯2.后端使用springboot的websocket
package com.example.mengchuangyuan.common.chat.mini.mapper;import com.alibaba.fastjson.JSON;import com.example.mengchuangyuan.common.redis.mapper.RedisUtils;import com.example.mengchuangyuan.common.redis.tool.SufferVariable;import com.example.mengchuangyuan.common.tool.DateYMDms;import lombok.extern.slf4j.Slf4j;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import org.springframework.stereotype.Controller;import javax.websocket.Session;import java.util.*;import java.util.concurrent.ConcurrentHashMap;@Component@Slf4jpublic class SessionPool { @Autowired private RedisUtils redisUtils; //key-value : userId - 会话(系统创建) public static Map<String, Session> sessions = new ConcurrentHashMap<>();//避免多线程问题 public void close(String sessionId) { //sessionId是在session中添加了一个标识,准确定位某条session for (String userId : SessionPool.sessions.keySet()) { Session session = SessionPool.sessions.get(userId); if (session.getId().equals(sessionId)) { sessions.remove(userId); break; } } } public void sendMessage(String userId, String message) { sessions.get(userId).getAsyncRemote().sendText(message); } //消息的群发,业务逻辑的群发 public void sendMessage(String message) {// redisUtils.cacheValue("chatMessage","String.valueOf(SufferVariable.messageMap)"); for (String sessionId : SessionPool.sessions.keySet()) { SessionPool.sessions.get(sessionId).getAsyncRemote().sendText(message); } } //点对点的消息推送 public void sendMessage(Map<String, Object> params) { log.info("消息内容:"+String.valueOf(params)); long mid = System.currentTimeMillis(); Map<String,Object> formUser = (Map<String, Object>) params.get("formUser"); Map<String,Object> toUser = (Map<String, Object>) params.get("toUser"); String userId = formUser.get("openid").toString(); String toUserId = toUser.get("openid").toString();// String msg = params.get("message").toString(); String type = params.get("type").toString(); String linkType = params.get("linkType").toString(); //获取用户session Session session = sessions.get(toUserId); Map<String,Object> keyMap; List<String> setOpenid; Map<String,Object> map; List<Object> list; String uid = userId+toUserId; params.put("mid",mid); if (SufferVariable.messageMap.get(userId+toUserId)==null&&SufferVariable.messageMap.get(toUserId+userId)==null){// messageMap.put(userId+toUserId,userId+toUserId); map = new HashMap<>(); list = new ArrayList<>(); map.put(linkType,list); SufferVariable.messageMap.put(uid,map);// list.add(params); }else { if (SufferVariable.messageMap.get(userId+toUserId)!=null){ uid = userId+toUserId; }else { uid = toUserId+userId; } map = (Map<String, Object>) SufferVariable.messageMap.get(uid); list = (List<Object>) map.get(linkType); } //获取历史记录 if (type.equalsIgnoreCase("history")){ if (sessions.get(userId) != null) { Map<String, Object> map2 = new HashMap<>();// map = (Map<String, Object>) SufferVariable.messageMap.get(uid); map2.put("type", "isHistory"); map2.put("message",list); sessions.get(userId).getAsyncRemote().sendText(JSON.toJSONString(map2)); } return; } String nowDate = DateYMDms.getUtilDate(); if (list.size()!=0) { Map<String, Object> lastMap = (Map<String, Object>) list.get(list.size() - 1); String date = DateYMDms.getYMDms(5, lastMap.get("nowDate").toString()); params.put("date", date); }else { params.put("date", nowDate); }// if (SufferVariable.openidKeys.get(linkType)==null){// keyMap = new HashMap<>();// }else {// keyMap = (Map<String, Object>) SufferVariable.openidKeys.get(linkType);// }// if (keyMap.get(userId)==null){// setOpenid = new ArrayList<>();// }else {// log.info(String.valueOf(SufferVariable.openidKeys));// setOpenid = (List<String>) keyMap.get(userId);// } if (SufferVariable.openidKeys.get(linkType) == null){ setOpenid = new ArrayList<>(); }else { setOpenid = (List<String>) SufferVariable.openidKeys.get(linkType); } setOpenid.add(uid); Set<String> set = new LinkedHashSet<>(setOpenid); setOpenid.clear(); setOpenid.addAll(set);// keyMap.put(userId,setOpenid); SufferVariable.openidKeys.put(linkType,setOpenid); params.put("nowDate",nowDate); list.add(params); map.put(linkType,list); SufferVariable.messageMap.put(uid,map); redisUtils.cacheValue("chatMessage",SufferVariable.messageMap); redisUtils.cacheValue("chatOpenidKeys",SufferVariable.openidKeys); if (session != null) { log.info(uid+":"+String.valueOf(SufferVariable.messageMap.get(uid))); session.getAsyncRemote().sendText(JSON.toJSONString(params)); }// log.info(String.valueOf(messageMap));// params.remove("formUserId"); //session不为空的情况下进行点对点推送 }}

用户评论 (0)

发表评论

captcha

相关资源

VXLAN手动隧道 集中式网关,不同子网互访

VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不同子网互访。VXLAN手动隧道 集中式网关,不

9.54KB10积分

地下偶像有声01.zip

地下偶像有声01.zip

10.14MB44积分

知识图谱作业代码,包含数据预处理与转换、模型训练、结果评估等

知识图谱作业代码,包含数据预处理与转换、模型训练、结果评估等

306.8KB47积分

免费下载Springboot驾校预约管理系统

系统概述:驾校预约管理系统是一套集学员管理、教练管理、课程预约、考试安排等功能于一体的信息化解决方案。系统采用Spring Boot框架进行后端开发,利用其自动配置、内嵌服务器等特性,确保了系统的高性能与快速响应。关键技术:Spring Boot:简化了传统Spring应用的配置,提供了丰富的自动配置选项。MyBatis Plus:增强了MyBatis的功能,简化了数据库操作。JWT:用于实现无状态、安全的认证机制。Vue.js:作为前端框架,提供了丰富的组件和高效的数据绑定,优化了用户界面的交互性。核心功能模块:学员管理:系统支持学员信息的录入、修改和查询,以及学员状态的跟踪。教练管理:教练信息管理,包括教练的排班和工作评价。课程预约:学员可通过系统预约练车时间,系统自动处理预约冲突。考试管理:管理学员的考试安排,记录考试成绩。报表统计:系统自动生成教练工作量、学员通过率等统计报表。安全性:系统采用JWT进行用户认证,确保了数据传输的安全性和用户操作的合法性。同时,系统提供了角色权限管理,确保不同角色的访问权限得到有效控制。

1.12MB47积分