中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

服裝行業(yè)網(wǎng)站模板網(wǎng)絡(luò)推廣文案

服裝行業(yè)網(wǎng)站模板,網(wǎng)絡(luò)推廣文案,網(wǎng)站建設(shè)公司一年賺多少,房產(chǎn)法律咨詢熱線免費前端代碼 function initWebSocket() {if (typeof WebSocket "undefined") {console.log("您的瀏覽器不支持WebSocket");} else {console.log("您的瀏覽器支持WebSocket");//實現(xiàn)化WebSocket對象,指定要連接的服務(wù)器地址與端口 建立連…

前端代碼

function initWebSocket() {if (typeof WebSocket == "undefined") {console.log("您的瀏覽器不支持WebSocket");} else {console.log("您的瀏覽器支持WebSocket");//實現(xiàn)化WebSocket對象,指定要連接的服務(wù)器地址與端口 建立連接//等同于socket = new WebSocket("ws://localhost:8083/checkcentersys/websocket/20");var wsPathStr = wsPath + uuid;console.log("uuid22:" + uuid);socket = new WebSocket(wsPathStr);//打開事件socket.onopen = function () {console.log("Socket 已打開");socket.send("這是來自客戶端的消息" + location.href + new Date());};//獲得消息事件socket.onmessage = function (msg) {// debugger;console.log(msg.data);var data = JSON.parse(msg.data);if (data.code == 200) {alert("登錄成功!");//這里存放自己業(yè)務(wù)需要的數(shù)據(jù)。怎么放自己看window.sessionStorage.uuid = uuid;window.sessionStorage.userId = data.userId;window.sessionStorage.projId = data.projId;window.location.href = "pages/upload.html";} else {//如果過期了,關(guān)閉連接、重置連接、刷新二維碼// socket.close();// initQrImg();debugger;let path2 = getQrPath2 + "/" + uuid;axios.get(path2, {params: { dd: "cc" },}).then(function (success) {console.log("成功");},function (fail) {console.log("失敗");}).catch(function (error) {console.log("異常");});}//發(fā)現(xiàn)消息進入 開始處理前端觸發(fā)邏輯};//關(guān)閉事件socket.onclose = function () {console.log("Socket已關(guān)閉");};//發(fā)生了錯誤事件socket.onerror = function () {alert("Socket發(fā)生了錯誤");//此時可以嘗試刷新頁面};}

后端Java代碼

package com.example.poi.utils;import cn.hutool.json.JSONObject;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArraySet;/*** @Author xu* @create 2023/7/21 19*/
@ServerEndpoint("/websocket/{sid}")
@Component
public class WebSocketServer {static Log log= LogFactory.get(WebSocketServer.class);//靜態(tài)變量,用來記錄當前在線連接數(shù)。應(yīng)該把它設(shè)計成線程安全的。private static int onlineCount = 0;//concurrent包的線程安全Set,用來存放每個客戶端對應(yīng)的MyWebSocket對象。private static CopyOnWriteArraySet<WebSocketServer> webSocketSet = new CopyOnWriteArraySet<WebSocketServer>();//與某個客戶端的連接會話,需要通過它來給客戶端發(fā)送數(shù)據(jù)private Session session;//接收sidprivate String sid="";/*** 連接建立成功調(diào)用的方法** @param session* @param sid*/@OnOpenpublic void onOpen(Session session,@PathParam("sid") String sid) {this.session = session;webSocketSet.add(this); //加入set中addOnlineCount(); //在線數(shù)加1log.info("有新窗口開始監(jiān)聽:"+sid+",當前在線人數(shù)為" + getOnlineCount());this.sid=sid;/*try {sendMessage("連接成功");} catch (IOException e) {log.error("websocket IO異常");}*/}/*** 連接關(guān)閉調(diào)用的方法*/@OnClosepublic void onClose() {webSocketSet.remove(this); //從set中刪除subOnlineCount(); //在線數(shù)減1log.info("有一連接關(guān)閉!當前在線人數(shù)為" + getOnlineCount());}/***  收到客戶端消息后調(diào)用的方法* 客戶端發(fā)送過來的消息* @param message* @param session*/@OnMessagepublic void onMessage(String message, Session session) {log.info("收到來自窗口"+sid+"的信息:"+message);//群發(fā)消息for (WebSocketServer item : webSocketSet) {try {JSONObject jsonObject = new JSONObject();jsonObject.put("name","張三");jsonObject.put("code",2001);jsonObject.put("userId",16);jsonObject.put("projId",200);item.sendMessage(jsonObject.toString());} catch (IOException e) {e.printStackTrace();}}}/**** @param session* @param error*/@OnErrorpublic void onError(Session session, Throwable error) {log.error("發(fā)生錯誤");error.printStackTrace();}/*** 實現(xiàn)服務(wù)器主動推送* @param message* @throws IOException*/public void sendMessage(String message) throws IOException {this.session.getBasicRemote().sendText(message);}/*** 發(fā)送消息* @param message* @param sid* @throws IOException*/public static void sendInfo(String message,@PathParam("sid") String sid) throws IOException {log.info("推送消息到窗口"+sid+",推送內(nèi)容:"+message);for (WebSocketServer item : webSocketSet) {try {//這里可以設(shè)定只推送給這個sid的,為null則全部推送if(sid == null) {item.sendMessage(message);}else if(item.sid.equals(sid)){item.sendMessage(message);}} catch (IOException e) {continue;}}}public static synchronized int getOnlineCount() {return onlineCount;}public static synchronized void addOnlineCount() {WebSocketServer.onlineCount++;}public static synchronized void subOnlineCount() {WebSocketServer.onlineCount--;}/**必須要有這個bean才能生效使用webSocketServer*/@Beanpublic ServerEndpointExporter serverEndpointExporter() {return new ServerEndpointExporter();}}

pom

		<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.1</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.13</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.7.10</version></dependency><dependency><groupId>com.google.zxing</groupId><artifactId>core</artifactId><version>3.4.1</version></dependency><dependency><groupId>commons-lang</groupId><artifactId>commons-lang</artifactId><version>2.6</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.12</version></dependency>

生成二維碼

   //獲取登錄二維碼、放入Token//@CrossOrigin@RequestMapping(value = "/getLoginQr" ,method = RequestMethod.GET)public void createCodeImg(HttpServletRequest request, HttpServletResponse response){response.setHeader("Pragma", "No-cache");response.setHeader("Cache-Control", "no-cache");response.setDateHeader("Expires", 0);response.setContentType("image/jpeg");try {//這里沒啥操作 就是生成一個UUID插入 數(shù)據(jù)庫的表里//String uuid = userService.createQrImg();String uuid = "jdhasndi452iiwn11";response.addHeader("uuid", uuid);response.addHeader("Access-Control-Expose-Headers", "uuid");response.addHeader("Access-Control-Allow-Origin", "*");// 這里是開源工具類 hutool里的QrCodeUtil// 網(wǎng)址:http://hutool.mydoc.io/QrCodeUtil.generate(uuid, 300, 300, "jpg",response.getOutputStream());System.out.println("**");} catch (Exception e) {e.printStackTrace();}}

掃碼前端

<div id="qrImgDiv"></div>
function initQrImg() {$("#qrImgDiv").empty();var xmlhttp;xmlhttp = new XMLHttpRequest();xmlhttp.open("GET", getQrPath, true);xmlhttp.responseType = "blob";xmlhttp.onload = function () {console.log(this);uuid = this.getResponseHeader("uuid");console.log("uuid=", uuid);if (this.status == 200) {var blob = this.response;var img = document.createElement("img");img.className = "qrCodeBox-img";img.onload = function (e) {window.URL.revokeObjectURL(img.src);};img.src = window.URL.createObjectURL(blob);document.getElementById("qrImgDiv").appendChild(img);}};xmlhttp.send();}
http://www.risenshineclean.com/news/57054.html

相關(guān)文章:

  • xampp搭建wordpress長沙優(yōu)化網(wǎng)站
  • 山東有哪些網(wǎng)絡(luò)公司優(yōu)化法治化營商環(huán)境
  • 用dreamweaver怎么做網(wǎng)站百度推廣登錄賬號首頁
  • wordpress加中文字體山東搜索引擎優(yōu)化
  • 青海省建設(shè)廳官方網(wǎng)站建設(shè)云蘭州seo實戰(zhàn)優(yōu)化
  • 網(wǎng)站建設(shè)的主要工作西安seo陽建
  • 男女直接做那個的視頻網(wǎng)站專業(yè)網(wǎng)站建設(shè)公司首選
  • 開鎖做網(wǎng)站怎么樣pc優(yōu)化工具
  • 金閶網(wǎng)站建設(shè)什么是精準營銷
  • 怎么做跟別人一樣的網(wǎng)站自助建站系統(tǒng)哪個好
  • nginx wordpress安全商丘seo公司
  • 做網(wǎng)站加盟企業(yè)如何做好網(wǎng)絡(luò)營銷
  • 如何做婚戀網(wǎng)站北京網(wǎng)站優(yōu)化推廣方案
  • 長沙景點一日游攻略西安seo代運營
  • 網(wǎng)站的概念百度seo和谷歌seo有什么區(qū)別
  • 建設(shè)農(nóng)產(chǎn)品網(wǎng)站總結(jié)ppt整站排名優(yōu)化公司
  • 現(xiàn)在學java的都是傻子 知乎win10優(yōu)化工具
  • 簡單大氣的企業(yè)網(wǎng)站韓國搜索引擎排名
  • 直播型網(wǎng)站開發(fā)怎么在網(wǎng)上推廣廣告
  • 動易學校網(wǎng)站管理系統(tǒng) 下載各大網(wǎng)站收錄提交入口
  • 電腦銷售網(wǎng)站開發(fā)論文企業(yè)網(wǎng)站seo推廣方案
  • 網(wǎng)站域名備案誰來做太原seo顧問
  • 做網(wǎng)站需要公司有哪些游戲優(yōu)化大師官網(wǎng)
  • 深圳市網(wǎng)站維護外貿(mào)谷歌優(yōu)化
  • 做網(wǎng)站掙錢快又多武漢seo招聘
  • 做網(wǎng)站的網(wǎng)絡(luò)公司有哪些linux網(wǎng)站入口
  • 網(wǎng)站建設(shè)公司前景如何在百度上營銷
  • 網(wǎng)站開發(fā)論文結(jié)論百度游戲排行榜
  • 北京設(shè)計制作網(wǎng)站制作包頭網(wǎng)站建設(shè)推廣
  • 做個網(wǎng)站 多少錢網(wǎng)絡(luò)新聞發(fā)布平臺