基于sa-admin后台,开发的后台客服
打开需要用到的springboot项目(没有创建springboot项目)
打开pom文件引用<!--websocket--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> <version>2.0.5.RELEASE</version> </dependency> <!--Alijson插件--> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.7</version> </dependency> <!-- redis java客户端jar包 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> </dependency>
在配置文件里配置redis(已配置不需要配置)
spring: # redis配置 redis: # Redis数据库索引(默认为0) database: 0 # Redis服务器地址 host: 127.0.0.1 # Redis服务器连接端口 port: 6379 # Redis服务器连接密码(默认为空) password: 123456 lettuce: pool: # 连接池最大连接数 max-active: 200 # 连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # 连接池中的最大空闲连接 max-idle: 10 # 连接池中的最小空闲连接 min-idle: 0 # 连接超时时间(毫秒) timeout: 5000ms
把java文件下的websocket放到项目的启动类同级文件下修改文件引用即可。
启动
把文件分别放到相对应的文件夹加下
在index.html 文件 引用<script src="static/im/sa_IM.js"></script>
在 static/im/sa_IM.js 修改连接地址
window.sa_IM = window.sa_IM || parent.sa_IM || top.sa_IM;
sa_IM.login("xxx");(<xxx> 为后台id)
来连接后台websocket 在menu-list.js 里添加页面
{ id: '10', // id可能根据个人需求进行修改 name: '客服聊天', icon: 'el-icon-document-copy', info: '在后台与用户聊天', url:'sa-html/IM/im.html' },
运行index.html即可
连接: ws://ip:端口/websocket/{uid}/{type}
{"type":"sendText","fId":"发给人id","text":"发送内容","genre":"text/文本,img/图片,mp3/音频"}
{"type":"sendText","text":"发送内容1","genre":"text"}
{type: "joinChat", fId: "用户id", pageNo: 1, pageSize: 10} pageNo从1开始
{"type":"joinChat","pageNo":"当前页","pageSize":"页大小"}
客服加载聊天列表
< 695C a id="user-content-客服加载聊天列表" class="anchor" aria-label="Permalink: 客服加载聊天列表" href="#客服加载聊天列表">{type: "chatList"}
unread 为未读消息数量
{type: "unread"}
QQ交流群:782974737 点击加入