整合營銷服務(wù)商

          電腦端+手機端+微信端=數(shù)據(jù)同步管理

          免費咨詢熱線:

          實在!基于Springboot和WebScoket,

          實在!基于Springboot和WebScoket,寫了一個在線聊天小程序

          于Springboot和WebScoket寫的一個在線聊天小程序

          (好幾天沒有寫東西了,也沒有去練手了,就看了看這個。。。)

          項目說明

          • 此項目為一個聊天的小demo,采用springboot+websocket+vue開發(fā)。
          • 其中有一個接口為添加好友接口,添加好友會判斷是否已經(jīng)是好友。
          • 聊天的時候:A給B發(fā)送消息如果B的聊天窗口不是A,則B處會提醒A發(fā)來一條消息。
          • 聊天內(nèi)容的輸入框采用layui的富文本編輯器,目前不支持回車發(fā)送內(nèi)容。
          • 聊天可以發(fā)送圖片,圖片默認(rèn)存儲在D:/chat/目錄下。
          • 點擊聊天內(nèi)容中的圖片會彈出預(yù)覽,這個預(yù)覽彈出此條消息中的所有圖片。
          • 在發(fā)送語音的時候,語音默認(rèn)發(fā)送給當(dāng)前聊天窗口的用戶,所以錄制語音的時候務(wù)必保證當(dāng)前聊天窗口有選擇的用戶。
          • 知道用戶的賬號可以添加好友,目前是如果賬號存在,可以直接添加成功

          老規(guī)矩,還是先看看小項目的目錄結(jié)構(gòu):

          一、先引入pom文件

          這里就只放了一點點代碼(代碼太長了)

          <dependency>
                      <groupId>commons-io</groupId>
                      <artifactId>commons-io</artifactId>
                      <version>2.4</version>
                  </dependency>
                  <dependency>
                      <groupId>org.projectlombok</groupId>
                      <artifactId>lombok</artifactId>
                  </dependency>
                  <dependency>
                      <groupId>net.sf.json-lib</groupId>
                      <artifactId>json-lib</artifactId>
                      <version>2.4</version>
                      <classifier>jdk15</classifier>
                  </dependency>
                  <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf -->
                  <dependency>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-starter-thymeleaf</artifactId>
                      <version>2.2.4.RELEASE</version>
                  </dependency>
                  <dependency>
                      <groupId>com.alibaba</groupId>
                      <artifactId>fastjson</artifactId>
                      <version>1.2.60</version>
                  </dependency>
                  <dependency>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-starter-test</artifactId>
                      <scope>test</scope>
                  </dependency>

          二、創(chuàng)建對應(yīng)的yml配置文件

          spring:
            profiles:
              active: prod
          spring:
            datasource:
              username: root
              password: root
              url: jdbc:mysql://localhost:3306/chat?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&serverTimezone=UTC
              driver-class-name: com.mysql.jdbc.Driver
              #指定數(shù)據(jù)源
              type: com.alibaba.druid.pool.DruidDataSource
          
              # 數(shù)據(jù)源其他配置
              initialSize: 5
              minIdle: 5
              maxActive: 20
              maxWait: 60000
              timeBetweenEvictionRunsMillis: 60000
              minEvictableIdleTimeMillis: 300000
              validationQuery: SELECT 1
              testWhileIdle: true
              testOnBorrow: false
              testOnReturn: false
              poolPreparedStatements: true
              #   配置監(jiān)控統(tǒng)計攔截的filters,去掉后監(jiān)控界面sql無法統(tǒng)計,'wall'用于防火墻
              filters: stat,log4j
              maxPoolPreparedStatementPerConnectionSize: 20
              useGlobalDataSourceStat: true
              connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
          
            thymeleaf:
              suffix: .html
              prefix:
                classpath: /templates/
              cache: false
          
            jackson: #返回的日期字段的格式
              date-format: yyyy-MM-dd HH:mm:ss
              time-zone: GMT+8
              serialization:
                write-dates-as-timestamps: false # true 使用時間戳顯示時間
            http:
              multipart:
                max-file-size: 1000Mb
                max-request-size: 1000Mb
          #配置文件式開發(fā)
          mybatis:
            #全局配置文件的位置
            config-location: classpath:mybatis/mybatis-config.xml
            #所有sql映射配置文件的位置
            mapper-locations: classpath:mybatis/mapper/**/*.xml
          
          server:
            session:
              timeout: 7200

          三、創(chuàng)建實體類

          這里就不再多說了,有Login,Userinfo,ChatMsg,ChatFriends

          四、創(chuàng)建對應(yīng)的mapper(即dao層)還有對應(yīng)的mapper映射文件

          (這里就舉出了一個,不再多說)

          public interface ChatFriendsMapper {
              //查詢所有的好友
              List<ChatFriends> LookUserAllFriends(String userid);
              //插入好友
              void InsertUserFriend(ChatFriends chatFriends);
              //判斷是否加好友
              Integer JustTwoUserIsFriend(ChatFriends chatFriends);
              //查詢用戶的信息
              Userinfo LkUserinfoByUserid(String userid);
          }
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
          <mapper namespace="com.chat.mapper.ChatFriendsMapper">
              <select id="LookUserAllFriends" resultType="com.chat.bean.ChatFriends" parameterType="java.lang.String">
                select userid,nickname,uimg from userinfo where userid in (select a.fuserid from chat_friends a where a.userid=#{userid})
              </select>
              <insert id="InsertUserFriend" parameterType="com.chat.bean.ChatFriends">
                  insert into chat_friends (userid, fuserid) value (#{userid},#{fuserid})
              </insert>
              <select id="JustTwoUserIsFriend" parameterType="com.chat.bean.ChatFriends" resultType="java.lang.Integer">
                  select id from chat_friends where userid=#{userid} and fuserid=#{fuserid}
              </select>
              <select id="LkUserinfoByUserid" parameterType="java.lang.String" resultType="com.chat.bean.Userinfo">
                  select * from userinfo where userid=#{userid}
              </select>
          </mapper>

          五、創(chuàng)建對應(yīng)的業(yè)務(wù)類(即service)

          (同樣的業(yè)務(wù)層這里也就指出一個)

          @Service
          public class ChatFriendsService {
              @Autowired
              ChatFriendsMapper chatFriendsMapper;
              public List<ChatFriends> LookUserAllFriends(String userid){
                  return chatFriendsMapper.LookUserAllFriends(userid);
              }
              public void InsertUserFriend(ChatFriends chatFriends){
                  chatFriendsMapper.InsertUserFriend(chatFriends);
              }
              public Integer JustTwoUserIsFriend(ChatFriends chatFriends){
                  return chatFriendsMapper.JustTwoUserIsFriend(chatFriends);
              }
              public Userinfo LkUserinfoByUserid(String userid){
                  return chatFriendsMapper.LkUserinfoByUserid(userid);
              }
          }
          

          六、創(chuàng)建對應(yīng)的控制器

          這里再說說項目的接口

          1. /chat/upimg 聊天圖片上傳接口
          2. /chat/lkuser 這個接口用來添加好友的時候:查詢用戶,如果用戶存在返回用戶信息,如果不存在返回不存在
          3. /chat/adduser/ 這個接口是添加好友接口,會判斷添加的好友是否是自己,如果添加的好友已經(jīng)存在則直接返回
          4. /chat/ct 跳轉(zhuǎn)到聊天界面
          5. /chat/lkfriends 查詢用戶的好友
          6. /chat/lkuschatmsg/ 這個接口是查詢兩個用戶之間的聊天信息的接口,傳入用戶的userid,查詢當(dāng)前登錄用戶和該用戶的聊天記錄。
          7. /chat/audio 這個接口是Ajax上傳web界面js錄制的音頻數(shù)據(jù)用的接口

          (同樣就只寫一個)

          @Controller
          public class LoginCtrl {
              @Autowired
              LoginService loginService;
              @GetMapping("/")
              public String tologin(){
                  return "user/login";
              }
              /**
               * 登陸
               * */
              @PostMapping("/justlogin")
              @ResponseBody
              public R login(@RequestBody Login login, HttpSession session){
                  login.setPassword(Md5Util.StringInMd5(login.getPassword()));
                  String userid=loginService.justLogin(login);
                  if(userid==null){
                      return R.error().message("賬號或者密碼錯誤");
                  }
                  session.setAttribute("userid",userid);
                  return R.ok().message("登錄成功");
              }
          }
          

          七、創(chuàng)建對應(yīng)的工具類以及自定義異常類

          1. 表情過濾工具類
          public class EmojiFilter {
              private static boolean isEmojiCharacter(char codePoint) {
                  return (codePoint==0x0) || (codePoint==0x9) || (codePoint==0xA)
                          || (codePoint==0xD)
                          || ((codePoint >=0x20) && (codePoint <=0xD7FF))
                          || ((codePoint >=0xE000) && (codePoint <=0xFFFD))
                          || ((codePoint >=0x10000) && (codePoint <=0x10FFFF));
              }
          
              @Test
              public void testA(){
                  String s=EmojiFilter.filterEmoji("您好,你好啊");
                  System.out.println(s);
              }
          
          1. Md5數(shù)據(jù)加密類
             static String[] chars={"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};
          
              /**
               * 將普通字符串用md5加密,并轉(zhuǎn)化為16進制字符串
               * @param str
               * @return
               */
              public static String StringInMd5(String str) {
          
                  // 消息簽名(摘要)
                  MessageDigest md5=null;
                  try {
                      // 參數(shù)代表的是算法名稱
                      md5=MessageDigest.getInstance("md5");
                      byte[] result=md5.digest(str.getBytes());
          
                      StringBuilder sb=new StringBuilder(32);
                      // 將結(jié)果轉(zhuǎn)為16進制字符  0~9 A~F
                      for (int i=0; i < result.length; i++) {
                          // 一個字節(jié)對應(yīng)兩個字符
                          byte x=result[i];
                          // 取得高位
                          int h=0x0f & (x >>> 4);
                          // 取得低位
                          int l=0x0f & x;
                          sb.append(chars[h]).append(chars[l]);
                      }
                      return sb.toString();
          
                  } catch (NoSuchAlgorithmException e) {
                      throw new RuntimeException(e);
                  }
              }
          1. 測試數(shù)據(jù)加密類
          public class TestUtil {
              @Test
              public void testA(){
                  String s=Md5Util.StringInMd5("123456");
                  System.out.println(s);
              }
          }
          

          八、引入對應(yīng)的靜態(tài)資源文件(這個應(yīng)該一開始就做的)

          九、自定義一些配置并且注入到容器里面

          1. Druid數(shù)據(jù)源
          @Configuration
          public class DruidConfig {
              @ConfigurationProperties(prefix="spring.datasource")
              @Bean
              public DataSource druid(){
                  return new DruidDataSource();
              }
              //配置Druid的監(jiān)控
              //1.配置要給管理后臺的Servlet
              @Bean
              public ServletRegistrationBean servletRegistrationBean(){
                  ServletRegistrationBean bean=new ServletRegistrationBean(new StatViewServlet(),"/druid/*");
                  Map<String,String> initParams=new HashMap<>();
                  initParams.put("loginUsername","admin");
                  initParams.put("loginPassword","admin233215");
                  initParams.put("allow","");//默認(rèn)允許ip訪問
                  initParams.put("deny","");
                  bean.setInitParameters(initParams);
                  return bean;
              }
              //2.配置一個監(jiān)控的filter
              @Bean
              public FilterRegistrationBean webStarFilter(){
                  FilterRegistrationBean bean=new FilterRegistrationBean();
                  bean.setFilter(new WebStatFilter());
                  Map<String,String> initParams=new HashMap<>();
                  initParams.put("exclusions","*.js,*.css,/druid/*");
                  bean.setInitParameters(initParams);
                  bean.setUrlPatterns(Arrays.asList("/*"));
                  return bean;
              }
          }
          1. 靜態(tài)資源以及攔截器
          @Configuration
          public class MyConfig extends WebMvcConfigurerAdapter {
              //配置一個靜態(tài)文件的路徑 否則css和js無法使用,雖然默認(rèn)的靜態(tài)資源是放在static下,但是沒有配置里面的文件夾
              @Override
              public void addResourceHandlers(ResourceHandlerRegistry registry) {
                  registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
              }
              @Bean
              public WebMvcConfigurerAdapter WebMvcConfigurerAdapter() {
                  WebMvcConfigurerAdapter adapter=new WebMvcConfigurerAdapter() {
                      @Override
                      public void addResourceHandlers(ResourceHandlerRegistry registry) {
                          //registry.addResourceHandler("/pic/**").addResourceLocations("file:D:/chat/");
                          registry.addResourceHandler("/pic/**").addResourceLocations("file:D:/idea_project/SpringBoot/Project/Complete&&Finish/chat/chatmsg/");
                          super.addResourceHandlers(registry);
                      }
                  };
                  return adapter;
              }
              @Override
              public void addInterceptors(InterceptorRegistry registry) {
                  //注冊TestInterceptor攔截器
                  InterceptorRegistration registration=registry.addInterceptor(new AdminInterceptor());
                  registration.addPathPatterns("/chat/*");
              }
          }
          1. WebSocketConfigScokt通信配置
          @Configuration
          @EnableWebSocket
          public class WebSocketConfig {
           
              @Bean
              public ServerEndpointExporter serverEndpointExporter() {
                  return new ServerEndpointExporter();
              }
          }

          十、進行測試

          這是兩個不同的用戶

          當(dāng)然了,還可以進行語音,添加好友 今天的就寫到這里吧!謝謝! 這里要提一下我的一個學(xué)長的個人博客,當(dāng)然了,還有我的,謝謝

          作者:奶思

          鏈接:https://juejin.im/post/5ea7994c5188256da14e972d

          來源:掘金

          者:五月君

          轉(zhuǎn)發(fā)鏈接:https://mp.weixin.qq.com/s/TLKkRwftewa0uMvIRlOf5g

          鍵詞:Shopify聊天插件、獨立站運營、實時聊天機器人

          如果您在考慮 "如何在我的Shopify商店中添加實時聊天",您就來對地方了。在今天的文章中,我將告訴您如何一步一步地做到這一點。

          但在詳細(xì)介紹之前,讓我們了解一下為什么您應(yīng)該在您的網(wǎng)店中添加一個SaleSmartly聊天按鈕。

          為什么您的Shopify商店需要一個實時聊天工具?

          如果您在經(jīng)營電子商務(wù)業(yè)務(wù),您知道將每個訪客變成客戶,然后成為回頭客是多么困難的事情。通過實時聊天,您可以提供個性化的服務(wù),讓您的工作更加輕松。

          以下是為您的在線商店添加SaleSmartly實時聊天的好處。

          • 在潛在客戶考慮購買時抓住他們。當(dāng)網(wǎng)站訪客處于決策過程中時,您可以發(fā)送一條主動信息,讓他們知道您可以立即進行聊天。
          • 提高銷售額。根據(jù)研究,與企業(yè)進行實時聊天對話的客戶完成購買的可能性要高 2.8 倍。
          • 提高客戶參與度。實時聊天是一種 1:1 的對話,這是一種在個人層面上與潛在客戶互動的好方法,讓他們覺得與您更有聯(lián)系。

          聽起來不錯,對嗎?

          您可能會為擁有一個而感到興奮!所以,讓我們繼續(xù)發(fā)現(xiàn)最適合您的Shopify商店的實時聊天應(yīng)用程序。

          SaleSmartly實時聊天。最好的Shopify實時聊天應(yīng)用程序

          SaleSmartly為您提供了一個強大的實時聊天小工具,您可以將其添加到您的Shopify商店或其他電子商務(wù)商店。它是最好的Shopify實時聊天應(yīng)用程序之一。

          SaleSmartly實時聊天功能。

          • 在產(chǎn)品頁面上觸發(fā)與購物者的個性化實時聊天對話,促進銷售
          • 實時回答訪客的要求,消除任何銷售異議或疑慮
          • 知道客戶在哪個頁面上詢問
          • 在對話線程附近獲得所有先前的客戶購買信息和對話歷史(無論哪個渠道),以提供個性化的建議和支持
          • 為多個店鋪安裝實時聊天,并將所有對話集中到一個地方
          • 使用預(yù)制模板,一鍵回復(fù)
          • 為 "我的訂單在哪里?"等常見的問題設(shè)置自動回復(fù)和機器人。
          • 根據(jù)內(nèi)容以及人工智能檢測到的情緒和意圖,對票據(jù)進行分類、分配和優(yōu)先處理

          關(guān)于定價,SaleSmartly為您提供免費版試用,能嘗試各種功能。它的定價計劃比Zendesk Chat、Tidio Chat和其他實時聊天軟件都要合理和實惠。

          SaleSmartly也提供全渠道溝通,SaleSmartly集成了Messenger、WhatsApp、Instagram、Line、Telegram、Email等多渠道聊天管理插件,能助力賣家全面觸達(dá)海外消費者;同時支持100+語言實時翻譯,讓賣家與海外消費者可以無障礙交流。您還可以從此儀表板訪問來自其他渠道(如電子郵件、電話和社交媒體)的所有票證。

          將SaleSmartly與你的Shopify商店整合

          要跟上本教程,你需要一個SaleSmartly聊天賬戶。如果您還沒有, 請快快注冊一個吧!

          SaleSmartly實時聊天還提供了建立聊天機器人的能力,提升客戶回復(fù)效率,增加團隊之間的協(xié)作。通過自動化流程服務(wù),幫助提升客服工作效率。同時支持移動端小程序,隨時隨地回復(fù)各渠道的客戶咨詢。

          SaleSmartly官方注冊鏈接:https://www.salesmartly.com/?source=tth-Shopify627


          主站蜘蛛池模板: 末成年女A∨片一区二区| 久久国产三级无码一区二区| 国产不卡视频一区二区三区| 成人免费一区二区三区| 亚洲av无码一区二区三区观看| 国产综合视频在线观看一区| 中文字幕一区二区三区精彩视频 | 久久精品免费一区二区喷潮| 久久久久国产一区二区三区| 欧美日本精品一区二区三区 | 日本一区二区在线播放| 亚洲一区二区三区在线播放| 免费看AV毛片一区二区三区| 亚洲一区二区三区亚瑟| 亚洲无线码在线一区观看| 视频一区视频二区日韩专区| 人妻在线无码一区二区三区| 亚洲福利一区二区| 亚洲AV无码一区二区三区系列| 杨幂AV污网站在线一区二区| 日本韩国一区二区三区| 国产成人精品第一区二区| 亚洲电影一区二区| 亚洲综合色自拍一区| 一区视频在线播放| 无码日韩人妻AV一区二区三区| 免费无码一区二区三区蜜桃大 | 精品无码综合一区| 波多野结衣中文一区| 日本一区二区三区在线看| 色综合久久一区二区三区| 久久精品一区二区三区AV| 国产成人精品视频一区二区不卡| 成人精品一区二区三区不卡免费看| 精品无码成人片一区二区| 一区二区高清在线观看| chinese国产一区二区| 国产精品污WWW一区二区三区| 搜日本一区二区三区免费高清视频 | 日韩一区二区精品观看| 一区二区三区日本电影|