{"id":6655,"date":"2025-09-29T12:31:44","date_gmt":"2025-09-29T04:31:44","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=6655"},"modified":"2025-09-29T12:31:52","modified_gmt":"2025-09-29T04:31:52","slug":"%e5%88%86%e5%b8%83%e5%bc%8f%e7%b3%bb%e7%bb%9f-token-%e7%bb%ad%e6%9c%9f%e8%b8%a9%e5%9d%91%e5%ae%9e%e5%bd%95%ef%bc%9a%e8%87%aa%e5%8a%a8%e7%bb%ad%e6%9c%9f-%e8%ae%be%e5%a4%87%e7%bb%91%e5%ae%9a%e8%bf%99","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/java\/%e5%88%86%e5%b8%83%e5%bc%8f%e7%b3%bb%e7%bb%9f-token-%e7%bb%ad%e6%9c%9f%e8%b8%a9%e5%9d%91%e5%ae%9e%e5%bd%95%ef%bc%9a%e8%87%aa%e5%8a%a8%e7%bb%ad%e6%9c%9f-%e8%ae%be%e5%a4%87%e7%bb%91%e5%ae%9a%e8%bf%99\/","title":{"rendered":"\u5206\u5e03\u5f0f\u7cfb\u7edf Token \u7eed\u671f\u8e29\u5751\u5b9e\u5f55\uff1a\u81ea\u52a8\u7eed\u671f + \u8bbe\u5907\u7ed1\u5b9a\u8fd9\u6837\u505a\u624d\u5b89\u5168"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u65b9\u6848\u4e09\uff1a\u81ea\u52a8\u7eed\u671f\u65b9\u6848\uff08\u7528\u6237\u5b8c\u5168\u65e0\u611f\u77e5\uff09<\/h2>\n\n\n\n<p>\u57fa\u7840\u65b9\u6848\u9700\u8981\u524d\u7aef\u4e3b\u52a8\u8c03\u7528\u5237\u65b0\u63a5\u53e3\uff0c\u81ea\u52a8\u7eed\u671f\u5219\u662f\u540e\u7aef\u5077\u5077\u5904\u7406\uff0c\u7528\u6237\u64cd\u4f5c\u65f6\u5b8c\u5168\u6ca1\u611f\u89c9\uff0c\u4f53\u9a8c\u6700\u597d\uff0c\u9002\u5408 SAAS \u5e94\u7528\u3001\u524d\u540e\u7aef\u5206\u79bb\u7cfb\u7edf\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u6838\u5fc3\u601d\u8def\uff1a\u62e6\u622a\u5668 + \u6ed1\u52a8\u7a97\u53e3<\/h3>\n\n\n\n<p>\u5728\u8bf7\u6c42\u62e6\u622a\u5668\u91cc\u5224\u65ad Token \u5269\u4f59\u65f6\u95f4\uff0c\u5feb\u8fc7\u671f\u65f6\u81ea\u52a8\u5237\u65b0\uff0c\u7528\u54cd\u5e94\u5934\u8fd4\u56de\u65b0 Token\uff0c\u524d\u7aef\u5077\u5077\u66ff\u6362\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Component<br>public&nbsp;class&nbsp;TokenRenewInterceptor&nbsp;implements&nbsp;HandlerInterceptor&nbsp;{<br>&nbsp; &nbsp;&nbsp;@Autowired<br>&nbsp; &nbsp;&nbsp;private&nbsp;TokenService tokenService;<br><br>&nbsp; &nbsp;&nbsp;\/\/ Token\u603b\u6709\u6548\u671f30\u5206\u949f\uff0c\u5269\u4f59\u65f6\u95f4\u5c0f\u4e8e5\u5206\u949f\uff08\u621630%\u6709\u6548\u671f\uff09\u65f6\u7eed\u671f<br>&nbsp; &nbsp;&nbsp;private&nbsp;static&nbsp;final&nbsp;long&nbsp;MIN_REMAIN_TIME&nbsp;=&nbsp;5&nbsp;*&nbsp;60&nbsp;*&nbsp;1000;<br>&nbsp; &nbsp;&nbsp;private&nbsp;static&nbsp;final&nbsp;double&nbsp;REMAIN_RATIO&nbsp;=&nbsp;0.3;<br><br>&nbsp; &nbsp;&nbsp;@Override<br>&nbsp; &nbsp;&nbsp;public&nbsp;boolean&nbsp;preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)&nbsp;throws&nbsp;Exception {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 1. \u63d0\u53d6Token\uff08\u4ece\u8bf7\u6c42\u5934\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;token&nbsp;=&nbsp;request.getHeader(\"Authorization\").replace(\"Bearer \",&nbsp;\"\");<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(token ==&nbsp;null) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;throw&nbsp;new&nbsp;SecurityException(\"Token\u4e0d\u80fd\u4e3a\u7a7a\");<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 2. \u5224\u65ad\u662f\u5426\u9700\u8981\u7eed\u671f<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(needRenew(token)) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 3. \u81ea\u52a8\u5237\u65b0Token<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;newToken&nbsp;=&nbsp;tokenService.autoRefreshToken(token);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 4. \u65b0Token\u653e\u5728\u54cd\u5e94\u5934\uff0c\u524d\u7aef\u5077\u5077\u66ff\u6362<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.setHeader(\"X-New-Token\", newToken);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;true;<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp;&nbsp;\/\/ \u5224\u65ad\u662f\u5426\u9700\u8981\u7eed\u671f\uff1a\u53cc\u9608\u503c\u7b56\u7565\uff08\u7edd\u5bf9\u65f6\u95f4+\u76f8\u5bf9\u6bd4\u4f8b\uff09<br>&nbsp; &nbsp;&nbsp;private&nbsp;boolean&nbsp;needRenew(String token)&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u89e3\u6790Token\u8fc7\u671f\u65f6\u95f4\u548c\u603b\u6709\u6548\u671f<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Date&nbsp;expireTime&nbsp;=&nbsp;JwtUtil.getExpireTime(token);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;long&nbsp;totalValidTime&nbsp;=&nbsp;JwtUtil.getTotalValidTime(token);&nbsp;\/\/ 30*60*1000<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;long&nbsp;remainTime&nbsp;=&nbsp;expireTime.getTime() - System.currentTimeMillis();<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u5269\u4f59\u65f6\u95f4\u5c0f\u4e8e5\u5206\u949f \u6216 \u5c0f\u4e8e\u603b\u6709\u6548\u671f\u768430%\uff0c\u5c31\u9700\u8981\u7eed\u671f<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;remainTime &lt;= Math.min(MIN_REMAIN_TIME, (long) (totalValidTime * REMAIN_RATIO));<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<p>\u524d\u7aef\u62ff\u5230\u54cd\u5e94\u5934\u7684<code><strong>X-New-Token<\/strong><\/code>\u540e\uff0c\u5077\u5077\u66ff\u6362\u672c\u5730\u5b58\u50a8\u7684 Token\uff0c\u7528\u6237\u5b8c\u5168\u6ca1\u611f\u77e5 \u2014\u2014 \u6bd4\u5982\u6b63\u5728\u7f16\u8f91\u6587\u6863\uff0cToken \u7eed\u671f\u4e86\u90fd\u4e0d\u77e5\u9053\uff0c\u4f53\u9a8c\u62c9\u6ee1\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Redis \u7f13\u5b58\u7eed\u671f\uff1a\u89e3\u51b3\u5206\u5e03\u5f0f\u4e00\u81f4\u6027\u95ee\u9898<\/h3>\n\n\n\n<p>\u5206\u5e03\u5f0f\u7cfb\u7edf\u91cc\uff0c\u591a\u4e2a\u670d\u52a1\u90fd\u8981\u5224\u65ad Token \u662f\u5426\u9700\u8981\u7eed\u671f\uff0c\u7528 Redis \u7f13\u5b58 Token \u72b6\u6001\uff0c\u907f\u514d\u6bcf\u4e2a\u670d\u52a1\u90fd\u89e3\u6790 JWT\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Service<br>public&nbsp;class&nbsp;TokenService&nbsp;{<br>&nbsp; &nbsp;&nbsp;@Autowired<br>&nbsp; &nbsp;&nbsp;private&nbsp;RedisTemplate&lt;String, String&gt; redisTemplate;<br><br>&nbsp; &nbsp;&nbsp;\/\/ Token\u6709\u6548\u671f30\u5206\u949f\uff0cRedis\u7f13\u5b58\u65f6\u95f4\u548cToken\u4e00\u81f4<br>&nbsp; &nbsp;&nbsp;private&nbsp;static&nbsp;final&nbsp;long&nbsp;TOKEN_EXPIRE&nbsp;=&nbsp;30&nbsp;*&nbsp;60;<br><br>&nbsp; &nbsp;&nbsp;\/\/ \u81ea\u52a8\u5237\u65b0Token\uff08\u7ed3\u5408Redis\u7f13\u5b58\uff09<br>&nbsp; &nbsp;&nbsp;public&nbsp;String&nbsp;autoRefreshToken(String oldToken)&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 1. \u5148\u67e5Redis\u7f13\u5b58\uff0c\u7f13\u5b58\u4e0d\u5b58\u5728\u8bf4\u660eToken\u5df2\u5931\u6548<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;cacheKey&nbsp;=&nbsp;\"token:cache:\"&nbsp;+ oldToken;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;cachedToken&nbsp;=&nbsp;redisTemplate.opsForValue().get(cacheKey);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(cachedToken ==&nbsp;null) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;throw&nbsp;new&nbsp;SecurityException(\"Token\u5df2\u5931\u6548\uff0c\u8bf7\u91cd\u65b0\u767b\u5f55\");<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 2. \u89e3\u6790\u7528\u6237\u540d\uff0c\u751f\u6210\u65b0Token<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;username&nbsp;=&nbsp;JwtUtil.parseUsername(oldToken);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;newToken&nbsp;=&nbsp;JwtUtil.createToken(username, TOKEN_EXPIRE *&nbsp;1000);<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 3. \u5173\u952e\uff1a\u65e7Token\u7684\u7f13\u5b58Key\u4e0d\u53d8\uff0c\u503c\u6362\u6210\u65b0Token\uff08\u4fdd\u8bc1\u5206\u5e03\u5f0f\u670d\u52a1\u62ff\u5230\u6700\u65b0Token\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp; redisTemplate.opsForValue().set(cacheKey, newToken, TOKEN_EXPIRE, TimeUnit.SECONDS);<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 4. \u65e7Token\u52a0\u5165\u9ed1\u540d\u5355\uff08\u63d0\u524d\u5931\u6548\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;blacklistKey&nbsp;=&nbsp;\"token:blacklist:\"&nbsp;+ oldToken;<br>&nbsp; &nbsp; &nbsp; &nbsp; redisTemplate.opsForValue().set(blacklistKey,&nbsp;\"invalid\", TOKEN_EXPIRE +&nbsp;5&nbsp;*&nbsp;60, TimeUnit.SECONDS);<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;newToken;<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<p><strong>\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u505a<\/strong>\uff1a\u5fae\u670d\u52a1 A \u548c\u5fae\u670d\u52a1 B \u90fd\u80fd\u901a\u8fc7 Redis \u62ff\u5230\u6700\u65b0 Token\uff0c\u4e0d\u4f1a\u51fa\u73b0 \u201c\u670d\u52a1 A \u7eed\u671f\u4e86\uff0c\u670d\u52a1 B \u8fd8\u5728\u7528\u65e7 Token\u201d \u7684\u60c5\u51b5\u3002https:\/\/wxa.wxs.qq.com\/tmpl\/oc\/base_tmpl.html<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Gateway \u5168\u5c40\u8fc7\u6ee4\u5668\uff1a\u5fae\u670d\u52a1\u7edf\u4e00\u5904\u7406<\/h3>\n\n\n\n<p>\u5fae\u670d\u52a1\u67b6\u6784\u4e0b\uff0c\u5728 Gateway \u7f51\u5173\u52a0\u5168\u5c40\u8fc7\u6ee4\u5668\uff0c\u6240\u6709\u670d\u52a1\u7684 Token \u7eed\u671f\u903b\u8f91\u96c6\u4e2d\u7ba1\u7406\uff0c\u4e0d\u7528\u6bcf\u4e2a\u670d\u52a1\u90fd\u52a0\u62e6\u622a\u5668\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Component<br>@Order(-100)\/\/ \u4f18\u5148\u7ea7\u9ad8\u4e8e\u5176\u4ed6\u8fc7\u6ee4\u5668<br>public&nbsp;class&nbsp;TokenRenewGlobalFilter&nbsp;implements&nbsp;GlobalFilter&nbsp;{<br>&nbsp; &nbsp;&nbsp;@Autowired<br>&nbsp; &nbsp;&nbsp;private&nbsp;TokenService tokenService;<br><br>&nbsp; &nbsp;&nbsp;@Override<br>&nbsp; &nbsp;&nbsp;public&nbsp;Mono&lt;Void&gt;&nbsp;filter(ServerWebExchange exchange, GatewayFilterChain chain)&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 1. \u63d0\u53d6Token\uff08\u4ece\u8bf7\u6c42\u5934\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;ServerHttpRequest&nbsp;request&nbsp;=&nbsp;exchange.getRequest();<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;token&nbsp;=&nbsp;request.getHeaders().getFirst(\"Authorization\");<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(token ==&nbsp;null&nbsp;|| !token.startsWith(\"Bearer \")) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;chain.filter(exchange);&nbsp;\/\/ \u65e0Token\uff0c\u540e\u7eed\u8fc7\u6ee4\u5668\u5904\u7406<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; token = token.replace(\"Bearer \",&nbsp;\"\");<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 2. \u5224\u65ad\u662f\u5426\u9700\u8981\u7eed\u671f<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(needRenew(token)) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;try&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 3. \u81ea\u52a8\u5237\u65b0Token<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;newToken&nbsp;=&nbsp;tokenService.autoRefreshToken(token);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 4. \u65b0Token\u653e\u5728\u54cd\u5e94\u5934<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;ServerHttpResponse&nbsp;response&nbsp;=&nbsp;exchange.getResponse();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.getHeaders().add(\"X-New-Token\", newToken);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;catch&nbsp;(Exception e) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u7eed\u671f\u5931\u8d25\uff0c\u4e0d\u5f71\u54cd\u539f\u8bf7\u6c42\uff08\u539fToken\u53ef\u80fd\u8fd8\u6709\u6548\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.warn(\"Token\u7eed\u671f\u5931\u8d25\uff1a{}\", e.getMessage());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;chain.filter(exchange);<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp;&nbsp;\/\/ \u5224\u65ad\u662f\u5426\u9700\u8981\u7eed\u671f\uff08\u548c\u62e6\u622a\u5668\u903b\u8f91\u4e00\u81f4\uff09<br>&nbsp; &nbsp;&nbsp;private&nbsp;boolean&nbsp;needRenew(String token)&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Date&nbsp;expireTime&nbsp;=&nbsp;JwtUtil.getExpireTime(token);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;long&nbsp;totalValidTime&nbsp;=&nbsp;JwtUtil.getTotalValidTime(token);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;long&nbsp;remainTime&nbsp;=&nbsp;expireTime.getTime() - System.currentTimeMillis();<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;remainTime &lt;= Math.min(5&nbsp;*&nbsp;60&nbsp;*&nbsp;1000, (long) (totalValidTime *&nbsp;0.3));<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6837\u4e0d\u7ba1\u662f\u8ba2\u5355\u670d\u52a1\u3001\u7528\u6237\u670d\u52a1\uff0c\u8fd8\u662f\u5546\u54c1\u670d\u52a1\uff0c\u90fd\u4e0d\u7528\u7ba1 Token \u7eed\u671f\uff0c\u5168\u7531 Gateway \u7edf\u4e00\u5904\u7406\uff0c\u4ee3\u7801\u91cf\u51cf\u5c11 80%\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u5206\u5e03\u5f0f\u73af\u5883\u7684\u7279\u6b8a\u6311\u6218\uff1a\u591a\u8bbe\u5907 + \u8de8\u670d\u52a1<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u591a\u8bbe\u5907\u4f1a\u8bdd\u7ba1\u7406\uff1a\u907f\u514d \u201c\u6ce8\u9500\u4e00\u4e2a\u8bbe\u5907\uff0c\u6240\u6709\u8bbe\u5907\u4e0b\u7ebf\u201d<\/h3>\n\n\n\n<p>\u7528\u6237\u7528\u624b\u673a\u548c\u7535\u8111\u540c\u65f6\u767b\u5f55\uff0c\u6ce8\u9500\u7535\u8111\u7aef\uff0c\u624b\u673a\u7aef\u4e0d\u80fd\u8ddf\u7740\u4e0b\u7ebf\uff0c\u7528 Redis Hash \u5b58\u50a8\u6bcf\u4e2a\u7528\u6237\u7684\u8bbe\u5907\u4f1a\u8bdd\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Service<br>public&nbsp;class&nbsp;DeviceSessionService&nbsp;{<br>&nbsp; &nbsp;&nbsp;@Autowired<br>&nbsp; &nbsp;&nbsp;private&nbsp;RedisTemplate&lt;String, String&gt; redisTemplate;<br><br>&nbsp; &nbsp;&nbsp;\/\/ \u7528\u6237\u767b\u5f55\u65f6\uff0c\u5b58\u50a8\u8bbe\u5907\u4f1a\u8bdd\uff08key\uff1auser:{userId}:devices\uff0cfield\uff1a\u8bbe\u5907\u7c7b\u578b\uff0cvalue\uff1arefresh_token\u7684stateId\uff09<br>&nbsp; &nbsp;&nbsp;public&nbsp;void&nbsp;saveDeviceSession(Long userId, String deviceType, String stateId)&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;hashKe y=&nbsp;\"user:\"&nbsp;+ userId +&nbsp;\":devices\";<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u5b58\u50a8\u8bbe\u5907\u5bf9\u5e94\u7684stateId\uff08\u8986\u76d6\u65e7\u7684\uff0c\u540c\u4e00\u8bbe\u5907\u767b\u5f55\u4f1a\u9876\u6389\u4e4b\u524d\u7684\u4f1a\u8bdd\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp; redisTemplate.opsForHash().put(hashKey, deviceType, stateId);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u8bbe\u7f6eHash\u8fc7\u671f\u65f6\u95f4\uff08\u548crefresh_token\u4e00\u81f4\uff0c7\u5929\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp; redisTemplate.expire(hashKey,&nbsp;7&nbsp;*&nbsp;24&nbsp;*&nbsp;60&nbsp;*&nbsp;60, TimeUnit.SECONDS);<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp;&nbsp;\/\/ \u6ce8\u9500\u6307\u5b9a\u8bbe\u5907\u7684\u4f1a\u8bdd<br>&nbsp; &nbsp;&nbsp;public&nbsp;void&nbsp;logoutDevice(Long userId, String deviceType)&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;hashKey&nbsp;=&nbsp;\"user:\"&nbsp;+ userId +&nbsp;\":devices\";<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 1. \u83b7\u53d6\u8be5\u8bbe\u5907\u5bf9\u5e94\u7684stateId<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;stateId&nbsp;=&nbsp;(String) redisTemplate.opsForHash().get(hashKey, deviceType);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(stateId ==&nbsp;null) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 2. \u4f7f\u8be5\u8bbe\u5907\u7684refresh_token\u5931\u6548<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;refreshKey&nbsp;=&nbsp;\"token:refresh:\"&nbsp;+ stateId;<br>&nbsp; &nbsp; &nbsp; &nbsp; redisTemplate.delete(refreshKey);<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 3. \u4eceHash\u4e2d\u5220\u9664\u8be5\u8bbe\u5907<br>&nbsp; &nbsp; &nbsp; &nbsp; redisTemplate.opsForHash().delete(hashKey, deviceType);<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp;&nbsp;\/\/ \u5f3a\u5236\u7528\u6237\u6240\u6709\u8bbe\u5907\u4e0b\u7ebf\uff08\u5982\u6539\u5bc6\u7801\u540e\uff09<br>&nbsp; &nbsp;&nbsp;public&nbsp;void&nbsp;logoutAllDevices(Long userId)&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;hashKey&nbsp;=&nbsp;\"user:\"&nbsp;+ userId +&nbsp;\":devices\";<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 1. \u83b7\u53d6\u6240\u6709\u8bbe\u5907\u7684stateId<br>&nbsp; &nbsp; &nbsp; &nbsp; Map&lt;Object, Object&gt; deviceMap = redisTemplate.opsForHash().entries(hashKey);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 2. \u4f7f\u6240\u6709refresh_token\u5931\u6548<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(Object stateId : deviceMap.values()) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;refreshKey&nbsp;=&nbsp;\"token:refresh:\"&nbsp;+ stateId;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; redisTemplate.delete(refreshKey);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 3. \u5220\u9664\u6240\u6709\u8bbe\u5907\u4f1a\u8bdd<br>&nbsp; &nbsp; &nbsp; &nbsp; redisTemplate.delete(hashKey);<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/wxa.wxs.qq.com\/tmpl\/oc\/base_tmpl.html\n<\/div><\/figure>\n\n\n\n<p>\u6bd4\u5982\u7528\u6237\u5728\u7535\u8111\u7aef\u6ce8\u9500\uff0c\u53ea\u4f1a\u5220\u9664 \u201cPC\u201d \u8bbe\u5907\u5bf9\u5e94\u7684\u4f1a\u8bdd\uff0c\u624b\u673a\u7aef\u7684 \u201cMobile\u201d \u8bbe\u5907\u4e0d\u53d7\u5f71\u54cd\uff0c\u4f53\u9a8c\u66f4\u53cb\u597d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u8de8\u670d\u52a1\u4ee4\u724c\u9a8c\u8bc1\uff1a\u672c\u5730\u7f13\u5b58 + \u8ba4\u8bc1\u4e2d\u5fc3<\/h3>\n\n\n\n<p>\u591a\u670d\u52a1\u95f4\u9a8c\u8bc1 Token\uff0c\u6bcf\u6b21\u90fd\u67e5 Redis \u6216\u8ba4\u8bc1\u4e2d\u5fc3\u4f1a\u5f71\u54cd\u6027\u80fd\uff0c\u7528\u672c\u5730\u7f13\u5b58\u505a\u4e00\u5c42\u5feb\u901f\u9a8c\u8bc1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Service<br>public&nbsp;class&nbsp;CrossServiceTokenValidator&nbsp;{<br>&nbsp; &nbsp;&nbsp;@Autowired<br>&nbsp; &nbsp;&nbsp;private&nbsp;AuthCenterClient authCenterClient;&nbsp;\/\/ \u8ba4\u8bc1\u4e2d\u5fc3Feign\u5ba2\u6237\u7aef<br>&nbsp; &nbsp;&nbsp;@Autowired<br>&nbsp; &nbsp;&nbsp;private&nbsp;RedisTemplate&lt;String, String&gt; redisTemplate;<br><br>&nbsp; &nbsp;&nbsp;\/\/ Caffeine\u672c\u5730\u7f13\u5b58\uff1a\u5b58\u50a8\u6700\u8fd110000\u4e2a\u6709\u6548Token\uff0c5\u5206\u949f\u8fc7\u671f<br>&nbsp; &nbsp;&nbsp;private&nbsp;final&nbsp;LoadingCache&lt;String, Boolean&gt; tokenLocalCache = Caffeine.newBuilder()<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .maximumSize(10_000)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .expireAfterWrite(5, TimeUnit.MINUTES)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .build(key -&gt; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u7f13\u5b58\u672a\u547d\u4e2d\u65f6\uff0c\u67e5Redis\u6216\u8ba4\u8bc1\u4e2d\u5fc3<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;redisKey&nbsp;=&nbsp;\"token:valid:\"&nbsp;+ key;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(Boolean.TRUE.equals(redisTemplate.hasKey(redisKey))) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ Redis\u6ca1\u67e5\u5230\uff0c\u67e5\u8ba4\u8bc1\u4e2d\u5fc3\uff08\u6700\u7ec8\u6570\u636e\u6e90\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;authCenterClient.validateToken(key);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br><br>&nbsp; &nbsp;&nbsp;\/\/ \u8de8\u670d\u52a1\u9a8c\u8bc1Token<br>&nbsp; &nbsp;&nbsp;public&nbsp;boolean&nbsp;validateTokenAcrossService(String token)&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;try&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 1. \u5148\u67e5\u672c\u5730\u7f13\u5b58\uff08\u5feb\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;tokenLocalCache.get(token);<br>&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;catch&nbsp;(Exception e) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 2. \u7f13\u5b58\u67e5\u4e0d\u5230\uff0c\u76f4\u63a5\u67e5\u8ba4\u8bc1\u4e2d\u5fc3\uff08\u515c\u5e95\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;authCenterClient.validateToken(token);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<p>\u672c\u5730\u7f13\u5b58\u80fd\u6321\u4f4f 80% \u7684\u9a8c\u8bc1\u8bf7\u6c42\uff0c\u53ea\u6709 20% \u7684\u8bf7\u6c42\u4f1a\u67e5 Redis \u6216\u8ba4\u8bc1\u4e2d\u5fc3\uff0c\u6027\u80fd\u63d0\u5347\u660e\u663e \u2014\u2014 \u4e4b\u524d\u505a SAAS \u7cfb\u7edf\uff0c\u6ca1\u52a0\u672c\u5730\u7f13\u5b58\u65f6\uff0cToken \u9a8c\u8bc1 QPS \u53ea\u6709 500\uff0c\u52a0\u4e86\u4e4b\u540e\u80fd\u5230 5000\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u30015 \u79cd Token \u7eed\u671f\u65b9\u6848\u5168\u5bf9\u6bd4\uff08\u8be5\u600e\u4e48\u9009\uff1f\uff09<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u65b9\u6848<\/th><th>\u5b89\u5168\u6027<\/th><th>\u7528\u6237\u4f53\u9a8c<\/th><th>\u5b9e\u73b0\u590d\u6742\u5ea6<\/th><th>\u9002\u7528\u573a\u666f<\/th><th>\u6027\u80fd\u5f71\u54cd<\/th><\/tr><\/thead><tbody><tr><td>\u5355 Token \u57fa\u7840\u7248<\/td><td>\u2605\u2606\u2606\u2606\u2606<\/td><td>\u2605\u2605\u2606\u2606\u2606<\/td><td>\u4f4e<\/td><td>\u5185\u90e8\u6d4b\u8bd5\u7cfb\u7edf<\/td><td>\u4f4e<\/td><\/tr><tr><td>\u5355 Token + \u9ed1\u540d\u5355<\/td><td>\u2605\u2605\u2606\u2606\u2606<\/td><td>\u2605\u2605\u2605\u2606\u2606<\/td><td>\u4f4e<\/td><td>\u4f01\u4e1a\u5185\u7f51\u3001\u77ed\u671f\u6d3b\u52a8<\/td><td>\u4e2d<\/td><\/tr><tr><td>\u53cc Token \u57fa\u7840\u7248<\/td><td>\u2605\u2605\u2605\u2606\u2606<\/td><td>\u2605\u2605\u2605\u2605\u2606<\/td><td>\u4e2d<\/td><td>\u5e38\u89c4 Web\/APP<\/td><td>\u4e2d<\/td><\/tr><tr><td>\u53cc Token + \u4e09\u9a8c\u8bc1<\/td><td>\u2605\u2605\u2605\u2605\u2605<\/td><td>\u2605\u2605\u2605\u2606\u2606<\/td><td>\u9ad8<\/td><td>\u91d1\u878d\u3001\u652f\u4ed8\u7cfb\u7edf<\/td><td>\u9ad8<\/td><\/tr><tr><td>\u81ea\u52a8\u7eed\u671f + Gateway<\/td><td>\u2605\u2605\u2605\u2605\u2606<\/td><td>\u2605\u2605\u2605\u2605\u2605<\/td><td>\u9ad8<\/td><td>SAAS \u5e94\u7528\u3001\u5fae\u670d\u52a1\u3001\u9ad8\u4f53\u9a8c\u8981\u6c42<\/td><td>\u4e2d\u9ad8<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>\u9009\u578b\u53e3\u8bc0<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b89\u5168\u7b2c\u4e00\uff08\u91d1\u878d \/ \u652f\u4ed8\uff09\uff1a\u53cc Token + \u4e09\u9a8c\u8bc1 + \u8bbe\u5907\u7ed1\u5b9a<\/li>\n\n\n\n<li>\u4f53\u9a8c\u7b2c\u4e00\uff08SAAS\/APP\uff09\uff1a\u81ea\u52a8\u7eed\u671f + Gateway + \u672c\u5730\u7f13\u5b58<\/li>\n\n\n\n<li>\u7b80\u5355\u5feb\u901f\uff08\u5185\u90e8\u7cfb\u7edf\uff09\uff1a\u5355 Token + \u9ed1\u540d\u5355<\/li>\n\n\n\n<li>\u5206\u5e03\u5f0f\u7cfb\u7edf\uff1a\u5fc5\u52a0 Gateway \u5168\u5c40\u5904\u7406 + \u672c\u5730\u7f13\u5b58<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u907f\u5751\u6307\u5357\uff1a\u8fd9 5 \u4e2a\u5751\u5343\u4e07\u522b\u8e29<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>access_token \u6709\u6548\u671f\u592a\u957f<\/strong><br>\u6700\u957f\u4e0d\u8981\u8d85\u8fc7 30 \u5206\u949f\uff0c\u8d8a\u957f\u98ce\u9669\u8d8a\u9ad8 \u2014\u2014 \u4e4b\u524d\u89c1\u8fc7\u6709\u4eba\u8bbe 2 \u5c0f\u65f6\uff0c\u7ed3\u679c Token \u88ab\u52ab\u6301\uff0c\u653b\u51fb\u8005\u7528\u4e86 1 \u4e2a\u591a\u5c0f\u65f6\u624d\u88ab\u53d1\u73b0\u3002<\/li>\n\n\n\n<li><strong>refresh_token \u53ef\u91cd\u590d\u4f7f\u7528<\/strong><br>\u6bcf\u6b21\u5237\u65b0\u5fc5\u987b\u751f\u6210\u65b0\u7684 refresh_token\uff0c\u65e7\u7684\u7acb\u5373\u5931\u6548\uff0c\u5426\u5219\u88ab\u52ab\u6301\u540e\u80fd\u65e0\u9650\u5237\u65b0\u3002<\/li>\n\n\n\n<li><strong>\u6ca1\u5904\u7406\u8bbe\u5907\u53d8\u66f4<\/strong><br>\u624b\u673a\u767b\u5f55\u540e\uff0c\u7a81\u7136\u5728\u7535\u8111\u4e0a\u7528\u540c\u4e00\u4e2a refresh_token \u5237\u65b0\uff0c\u5fc5\u987b\u8981\u6c42\u91cd\u65b0\u9a8c\u8bc1\uff08\u5982\u77ed\u4fe1\u9a8c\u8bc1\u7801\uff09\uff0c\u9632\u6b62 Token \u88ab\u76d7\u7528\u3002<\/li>\n\n\n\n<li><strong>\u5e76\u53d1\u5237\u65b0\u6ca1\u52a0\u9501<\/strong><br>\u9ad8\u5cf0\u671f\u591a\u4e2a\u8bf7\u6c42\u540c\u65f6\u5237\u65b0\uff0c\u4f1a\u751f\u6210\u591a\u4e2a\u6709\u6548 Token\uff0c\u7528 Redisson \u5206\u5e03\u5f0f\u9501\u63a7\u5236\uff0c\u53ea\u80fd\u6709\u4e00\u4e2a\u8bf7\u6c42\u6210\u529f\u3002<\/li>\n\n\n\n<li><strong>\u654f\u611f\u64cd\u4f5c\u4e0d\u4e8c\u6b21\u9a8c\u8bc1<\/strong><br>\u4ed8\u6b3e\u3001\u6539\u5bc6\u7801\u7b49\u654f\u611f\u64cd\u4f5c\uff0c\u4e0d\u80fd\u53ea\u9a8c\u8bc1 Token\uff0c\u8fd8\u8981\u52a0\u77ed\u4fe1 \/ \u9a8c\u8bc1\u7801\u4e8c\u6b21\u9a8c\u8bc1\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u654f\u611f\u64cd\u4f5c\u4e8c\u6b21\u9a8c\u8bc1<br>public&nbsp;void&nbsp;processPayment(String token, String smsCode)&nbsp;{<br>&nbsp; &nbsp;&nbsp;\/\/ 1. \u9a8c\u8bc1Token\uff08\u57fa\u7840\uff09<br>&nbsp; &nbsp;&nbsp;if&nbsp;(!tokenService.validateToken(token)) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;throw&nbsp;new&nbsp;SecurityException(\"Token\u5931\u6548\");<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;&nbsp;\/\/ 2. \u9a8c\u8bc1\u77ed\u4fe1\u9a8c\u8bc1\u7801\uff08\u4e8c\u6b21\u9a8c\u8bc1\uff09<br>&nbsp; &nbsp;&nbsp;Long&nbsp;userId&nbsp;=&nbsp;JwtUtil.parseUserId(token);<br>&nbsp; &nbsp;&nbsp;if&nbsp;(!smsService.verifyCode(userId, smsCode)) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;throw&nbsp;new&nbsp;SecurityException(\"\u77ed\u4fe1\u9a8c\u8bc1\u7801\u9519\u8bef\");<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;&nbsp;\/\/ 3. \u6267\u884c\u4ed8\u6b3e\u64cd\u4f5c<br>&nbsp; &nbsp; paymentService.pay(userId);<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6700\u540e\uff1a\u597d\u7684 Token \u7eed\u671f\u50cf \u201c\u81ea\u4e3b\u795e\u7ecf\u7cfb\u7edf\u201d<\/h2>\n\n\n\n<p>\u7528\u6237\u5e73\u65f6\u611f\u53d7\u4e0d\u5230\u5b83\u7684\u5b58\u5728\uff0c\u4f46\u5728 Token \u5feb\u8fc7\u671f\u65f6\uff0c\u4f1a\u81ea\u52a8\u7eed\u671f\uff1b\u5728\u8bbe\u5907\u53d8\u66f4\u65f6\uff0c\u4f1a\u9ed8\u9ed8\u9a8c\u8bc1\uff1b\u5728\u654f\u611f\u64cd\u4f5c\u65f6\uff0c\u4f1a\u4e25\u683c\u628a\u5173\u3002<\/p>\n\n\n\n<p>\u4ece\u5355 Token \u5230\u53cc Token\uff0c\u518d\u5230\u81ea\u52a8\u7eed\u671f\uff0c\u6838\u5fc3\u4e0d\u662f\u6280\u672f\u591a\u590d\u6742\uff0c\u800c\u662f\u5e73\u8861\u5b89\u5168\u3001\u4f53\u9a8c\u548c\u6027\u80fd \u2014\u2014 \u4e0d\u8981\u4e3a\u4e86\u5b89\u5168\u727a\u7272\u4f53\u9a8c\uff0c\u4e5f\u4e0d\u8981\u4e3a\u4e86\u4f53\u9a8c\u5ffd\u7565\u5b89\u5168\u3002<\/p>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u65b9\u6848\u4e09\uff1a\u81ea\u52a8\u7eed\u671f\u65b9\u6848\uff08\u7528\u6237\u5b8c\u5168\u65e0\u611f\u77e5\uff09 \u57fa\u7840\u65b9\u6848\u9700\u8981\u524d\u7aef\u4e3b\u52a8\u8c03\u7528\u5237\u65b0\u63a5\u53e3\uff0c\u81ea\u52a8\u7eed\u671f\u5219\u662f\u540e\u7aef\u5077\u5077\u5904\u7406\uff0c\u7528\u6237\u64cd\u4f5c\u65f6\u5b8c\u5168\u6ca1\u611f\u89c9\uff0c\u4f53\u9a8c &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[2,7],"tags":[],"class_list":["post-6655","post","type-post","status-publish","format-standard","hentry","category-java","category-spring-boot"],"post_thumbnail_image":"","content_first_image":null,"post_medium_image_300":"","post_thumbnail_image_624":"","post_frist_image":null,"post_medium_image":"","post_large_image":"","post_full_image":"","post_all_images":[],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Java","post_date":"2025-09-29","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":217,"next_post_id":6659,"next_post_title":"SpringBoot+WebSocket\u6253\u9020\u8d85\u7a33\u5b9a\u5b9e\u65f6\u76d1\u63a7\uff01","previous_post_id":6646,"previous_post_title":"SpringBoot\u5168\u5c40\/\u5c40\u90e8\u53cc\u6a21\u5f0fGzip\u538b\u7f29\u5b9e\u6218\uff1a14MB GeoJSON\u79d2\u53d83MB","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6655","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=6655"}],"version-history":[{"count":1,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6655\/revisions"}],"predecessor-version":[{"id":6656,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6655\/revisions\/6656"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=6655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=6655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=6655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}