{"id":592,"date":"2023-05-28T01:41:12","date_gmt":"2023-05-27T17:41:12","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=592"},"modified":"2023-06-30T11:31:40","modified_gmt":"2023-06-30T03:31:40","slug":"springboot%e9%9b%86%e6%88%90websocket%ef%bc%8c%e5%ae%9e%e7%8e%b0%e5%90%8e%e5%8f%b0%e5%90%91%e5%89%8d%e7%ab%af%e6%8e%a8%e9%80%81%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/spring-boot\/springboot%e9%9b%86%e6%88%90websocket%ef%bc%8c%e5%ae%9e%e7%8e%b0%e5%90%8e%e5%8f%b0%e5%90%91%e5%89%8d%e7%ab%af%e6%8e%a8%e9%80%81%e4%bf%a1%e6%81%af\/","title":{"rendered":"SpringBoot\u96c6\u6210WebSocket\uff0c\u5b9e\u73b0\u540e\u53f0\u5411\u524d\u7aef\u63a8\u9001\u4fe1\u606f"},"content":{"rendered":"<div class=\"wxsyncmain\">\n<p style=\"text-align: left;\"><span style=\"color: #888888; font-family: 'Helvetica Neue', Helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif; font-size: 14px; letter-spacing: 0.544px; text-align: left; background-color: #ffffff;\">\u539f\u6587\uff1ablog.csdn.net\/MacWx\/article\/details\/111319558<\/span><\/p>\n<section><\/section>\n<section style=\"margin-bottom: 0px; padding: 5px; outline: 0px; max-width: 100%; white-space: normal; background-color: #ffffff; line-height: 1.6; word-break: break-word; text-align: left; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif; font-size: 16px; color: #353535; word-spacing: 0.8px; letter-spacing: 0.8px; border-radius: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;\" data-tool=\"mdnice\u7f16\u8f91\u5668\" data-website=\"https:\/\/www.mdnice.com\">\n<h2 style=\"margin-top: 20px; margin-right: 10px; outline: 0px; font-weight: bold; font-size: 22px; max-width: 100%; color: black; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"padding-left: 10px; outline: 0px; max-width: 100%; font-size: 18px; color: #222222; display: inline-block; border-left: 5px solid #f83929; box-sizing: border-box !important; overflow-wrap: break-word !important;\">\u524d\u8a00<\/span><\/h2>\n<p style=\"margin-top: 0.8em; margin-bottom: 0.8em; padding-top: 8px; padding-bottom: 8px; outline: 0px; max-width: 100%; line-height: 1.75; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u5728\u4e00\u6b21\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u4f7f\u7528\u5230\u4e86Netty\u7f51\u7edc\u5e94\u7528\u6846\u67b6\uff0c\u4ee5\u53caMQTT\u8fdb\u884c\u6d88\u606f\u6570\u636e\u7684\u6536\u53d1\uff0c\u8fd9\u5176\u4e2d\u9700\u8981\u540e\u53f0\u6765\u5c06\u83b7\u53d6\u5230\u7684\u6d88\u606f\u4e3b\u52a8\u63a8\u9001\u7ed9\u524d\u7aef\uff0c\u4e8e\u662f\u5c31\u4f7f\u7528\u5230\u4e86MQTT\uff0c\u7279\u6b64\u8bb0\u5f55\u4e00\u4e0b\u3002<\/p>\n<h2 style=\"margin-top: 20px; margin-right: 10px; outline: 0px; font-weight: bold; font-size: 22px; max-width: 100%; color: black; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"padding-left: 10px; outline: 0px; max-width: 100%; font-size: 18px; color: #222222; display: inline-block; border-left: 5px solid #f83929; box-sizing: border-box !important; overflow-wrap: break-word !important;\">\u4e00\u3001\u4ec0\u4e48\u662fwebsocket\uff1f<\/span><\/h2>\n<p style=\"margin-top: 0.8em; margin-bottom: 0.8em; padding-top: 8px; padding-bottom: 8px; outline: 0px; max-width: 100%; line-height: 1.75; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">WebSocket\u534f\u8bae\u662f\u57fa\u4e8eTCP\u7684\u4e00\u79cd\u65b0\u7684\u7f51\u7edc\u534f\u8bae\u3002\u5b83\u5b9e\u73b0\u4e86\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u5168\u53cc\u5de5\u901a\u4fe1\uff0c\u5b66\u8fc7\u8ba1\u7b97\u673a\u7f51\u7edc\u90fd\u77e5\u9053\uff0c\u65e2\u7136\u662f\u5168\u53cc\u5de5\uff0c\u5c31\u8bf4\u660e\u4e86<span style=\"outline: 0px; max-width: 100%; font-weight: bold; color: #f83929; box-sizing: border-box !important; overflow-wrap: break-word !important;\">\u670d\u52a1\u5668\u53ef\u4ee5\u4e3b\u52a8\u53d1\u9001\u4fe1\u606f\u7ed9\u5ba2\u6237\u7aef<\/span>\u3002\u8fd9\u4e0e\u6211\u4eec\u7684\u63a8\u9001\u6280\u672f\u6216\u8005\u662f\u591a\u4eba\u5728\u7ebf\u804a\u5929\u7684\u529f\u80fd\u4e0d\u8c0b\u800c\u5408\u3002<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" style=\"width: 100%; height: auto;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010915124.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-backh=\"353\" data-backw=\"568\" data-galleryid=\"\" data-ratio=\"0.6214511041009464\" data-s=\"300,640\" data-type=\"png\" data-w=\"634\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"width: 100%; height: auto;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010915124.png\" data-backh=\"353\" data-backw=\"568\" data-galleryid=\"\" data-ratio=\"0.6214511041009464\" data-s=\"300,640\" data-type=\"png\" data-w=\"634\" \/><\/noscript><\/p>\n<p style=\"margin-top: 0.8em; margin-bottom: 0.8em; padding-top: 8px; padding-bottom: 8px; outline: 0px; max-width: 100%; line-height: 1.75; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u4e3a\u4ec0\u4e48\u4e0d\u4f7f\u7528HTTP \u534f\u8bae\u5462\uff1f\u8fd9\u662f\u56e0\u4e3aHTTP\u662f\u5355\u5de5\u901a\u4fe1\uff0c\u901a\u4fe1\u53ea\u80fd\u7531\u5ba2\u6237\u7aef\u53d1\u8d77\uff0c\u5ba2\u6237\u7aef\u8bf7\u6c42\u4e00\u4e0b\uff0c\u670d\u52a1\u5668\u5904\u7406\u4e00\u4e0b\uff0c\u8fd9\u5c31\u592a\u9ebb\u70e6\u4e86\u3002\u4e8e\u662fwebsocket\u5e94\u8fd0\u800c\u751f\u3002<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010915867.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-galleryid=\"\" data-ratio=\"0.7731958762886598\" data-s=\"300,640\" data-type=\"png\" data-w=\"776\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010915867.png\" data-galleryid=\"\" data-ratio=\"0.7731958762886598\" data-s=\"300,640\" data-type=\"png\" data-w=\"776\" \/><\/noscript><\/p>\n<p style=\"margin-top: 0.8em; margin-bottom: 0.8em; padding-top: 8px; padding-bottom: 8px; outline: 0px; max-width: 100%; line-height: 1.75; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u4e0b\u9762\u6211\u4eec\u5c31\u76f4\u63a5\u5f00\u59cb\u4f7f\u7528Springboot\u5f00\u59cb\u6574\u5408\u3002\u4ee5\u4e0b\u6848\u4f8b\u90fd\u5728\u6211\u81ea\u5df1\u7684\u7535\u8111\u4e0a\u6d4b\u8bd5\u6210\u529f\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u529f\u80fd\u8fdb\u884c\u4fee\u6539\u5373\u53ef\u3002\u6211\u7684\u9879\u76ee\u7ed3\u6784\u5982\u4e0b\uff1a<img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010919750.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-ratio=\"0.1568627450980392\" data-type=\"png\" data-w=\"663\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010919750.png\" data-ratio=\"0.1568627450980392\" data-type=\"png\" data-w=\"663\" \/><\/noscript><\/p>\n<h2 style=\"margin-top: 20px; margin-right: 10px; outline: 0px; font-weight: bold; font-size: 22px; max-width: 100%; color: black; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"padding-left: 10px; outline: 0px; max-width: 100%; font-size: 18px; color: #222222; display: inline-block; border-left: 5px solid #f83929; box-sizing: border-box !important; overflow-wrap: break-word !important;\">\u4e8c\u3001\u4f7f\u7528\u6b65\u9aa4<\/span><\/h2>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; outline: 0px; font-weight: bold; font-size: 20px; max-width: 100%; color: black; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"outline: 0px; max-width: 100%; font-size: 16px; color: #222222; box-sizing: border-box !important; overflow-wrap: break-word !important;\">1.\u6dfb\u52a0\u4f9d\u8d56<\/span><\/h3>\n<p style=\"margin-top: 0.8em; margin-bottom: 0.8em; padding-top: 8px; padding-bottom: 8px; outline: 0px; max-width: 100%; line-height: 1.75; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">Maven\u4f9d\u8d56\uff1a<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\">&lt;dependency&gt;<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\">&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\">&lt;artifactId&gt;spring-boot-starter-websocket&lt;\/artifactId&gt;<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\">&lt;\/dependency&gt;<\/p>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; outline: 0px; font-weight: bold; font-size: 20px; max-width: 100%; color: black; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"outline: 0px; max-width: 100%; font-size: 16px; color: #222222; box-sizing: border-box !important; overflow-wrap: break-word !important;\">2.\u542f\u7528Springboot\u5bf9WebSocket\u7684\u652f\u6301<\/span><\/h3>\n<p style=\"margin-top: 0.8em; margin-bottom: 0.8em; padding-top: 8px; padding-bottom: 8px; outline: 0px; max-width: 100%; line-height: 1.75; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u542f\u7528WebSocket\u7684\u652f\u6301\u4e5f\u662f\u5f88\u7b80\u5355\uff0c\u51e0\u53e5\u4ee3\u7801\u641e\u5b9a\uff1a<\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"css\">import org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.web.socket.server.standard.ServerEndpointExporter; \n\/** * @ Auther: \u9a6c\u8d85\u4f1f * @ Date: 2020\/06\/16\/14:35 * @ Description: \u5f00\u542fWebSocket\u652f\u6301 *\/ \n@Configuration \npublic class WebSocketConfig { \n@Bean \npublic ServerEndpointExporter serverEndpointExporter() { \nreturn new ServerEndpointExporter(); \n}}<\/pre>\n<\/section>\n<hr style=\"margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 100%; height: 1px; text-align: center; background-image: linear-gradient(to right, rgba(248, 57, 41, 0), rgba(248, 57, 41, 0.75), rgba(248, 57, 41, 0)); box-sizing: border-box !important; overflow-wrap: break-word !important; border: initial none initial;\" data-tool=\"mdnice\u7f16\u8f91\u5668\" \/>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; outline: 0px; font-weight: bold; font-size: 20px; max-width: 100%; color: black; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"outline: 0px; max-width: 100%; font-size: 16px; color: #222222; box-sizing: border-box !important; overflow-wrap: break-word !important;\">3.\u6838\u5fc3\u914d\u7f6e\uff1aWebSocketServer<\/span><\/h3>\n<p style=\"margin-top: 0.8em; margin-bottom: 0.8em; padding-top: 8px; padding-bottom: 8px; outline: 0px; max-width: 100%; line-height: 1.75; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u56e0\u4e3aWebSocket\u662f\u7c7b\u4f3c\u5ba2\u6237\u7aef\u670d\u52a1\u7aef\u7684\u5f62\u5f0f(\u91c7\u7528ws\u534f\u8bae)\uff0c\u90a3\u4e48\u8fd9\u91cc\u7684WebSocketServer\u5176\u5b9e\u5c31\u76f8\u5f53\u4e8e\u4e00\u4e2aws\u534f\u8bae\u7684Controller<\/p>\n<ul class=\"list-paddingleft-1\" style=\"margin-top: 8px; margin-bottom: 8px; padding-left: 25px; outline: 0px; max-width: 100%; width: 567.427px; color: #f83929; overflow-wrap: break-word !important;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\n<li style=\"outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;\">\n<section style=\"margin-top: 5px; margin-bottom: 5px; outline: 0px; max-width: 100%; line-height: 26px; color: #353535; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\">@ ServerEndpoint \u6ce8\u89e3\u662f\u4e00\u4e2a\u7c7b\u5c42\u6b21\u7684\u6ce8\u89e3\uff0c\u5b83\u7684\u529f\u80fd\u4e3b\u8981\u662f\u5c06\u76ee\u524d\u7684\u7c7b\u5b9a\u4e49\u6210\u4e00\u4e2awebsocket\u670d\u52a1\u5668\u7aef, \u6ce8\u89e3\u7684\u503c\u5c06\u88ab\u7528\u4e8e\u76d1\u542c\u7528\u6237\u8fde\u63a5\u7684\u7ec8\u7aef\u8bbf\u95eeURL\u5730\u5740,\u5ba2\u6237\u7aef\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2aURL\u6765\u8fde\u63a5\u5230WebSocket\u670d\u52a1\u5668\u7aef<\/section>\n<\/li>\n<li style=\"outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;\">\n<section style=\"margin-top: 5px; margin-bottom: 5px; outline: 0px; max-width: 100%; line-height: 26px; color: #353535; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\">\u65b0\u5efa\u4e00\u4e2aConcurrentHashMap webSocketMap \u7528\u4e8e\u63a5\u6536\u5f53\u524duserId\u7684WebSocket\uff0c\u65b9\u4fbf\u4f20\u9012\u4e4b\u95f4\u5bf9userId\u8fdb\u884c\u63a8\u9001\u6d88\u606f\u3002<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin-top: 0.8em; margin-bottom: 0.8em; padding-top: 8px; padding-bottom: 8px; outline: 0px; max-width: 100%; line-height: 1.75; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u4e0b\u9762\u662f\u5177\u4f53\u4e1a\u52a1\u4ee3\u7801\uff1a<\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"cpp\">import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;\nimport com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;\nimport lombok.extern.slf4j.Slf4j;\nimport org.springframework.stereotype.Component;import org.springframework.stereotype.Service;\nimport javax.websocket.*;import javax.websocket.server.PathParam;import javax.websocket.server.ServerEndpoint;import java.io.IOException;import java.time.LocalDateTime;import java.util.List;import java.util.concurrent.CopyOnWriteArraySet;\n\/**\u3001\n* Created with IntelliJ IDEA.\n* @ Auther: \u9a6c\u8d85\u4f1f\n* @ Date: 2020\/06\/16\/14:35\n* @ Description: * @ ServerEndpoint \u6ce8\u89e3\u662f\u4e00\u4e2a\u7c7b\u5c42\u6b21\u7684\u6ce8\u89e3\uff0c\u5b83\u7684\u529f\u80fd\u4e3b\u8981\u662f\u5c06\u76ee\u524d\u7684\u7c7b\u5b9a\u4e49\u6210\u4e00\u4e2awebsocket\u670d\u52a1\u5668\u7aef,\n* \u6ce8\u89e3\u7684\u503c\u5c06\u88ab\u7528\u4e8e\u76d1\u542c\u7528\u6237\u8fde\u63a5\u7684\u7ec8\u7aef\u8bbf\u95eeURL\u5730\u5740,\u5ba2\u6237\u7aef\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2aURL\u6765\u8fde\u63a5\u5230WebSocket\u670d\u52a1\u5668\u7aef *\/\n@Component\n@Slf4j\n@Service\n@ServerEndpoint(\"\/api\/websocket\/{sid}\")\npublic class WebSocketServer {\n\/\/\u9759\u6001\u53d8\u91cf\uff0c\u7528\u6765\u8bb0\u5f55\u5f53\u524d\u5728\u7ebf\u8fde\u63a5\u6570\u3002\u5e94\u8be5\u628a\u5b83\u8bbe\u8ba1\u6210\u7ebf\u7a0b\u5b89\u5168\u7684\u3002\nprivate static int onlineCount = 0;\n\/\/concurrent\u5305\u7684\u7ebf\u7a0b\u5b89\u5168Set\uff0c\u7528\u6765\u5b58\u653e\u6bcf\u4e2a\u5ba2\u6237\u7aef\u5bf9\u5e94\u7684MyWebSocket\u5bf9\u8c61\u3002\nprivate static CopyOnWriteArraySet&lt;WebSocketServer&gt; webSocketSet = new CopyOnWriteArraySet&lt;WebSocketServer&gt;();\n\/\/\u4e0e\u67d0\u4e2a\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u4f1a\u8bdd\uff0c\u9700\u8981\u901a\u8fc7\u5b83\u6765\u7ed9\u5ba2\u6237\u7aef\u53d1\u9001\u6570\u636e\nprivate Session session;\n\/\/\u63a5\u6536sid private String sid = \"\";\n\/** * \u8fde\u63a5\u5efa\u7acb\u6210\u529f\u8c03\u7528\u7684\u65b9\u6cd5 *\/ \n@OnOpen \npublic void onOpen(Session session, @PathParam(\"sid\") String sid) { \nthis.session = session; \nwebSocketSet.add(this); \/\/\u52a0\u5165set\u4e2d this.sid = sid; addOnlineCount(); \n\/\/\u5728\u7ebf\u6570\u52a01 \ntry { \nsendMessage(\"conn_success\"); \nlog.info(\"\u6709\u65b0\u7a97\u53e3\u5f00\u59cb\u76d1\u542c:\" + sid + \",\u5f53\u524d\u5728\u7ebf\u4eba\u6570\u4e3a:\" + getOnlineCount()); \n} catch (IOException e) { \nlog.error(\"websocket IO Exception\"); \n} }\n\/** * \u8fde\u63a5\u5173\u95ed\u8c03\u7528\u7684\u65b9\u6cd5 *\/ \n@OnClose \npublic void onClose() { \nwebSocketSet.remove(this); \/\/\u4eceset\u4e2d\u5220\u9664 subOnlineCount(); \/\/\u5728\u7ebf\u6570\u51cf1 \/\/\u65ad\u5f00\u8fde\u63a5\u60c5\u51b5\u4e0b\uff0c\u66f4\u65b0\u4e3b\u677f\u5360\u7528\u60c5\u51b5\u4e3a\u91ca\u653e log.info(\"\u91ca\u653e\u7684sid\u4e3a\uff1a\"+sid); \/\/\u8fd9\u91cc\u5199\u4f60 \u91ca\u653e\u7684\u65f6\u5019\uff0c\u8981\u5904\u7406\u7684\u4e1a\u52a1 log.info(\"\u6709\u4e00\u8fde\u63a5\u5173\u95ed\uff01\u5f53\u524d\u5728\u7ebf\u4eba\u6570\u4e3a\" + getOnlineCount());\n}\n\/** * \u6536\u5230\u5ba2\u6237\u7aef\u6d88\u606f\u540e\u8c03\u7528\u7684\u65b9\u6cd5 * @ Param message \u5ba2\u6237\u7aef\u53d1\u9001\u8fc7\u6765\u7684\u6d88\u606f *\/ \n@OnMessage \npublic void onMessage(String message, Session session) { \nlog.info(\"\u6536\u5230\u6765\u81ea\u7a97\u53e3\" + sid + \"\u7684\u4fe1\u606f:\" + message); \n\/\/\u7fa4\u53d1\u6d88\u606f \nfor (WebSocketServer item : webSocketSet) { \ntry { \nitem.sendMessage(message); \n} catch (IOException e) { \ne.printStackTrace(); \n} } }\n\/** * @ Param session * @ Param error *\/ \n@OnError \npublic void onError(Session session, Throwable error) { \nlog.error(\"\u53d1\u751f\u9519\u8bef\"); error.printStackTrace(); \n}\n\/** * \u5b9e\u73b0\u670d\u52a1\u5668\u4e3b\u52a8\u63a8\u9001 *\/ \npublic void sendMessage(String message) throws IOException { this.session.getBasicRemote().sendText(message); \n}\n\/** * \u7fa4\u53d1\u81ea\u5b9a\u4e49\u6d88\u606f *\/ \npublic static void sendInfo(String message, @PathParam(\"sid\") String sid) throws IOException { \nlog.info(\"\u63a8\u9001\u6d88\u606f\u5230\u7a97\u53e3\" + sid + \"\uff0c\u63a8\u9001\u5185\u5bb9:\" + message);\nfor (WebSocketServer item : webSocketSet) { \ntry { \n\/\/\u8fd9\u91cc\u53ef\u4ee5\u8bbe\u5b9a\u53ea\u63a8\u9001\u7ed9\u8fd9\u4e2asid\u7684\uff0c\u4e3anull\u5219\u5168\u90e8\u63a8\u9001 \nif (sid == null) {\n\/\/ item.sendMessage(message); \n} else if (item.sid.equals(sid)) { \nitem.sendMessage(message);\n }\n } catch (IOException e) {\n continue;\n }\n }\n }\npublic static synchronized int getOnlineCount() {\n return onlineCount; \n}\npublic static synchronized void addOnlineCount() {\n WebSocketServer.onlineCount++;\n }\npublic static synchronized void subOnlineCount() {\n WebSocketServer.onlineCount--;\n }\npublic static CopyOnWriteArraySet&lt;WebSocketServer&gt; getWebSocketSet() {\n return webSocketSet;\n }}<\/pre>\n<\/section>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; outline: 0px; font-weight: bold; font-size: 20px; max-width: 100%; color: black; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"outline: 0px; max-width: 100%; font-size: 16px; color: #222222; box-sizing: border-box !important; overflow-wrap: break-word !important;\">4.\u6d4b\u8bd5Controller<\/span><\/h3>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"kotlin\">import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.servlet.ModelAndView;\nimport java.io.IOException;import java.util.HashMap;import java.util.Map;\n\/** * Created with IntelliJ IDEA. * * @ Auther: \u9a6c\u8d85\u4f1f * @ Date: 2020\/06\/16\/14:38 * @ Description: *\/\n@Controller(\"web_Scoket_system\")\n@RequestMapping(\"\/api\/socket\")\npublic class SystemController {\n    \/\/\u9875\u9762\u8bf7\u6c42\n    @GetMapping(\"\/index\/{userId}\")\n    public ModelAndView socket(@PathVariable String userId) {\n        ModelAndView mav = new ModelAndView(\"\/socket1\");\n        mav.addObject(\"userId\", userId);\n        return mav;    \n}\n    \/\/\u63a8\u9001\u6570\u636e\u63a5\u53e3    \n@ResponseBody    \n@RequestMapping(\"\/socket\/push\/{cid}\")    \npublic Map pushToWeb(@PathVariable String cid, String message) {        Map&lt;String,Object&gt; result = new HashMap&lt;&gt;();\n        try {\n            WebSocketServer.sendInfo(message, cid);\n            result.put(\"code\", cid);\n            result.put(\"msg\", message);\n        } catch (IOException e) {\n            e.printStackTrace();\n        }        return result;\n    }}<\/pre>\n<\/section>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; outline: 0px; font-weight: bold; font-size: 20px; max-width: 100%; color: black; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"outline: 0px; max-width: 100%; font-size: 16px; color: #222222; box-sizing: border-box !important; overflow-wrap: break-word !important;\">5.\u6d4b\u8bd5\u9875\u9762index.html<\/span><\/h3>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"xml\">&lt;!DOCTYPE html&gt;&lt;html&gt;\n &lt;head&gt;\n  &lt;meta charset=\"utf-8\"&gt;\n  &lt;title&gt;Java\u540e\u7aefWebSocket\u7684Tomcat\u5b9e\u73b0&lt;\/title&gt;\n  &lt;script type=\"text\/javascript\" src=\"js\/jquery.min.js\"&gt;&lt;\/script&gt;\n &lt;\/head&gt;\n &lt;body&gt;\n  &lt;div id=\"main\" style=\"width: 1200px;height:800px;\"&gt;&lt;\/div&gt;\n  Welcome&lt;br\/&gt;&lt;input id=\"text\" type=\"text\" \/&gt;\n  &lt;button onclick=\"send()\"&gt;\u53d1\u9001\u6d88\u606f&lt;\/button&gt;\n  &lt;hr\/&gt;\n  &lt;button onclick=\"closeWebSocket()\"&gt;\u5173\u95edWebSocket\u8fde\u63a5&lt;\/button&gt;\n  &lt;hr\/&gt;\n  &lt;div id=\"message\"&gt;&lt;\/div&gt;\n &lt;\/body&gt;\n &lt;script type=\"text\/javascript\"&gt;\n  var websocket = null;\n  \/\/\u5224\u65ad\u5f53\u524d\u6d4f\u89c8\u5668\u662f\u5426\u652f\u6301WebSocket\n  if('WebSocket' in window) {\n   \/\/\u6539\u6210\u4f60\u7684\u5730\u5740\n   websocket = new WebSocket(\"ws:\/\/192.168.100.196:8082\/api\/websocket\/100\");\n  } else {\n   alert('\u5f53\u524d\u6d4f\u89c8\u5668 Not support websocket')\n  }\n  \/\/\u8fde\u63a5\u53d1\u751f\u9519\u8bef\u7684\u56de\u8c03\u65b9\u6cd5\n  websocket.onerror = function() {\n   setMessageInnerHTML(\"WebSocket\u8fde\u63a5\u53d1\u751f\u9519\u8bef\");\n  };\n  \/\/\u8fde\u63a5\u6210\u529f\u5efa\u7acb\u7684\u56de\u8c03\u65b9\u6cd5\n  websocket.onopen = function() {\n   setMessageInnerHTML(\"WebSocket\u8fde\u63a5\u6210\u529f\");\n  }\n  var U01data, Uidata, Usdata\n  \/\/\u63a5\u6536\u5230\u6d88\u606f\u7684\u56de\u8c03\u65b9\u6cd5\n  websocket.onmessage = function(event) {\n   console.log(event);\n   setMessageInnerHTML(event);\n   setechart()\n  }\n  \/\/\u8fde\u63a5\u5173\u95ed\u7684\u56de\u8c03\u65b9\u6cd5\n  websocket.onclose = function() {\n   setMessageInnerHTML(\"WebSocket\u8fde\u63a5\u5173\u95ed\");\n  }\n  \/\/\u76d1\u542c\u7a97\u53e3\u5173\u95ed\u4e8b\u4ef6\uff0c\u5f53\u7a97\u53e3\u5173\u95ed\u65f6\uff0c\u4e3b\u52a8\u53bb\u5173\u95edwebsocket\u8fde\u63a5\uff0c\u9632\u6b62\u8fde\u63a5\u8fd8\u6ca1\u65ad\u5f00\u5c31\u5173\u95ed\u7a97\u53e3\uff0cserver\u7aef\u4f1a\u629b\u5f02\u5e38\u3002\n  window.onbeforeunload = function() {\n   closeWebSocket();\n  }\n  \/\/\u5c06\u6d88\u606f\u663e\u793a\u5728\u7f51\u9875\u4e0a\n  function setMessageInnerHTML(innerHTML) {\n   document.getElementById('message').innerHTML += innerHTML + '&lt;br\/&gt;';\n  }\n  \/\/\u5173\u95edWebSocket\u8fde\u63a5  function closeWebSocket() {\n   websocket.close();\n  }\n  \/\/\u53d1\u9001\u6d88\u606f  function send() {\n   var message = document.getElementById('text').value;\n   websocket.send('{\"msg\":\"' + message + '\"}');\n   setMessageInnerHTML(message + \"&amp;#13;\");\n  }&lt;\/script&gt;\n&lt;\/html&gt;<\/pre>\n<\/section>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; outline: 0px; font-weight: bold; font-size: 20px; max-width: 100%; color: black; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"outline: 0px; max-width: 100%; font-size: 16px; color: #222222; box-sizing: border-box !important; overflow-wrap: break-word !important;\">6.\u7ed3\u679c\u5c55\u793a<\/span><\/h3>\n<p style=\"margin-top: 0.8em; margin-bottom: 0.8em; padding-top: 8px; padding-bottom: 8px; outline: 0px; max-width: 100%; line-height: 1.75; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u540e\u53f0\uff1a\u5982\u679c\u6709\u8fde\u63a5\u8bf7\u6c42<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010920200.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-galleryid=\"\" data-ratio=\"0.12962962962962962\" data-s=\"300,640\" data-type=\"png\" data-w=\"1080\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010920200.png\" data-galleryid=\"\" data-ratio=\"0.12962962962962962\" data-s=\"300,640\" data-type=\"png\" data-w=\"1080\" \/><\/noscript><\/p>\n<p style=\"margin-top: 0.8em; margin-bottom: 0.8em; padding-top: 8px; padding-bottom: 8px; outline: 0px; max-width: 100%; line-height: 1.75; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u524d\u53f0\u663e\u793a\uff1a<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" style=\"width: 100%; height: auto;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010923259.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-backh=\"305\" data-backw=\"409\" data-galleryid=\"\" data-ratio=\"0.7457212713936431\" data-s=\"300,640\" data-type=\"png\" data-w=\"409\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"width: 100%; height: auto;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010923259.png\" data-backh=\"305\" data-backw=\"409\" data-galleryid=\"\" data-ratio=\"0.7457212713936431\" data-s=\"300,640\" data-type=\"png\" data-w=\"409\" \/><\/noscript><\/p>\n<h2 style=\"margin-top: 20px; margin-right: 10px; outline: 0px; font-weight: bold; font-size: 22px; max-width: 100%; color: black; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><span style=\"padding-left: 10px; outline: 0px; max-width: 100%; font-size: 18px; color: #222222; display: inline-block; border-left: 5px solid #f83929; box-sizing: border-box !important; overflow-wrap: break-word !important;\">\u603b\u7ed3<\/span><\/h2>\n<p style=\"margin-top: 0.8em; margin-bottom: 0.8em; padding-top: 8px; padding-bottom: 8px; outline: 0px; max-width: 100%; line-height: 1.75; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u8fd9\u4e2d\u95f4\u6211\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u8bf4WebSocket\u542f\u52a8\u7684\u65f6\u5019\u4f18\u5148\u4e8espring\u5bb9\u5668\uff0c\u4ece\u800c\u5bfc\u81f4\u5728WebSocketServer\u4e2d\u8c03\u7528\u4e1a\u52a1Service\u4f1a\u62a5\u7a7a\u6307\u9488\u5f02\u5e38<\/p>\n<p style=\"margin-top: 0.8em; margin-bottom: 0.8em; padding-top: 8px; padding-bottom: 8px; outline: 0px; max-width: 100%; line-height: 1.75; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u6240\u4ee5\u9700\u8981\u5728WebSocketServer\u4e2d\u5c06\u6240\u9700\u8981\u7528\u5230\u7684service\u7ed9\u9759\u6001\u521d\u59cb\u5316\u4e00\u4e0b\uff1a\u5982\u56fe\u6240\u793a\uff1a<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010923856.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-galleryid=\"\" data-ratio=\"0.28425925925925927\" data-s=\"300,640\" data-type=\"png\" data-w=\"1080\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010923856.png\" data-galleryid=\"\" data-ratio=\"0.28425925925925927\" data-s=\"300,640\" data-type=\"png\" data-w=\"1080\" \/><\/noscript><\/p>\n<p style=\"margin-top: 0.8em; margin-bottom: 0.8em; padding-top: 8px; padding-bottom: 8px; outline: 0px; max-width: 100%; line-height: 1.75; box-sizing: border-box !important; overflow-wrap: break-word !important; text-align: left;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u8fd8\u9700\u8981\u505a\u5982\u4e0b\u914d\u7f6e\uff1a<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010927371.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-galleryid=\"\" data-ratio=\"0.3148148148148148\" data-s=\"300,640\" data-type=\"png\" data-w=\"1080\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010927371.png\" data-galleryid=\"\" data-ratio=\"0.3148148148148148\" data-s=\"300,640\" data-type=\"png\" data-w=\"1080\" \/><\/noscript><\/p>\n<\/section>\n<p style=\"margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 100%; letter-spacing: 0.544px; white-space: normal; color: #3e3e3e; text-align: center; widows: 1; word-spacing: 2px; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; line-height: 2em; box-sizing: border-box !important; overflow-wrap: break-word !important;\"><strong style=\"outline: 0px; max-width: 100%; letter-spacing: 0.544px; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 16.3636px; box-sizing: border-box !important; overflow-wrap: break-word !important;\">\u00b7END\u00b7<\/strong><\/p>\n<p style=\"display: none;\">\n<blockquote><p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7: IT\u725b\u5ba2<\/p><\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\uff1ablog.csdn.net\/MacWx\/article\/details\/111319558 \u524d\u8a00 \u5728\u4e00\u6b21\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u4f7f\u7528\u5230\u4e86 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":584,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[7,8],"tags":[],"class_list":["post-592","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-boot","category-spring-cloud"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010914144-150x150.jpeg","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010915124.png","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010914144-300x300.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010914144.jpeg","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010915124.png","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010914144-300x300.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010914144.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010914144.jpeg","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010915124.png","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010915124.png","id":"image1"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010915867.png","id":"image2"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010915867.png","id":"image3"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010919750.png","id":"image4"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010919750.png","id":"image5"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010920200.png","id":"image6"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010920200.png","id":"image7"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010923259.png","id":"image8"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010923259.png","id":"image9"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010923856.png","id":"image10"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010923856.png","id":"image11"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010927371.png","id":"image12"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528010927371.png","id":"image13"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Spring Boot","post_date":"2023-05-27","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":343,"next_post_id":556,"next_post_title":"Linux\u8fdb\u9636","previous_post_id":510,"previous_post_title":"SpringBoot\u56db\u5927\u6838\u5fc3\u7ec4\u4ef6\uff0c\u8fd8\u6709\u4eba\u4e0d\u77e5\u9053\uff1f","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=592"}],"version-history":[{"count":0,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/592\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/584"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}