{"id":6565,"date":"2025-09-29T11:25:26","date_gmt":"2025-09-29T03:25:26","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=6565"},"modified":"2025-09-29T11:25:37","modified_gmt":"2025-09-29T03:25:37","slug":"springboot%e6%95%b4%e5%90%88%e5%be%ae%e4%bf%a1%e7%99%bb%e5%bd%95%ef%bc%9aopenid%e4%b8%8eunionid%e8%8e%b7%e5%8f%96%e5%85%a8%e6%b5%81%e7%a8%8b%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/spring-boot\/springboot%e6%95%b4%e5%90%88%e5%be%ae%e4%bf%a1%e7%99%bb%e5%bd%95%ef%bc%9aopenid%e4%b8%8eunionid%e8%8e%b7%e5%8f%96%e5%85%a8%e6%b5%81%e7%a8%8b%e8%a7%a3%e6%9e%90\/","title":{"rendered":"SpringBoot\u6574\u5408\u5fae\u4fe1\u767b\u5f55\uff1aOpenID\u4e0eUnionID\u83b7\u53d6\u5168\u6d41\u7a0b\u89e3\u6790"},"content":{"rendered":"\n<p>\u5c0f\u7a0b\u5e8f\u767b\u5f55\u5728\u5f00\u53d1\u4e2d\u662f\u6700\u5e38\u89c1\u7684\u9700\u6c42\uff0c\u54ea\u6015\u5c0f\u7a0b\u5e8f\u767b\u5f55\u4e0d\u662f\u4f60\u505a\uff0c\u4f60\u8fd8\u662f\u8981\u4e86\u89e3\u4e00\u4e0b\u6d41\u7a0b\uff0c\u540e\u7eed\u90fd\u8981\u4f7f\u7528\u5230openId\u548cunionId\uff0c\u4f60\u9700\u8981\u77e5\u9053\u8fd9\u4e9b\u662f\u5e72\u4ec0\u4e48\u7684\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"265\" height=\"569\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6566 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png 265w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719-140x300.png 140w\" sizes=\"auto, (max-width: 265px) 100vw, 265px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"265\" height=\"569\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png\" alt=\"\" class=\"wp-image-6566\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png 265w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719-140x300.png 140w\" sizes=\"auto, (max-width: 265px) 100vw, 265px\" \/><\/noscript><\/figure>\n\n\n\n<p>\u5fae\u4fe1\u767b\u5f55\u4e1a\u52a1\u903b\u8f91\u89c4\u5219\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"819\" height=\"758\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023634164.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6567 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023634164.png 819w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023634164-300x278.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023634164-768x711.png 768w\" sizes=\"auto, (max-width: 819px) 100vw, 819px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"819\" height=\"758\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023634164.png\" alt=\"\" class=\"wp-image-6567\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023634164.png 819w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023634164-300x278.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023634164-768x711.png 768w\" sizes=\"auto, (max-width: 819px) 100vw, 819px\" \/><\/noscript><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">\u601d\u8def\u8bf4\u660e<\/h1>\n\n\n\n<p>\u53c2\u8003\u5fae\u4fe1\u5b98\u65b9\u6587\u6863\u7684\u63d0\u4f9b\u7684\u601d\u8def\uff0c\u5b98\u65b9\u6587\u6863\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/developers.weixin.qq.com\/miniprogram\/dev\/framework\/open-ability\/login.html\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/developers.weixin.qq.com\/miniprogram\/dev\/framework\/open-ability\/login.html<\/a><\/p>\n\n\n\n<p>\u5fae\u4fe1\u5b98\u65b9\u63a8\u8350\u767b\u5f55\u6d41\u7a0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"628\" height=\"646\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023720853.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6568 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023720853.png 628w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023720853-292x300.png 292w\" sizes=\"auto, (max-width: 628px) 100vw, 628px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"628\" height=\"646\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023720853.png\" alt=\"\" class=\"wp-image-6568\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023720853.png 628w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023720853-292x300.png 292w\" sizes=\"auto, (max-width: 628px) 100vw, 628px\" \/><\/noscript><\/figure>\n\n\n\n<p>\u6ce8\u610f\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u2022 \u524d\u7aef\u5728\u5c0f\u7a0b\u5e8f\u96c6\u6210\u5fae\u4fe1\u76f8\u5173\u4f9d\u8d56\uff0c\u8c03\u7528<code>wx.login<\/code>\u83b7\u53d6\u4e34\u65f6\u767b\u5f55\u51ed\u8bc1code\uff0c\u4f20\u7ed9\u540e\u7aef\u3002<\/li>\n\n\n\n<li>\u2022 \u540e\u7aef\u8c03\u7528<code>auth.code2Session<\/code>\u63a5\u53e3\uff0c\u6362\u53d6<code>openId<\/code>\u548c\u3001<code>UnionId<\/code>\u3001\u4f1a\u8bdd\u79d8\u94a5<code>Session_Key<\/code>\u3002<\/li>\n\n\n\n<li>\u2022 \u5f00\u53d1\u8005\u670d\u52a1\u5668\u53ef\u4ee5\u6839\u636e\u7528\u6237\u6807\u8bc6\u81ea\u5b9a\u4e49\u767b\u5f55\u72b6\u6001\uff0c\u7528\u4e8e\u540e\u7eed\u4e1a\u52a1\u903b\u8f91\u4e2d\u524d\u540e\u7aef\u4ea4\u4e92\u8bc6\u522b\u7528\u6237\u8eab\u4efd\u3002<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">\u8868\u7ed3\u6784\u8bf4\u660e<\/h1>\n\n\n\n<p>\u521b\u5efa\u4e00\u5f20\u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u7528\u6237\u7684\u4fe1\u606f\u4ee5\u53ca<code>oenId<\/code>\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"315\" height=\"278\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023748614.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6569 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023748614.png 315w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023748614-300x265.png 300w\" sizes=\"auto, (max-width: 315px) 100vw, 315px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"315\" height=\"278\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023748614.png\" alt=\"\" class=\"wp-image-6569\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023748614.png 315w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023748614-300x265.png 300w\" sizes=\"auto, (max-width: 315px) 100vw, 315px\" \/><\/noscript><\/figure>\n\n\n\n<p>\u5efa\u8868\u8bed\u53e5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE\u00a0\"family_member\" (\n\u00a0 \"id\"\u00a0bigint\u00a0NOT NULL\u00a0AUTO_INCREMENT COMMENT\u00a0'\u4e3b\u952e',\n\u00a0 \"phone\"\u00a0varchar(20)\u00a0CHARACTER SET\u00a0utf8mb4\u00a0COLLATE\u00a0utf8mb4_general_ci\u00a0NOT NULL\u00a0COMMENT\u00a0'\u624b\u673a\u53f7',\n\u00a0 \"name\"\u00a0varchar(100)\u00a0CHARACTER SET\u00a0utf8mb4\u00a0COLLATE\u00a0utf8mb4_general_ci\u00a0DEFAULT\u00a0NULL\u00a0COMMENT\u00a0'\u540d\u79f0',\n\u00a0 \"avatar\"\u00a0varchar(255)\u00a0CHARACTER SET\u00a0utf8mb4\u00a0COLLATE\u00a0utf8mb4_general_ci\u00a0DEFAULT\u00a0NULL\u00a0COMMENT\u00a0'\u5934\u50cf',\n\u00a0 \"open_id\"\u00a0varchar(255)\u00a0CHARACTER SET\u00a0utf8mb4\u00a0COLLATE\u00a0utf8mb4_general_ci\u00a0DEFAULT\u00a0NULL\u00a0COMMENT\u00a0'OpenID',\n\u00a0 \"gender\"\u00a0int\u00a0DEFAULT\u00a0NULL\u00a0COMMENT\u00a0'\u6027\u522b(0:\u7537\uff0c1:\u5973)',\n\u00a0 \"create_time\"\u00a0timestamp\u00a0NULL\u00a0DEFAULT\u00a0CURRENT_TIMESTAMP\u00a0COMMENT\u00a0'\u521b\u5efa\u65f6\u95f4',\n\u00a0 \"update_time\"\u00a0timestamp\u00a0NULL\u00a0DEFAULT\u00a0CURRENT_TIMESTAMP\u00a0ON\u00a0UPDATE\u00a0CURRENT_TIMESTAMP\u00a0COMMENT\u00a0'\u66f4\u65b0\u65f6\u95f4',\n\u00a0 \"create_by\"\u00a0bigint\u00a0DEFAULT\u00a0NULL\u00a0COMMENT\u00a0'\u521b\u5efa\u4eba',\n\u00a0 \"update_by\"\u00a0bigint\u00a0DEFAULT\u00a0NULL\u00a0COMMENT\u00a0'\u66f4\u65b0\u4eba',\n\u00a0 \"remark\"\u00a0varchar(255)\u00a0CHARACTER SET\u00a0utf8mb4\u00a0COLLATE\u00a0utf8mb4_general_ci\u00a0DEFAULT\u00a0NULL\u00a0COMMENT\u00a0'\u5907\u6ce8',\n\u00a0 PRIMARY KEY\u00a0(\"id\")\u00a0USING\u00a0BTREE\n) ENGINE=InnoDB AUTO_INCREMENT=2\u00a0DEFAULT\u00a0CHARSET=utf8mb4\u00a0COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC\u00a0COMMENT='\u8001\u4eba\u5bb6\u5c5e';<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u63a5\u53e3\u8bf4\u660e<\/h1>\n\n\n\n<p>\u63a5\u53e3\u8ddf\u5e73\u65f6\u7684\u63a5\u53e3\u7565\u6709\u4e0d\u540c\uff0c\u53c2\u8003\u5fae\u4fe1\u5f00\u53d1\u8005\u5e73\u53f0\u63d0\u4f9b\u7684\u6d41\u7a0b\u5f00\u53d1\u3002<\/p>\n\n\n\n<p>\u8bf7\u6c42\u53c2\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{<br>&nbsp; \"code\":&nbsp;\"0e36jkGa1ercRF0Fu4Ia1V3fPD06jkGW\",&nbsp;\/\/\u4e34\u65f6\u767b\u5f55\u51ed\u8bc1code<br>&nbsp; \"nickName\":&nbsp;\"\u5fae\u4fe1\u7528\u6237\",<br>&nbsp; \"phoneCode\":&nbsp;\"13fe315872a4fb9ed3deee1e5909d5af60dfce7911013436fddcfe13f55ecad3\"<br>}<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0a\u4e09\u4e2a\u53c2\u6570\u90fd\u662f\u524d\u7aef\u8c03\u7528<code>wx.login<\/code>\u83b7\u53d6\u8fd4\u56de\u7684\u53c2\u6570<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u2022\u00a0<strong>code\uff1a<\/strong>\u00a0\u4e34\u65f6\u767b\u5f55\u51ed\u8bc1code\uff08\u6709\u6548\u65f6\u95f45\u5206\u949f\uff09<\/li>\n\n\n\n<li>\u2022\u00a0<strong>nickName\uff1a<\/strong>\u00a0\u5fae\u4fe1\u7528\u6237\u6635\u79f0\uff08\u73b0\u5728\u7edf\u4e00\u8fd4\u56de\uff1a\u5fae\u4fe1\u7528\u6237\uff09<\/li>\n\n\n\n<li>\u2022\u00a0<strong>phoneCode\uff1a<\/strong>\u00a0\u8be6\u7ec6\u7528\u6237\u4fe1\u606fcode\uff0c\u540e\u53f0\u6839\u636e\u6b64code\u83b7\u53d6\u624b\u673a\u53f7\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u54cd\u5e94\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{<br>&nbsp; \"code\":&nbsp;200,<br>&nbsp; \"msg\":&nbsp;\"\u64cd\u4f5c\u6210\u529f\",<br>&nbsp; \"data\":&nbsp;{<br>&nbsp; &nbsp; \"token\":&nbsp;\"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiLlpb3mn7_lvIDoirE4OTE1IiwiZXhwIjoxNDY1MjI3MTMyOCwidXNlcmlkIjoxfQ.nB6ElZbUywh-yiHDNMJS8WqUpcLWCszVdvAMfySFxIM\",<br>&nbsp; &nbsp; \"nickName\":&nbsp;\"\u597d\u67ff\u5f00\u82b18915\"<br>&nbsp; },<br>&nbsp; \"operationTime\":<strong>&nbsp;null<\/strong><br>}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u5c0f\u7a0b\u5e8f\u73af\u5883\u642d\u5efa<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">\u5fc5\u8981\u914d\u7f6e<\/h3>\n\n\n\n<p>\u6d4b\u8bd5\u9636\u6bb5\u4f7f\u7528\u6d4b\u8bd5\u53f7\uff0c\u5728\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u540e\u53f0\u83b7\u53d6appId\u548c\u5c0f\u7a0b\u5e8f\u79d8\u94a5\uff0c\u524d\u7aef\u548c\u540e\u7aef\u90fd\u9700\u8981\u8fd9\u4e24\u4e2a\u53c2\u6570\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"485\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023834843-1024x485.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6570 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023834843-1024x485.png 1024w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023834843-300x142.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023834843-768x364.png 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023834843.png 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"485\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023834843-1024x485.png\" alt=\"\" class=\"wp-image-6570\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023834843-1024x485.png 1024w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023834843-300x142.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023834843-768x364.png 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023834843.png 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/noscript><\/figure>\n\n\n\n<p>\u57fa\u7840\u73af\u5883\u8bf4\u660e<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"724\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023853995-1024x724.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6571 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023853995-1024x724.png 1024w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023853995-300x212.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023853995-768x543.png 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023853995.png 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"724\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023853995-1024x724.png\" alt=\"\" class=\"wp-image-6571\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023853995-1024x724.png 1024w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023853995-300x212.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023853995-768x543.png 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023853995.png 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/noscript><\/figure>\n\n\n\n<p>\u672c\u5730\u5f00\u53d1\u5ffd\u7565https\u6821\u9a8c<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"743\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023905147-1024x743.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6572 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023905147-1024x743.png 1024w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023905147-300x218.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023905147-768x558.png 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023905147.png 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"743\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023905147-1024x743.png\" alt=\"\" class=\"wp-image-6572\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023905147-1024x743.png 1024w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023905147-300x218.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023905147-768x558.png 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023905147.png 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/noscript><\/figure>\n\n\n\n<p>\u4fee\u6539\u5c0f\u7a0b\u5e8f\u73af\u5883\u7684APPID\uff0c\u6539\u4e3a\u81ea\u5df1\u7533\u8bf7\u7684\u6d4b\u8bd5\u53f7APPID\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"702\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023919533-1024x702.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6573 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023919533-1024x702.png 1024w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023919533-300x206.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023919533-768x526.png 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023919533.png 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"702\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023919533-1024x702.png\" alt=\"\" class=\"wp-image-6573\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023919533-1024x702.png 1024w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023919533-300x206.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023919533-768x526.png 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023919533.png 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/noscript><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">\u529f\u80fd\u5b9e\u73b0<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b9e\u73b0\u601d\u8def<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"722\" height=\"1024\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024019911-722x1024.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6574 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024019911-722x1024.png 722w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024019911-212x300.png 212w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024019911-768x1089.png 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024019911.png 903w\" sizes=\"auto, (max-width: 722px) 100vw, 722px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"722\" height=\"1024\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024019911-722x1024.png\" alt=\"\" class=\"wp-image-6574\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024019911-722x1024.png 722w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024019911-212x300.png 212w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024019911-768x1089.png 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024019911.png 903w\" sizes=\"auto, (max-width: 722px) 100vw, 722px\" \/><\/noscript><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u63a7\u5236\u5c42<\/h3>\n\n\n\n<p>Controller\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>@PostMapping(\"\/login\")<\/strong><strong><br>@ApiOperation(\"\u5c0f\u7a0b\u5e8f\u767b\u5f55\")<\/strong><strong><br>public<\/strong>&nbsp;AjaxResult&nbsp;login(<strong>@RequestBody<\/strong>&nbsp;UserLoginRequestDto userLoginRequestDto){<br>&nbsp; &nbsp; LoginVo&nbsp;loginVo&nbsp;=&nbsp;familyMemberService.login(userLoginRequestDto);<strong><br>&nbsp; &nbsp; return<\/strong>&nbsp;success(loginVo);<br><br>}<\/code><\/pre>\n\n\n\n<p>UserLoginRequestDTO:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong>&nbsp;com.zzyl.nursing.dto;<strong><br>&nbsp;<br>import<\/strong>&nbsp;io.swagger.annotations.ApiModelProperty;<strong><br>import<\/strong>&nbsp;lombok.Data;<br>&nbsp;<br>\/**<br>&nbsp;* C\u7aef\u7528\u6237\u767b\u5f55<br>&nbsp;*\/<strong><br>@Data<\/strong><strong><br>public<\/strong><strong>&nbsp;class<\/strong>&nbsp;UserLoginRequestDto&nbsp;{<strong><br>&nbsp;<br>&nbsp; &nbsp; @ApiModelProperty(\"\u6635\u79f0\")<\/strong><strong><br>&nbsp; &nbsp; private<\/strong>&nbsp;String nickName;<strong><br>&nbsp;<br>&nbsp; &nbsp; @ApiModelProperty(\"\u767b\u5f55\u4e34\u65f6\u51ed\u8bc1\")<\/strong><strong><br>&nbsp; &nbsp; private<\/strong>&nbsp;String code;<strong><br>&nbsp;<br>&nbsp; &nbsp; @ApiModelProperty(\"\u624b\u673a\u53f7\u4e34\u65f6\u51ed\u8bc1\")<\/strong><strong><br>&nbsp; &nbsp; private<\/strong>&nbsp;String phoneCode;<br>}<\/code><\/pre>\n\n\n\n<p>LoginVo:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong>&nbsp;com.zzyl.nursing.vo;<strong><br>&nbsp;<br>import<\/strong>&nbsp;io.swagger.annotations.ApiModel;<strong><br>import<\/strong>&nbsp;io.swagger.annotations.ApiModelProperty;<strong><br>import<\/strong>&nbsp;lombok.Data;<br>&nbsp;<br>\/**<br>&nbsp;* LoginVO<br>&nbsp;*&nbsp;@author&nbsp;itheima<br>&nbsp;*\/<strong><br>@Data<\/strong><strong><br>@ApiModel(value = \"\u767b\u5f55\u5bf9\u8c61\")<\/strong><strong><br>public<\/strong><strong>&nbsp;class<\/strong>&nbsp;LoginVo&nbsp;{<strong><br>&nbsp;<br>&nbsp; &nbsp; @ApiModelProperty(value = \"JWT token\")<\/strong><strong><br>&nbsp; &nbsp; private<\/strong>&nbsp;String token;<strong><br>&nbsp;<br>&nbsp; &nbsp; @ApiModelProperty(value = \"\u6635\u79f0\")<\/strong><strong><br>&nbsp; &nbsp; private<\/strong>&nbsp;String nickName;<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e1a\u52a1\u5c42\u3010\u91cd\u8981\u3011<\/h3>\n\n\n\n<p>\u4e00\u822c\u50cf\u8fd9\u79cd\u4e09\u65b9\u63a5\u53e3\u8c03\u7528\uff0c\u901a\u5e38\u4f1a\u5c01\u88c5\u4e00\u4e2a\u5355\u72ec\u4e1a\u52a1\u4ee3\u7801\uff0c\u4f7f\u5176\u66f4\u901a\u7528\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u2022 \u83b7\u53d6\u7528\u6237openId<\/li>\n\n\n\n<li>\u2022 \u83b7\u53d6\u624b\u673a\u53f7<\/li>\n\n\n\n<li>\u2022 \u83b7\u53d6token\uff08\u83b7\u53d6\u624b\u673a\u53f7\u9700\u8981\uff09<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u5fae\u4fe1\u63a5\u53e3\u8c03\u7528-\u5355\u72ec\u5c01\u88c5<\/h3>\n\n\n\n<p>\u65b0\u589e<code>WeachatService<\/code>\u63a5\u53e3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong>&nbsp;com.zzyl.nursing.service;<strong><br>&nbsp;<br>public<\/strong><strong>&nbsp;interface<\/strong>&nbsp;WechatService&nbsp;{<br>&nbsp;<br>&nbsp; &nbsp; \/**<br>&nbsp; &nbsp; &nbsp;* \u83b7\u53d6openid<br>&nbsp; &nbsp; &nbsp;*&nbsp;@param&nbsp;code<br>&nbsp; &nbsp; &nbsp;*&nbsp;@return<br>&nbsp; &nbsp; &nbsp;*\/<strong><br>&nbsp; &nbsp; public<\/strong>&nbsp;String&nbsp;getOpenid(String code);<br>&nbsp;<br>&nbsp; &nbsp; \/**<br>&nbsp; &nbsp; &nbsp;* \u83b7\u53d6\u624b\u673a\u53f7<br>&nbsp; &nbsp; &nbsp;*&nbsp;@param&nbsp;detailCode<br>&nbsp; &nbsp; &nbsp;*&nbsp;@return<br>&nbsp; &nbsp; &nbsp;*\/<strong><br>&nbsp; &nbsp; public<\/strong>&nbsp;String&nbsp;getPhone(String detailCode);<br>}<\/code><\/pre>\n\n\n\n<p>\u65b0\u589e<code>WeachatServiceImpl<\/code>\u5b9e\u73b0\u7c7b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong>&nbsp;com.zzyl.nursing.service.impl;<strong><br>&nbsp;<br>import<\/strong>&nbsp;cn.hutool.core.util.ObjectUtil;<strong><br>import<\/strong>&nbsp;cn.hutool.http.HttpUtil;<strong><br>import<\/strong>&nbsp;cn.hutool.json.JSONObject;<strong><br>import<\/strong>&nbsp;cn.hutool.json.JSONUtil;<strong><br>import<\/strong>&nbsp;com.zzyl.nursing.service.WechatService;<strong><br>import<\/strong>&nbsp;org.springframework.beans.factory.annotation.Value;<strong><br>import<\/strong>&nbsp;org.springframework.stereotype.Service;<strong><br>&nbsp;<br>import<\/strong>&nbsp;java.util.HashMap;<strong><br>import<\/strong>&nbsp;java.util.Map;<strong><br>&nbsp;<br>@Service<\/strong><strong><br>public<\/strong><strong>&nbsp;class<\/strong>&nbsp;WechatServiceImpl<strong>&nbsp;implements<\/strong>&nbsp;WechatService&nbsp;{<br>&nbsp;<br>&nbsp;<br>&nbsp; &nbsp; \/\/ \u767b\u5f55<strong><br>&nbsp; &nbsp; private<\/strong><strong>&nbsp;static<\/strong><strong>&nbsp;final<\/strong>&nbsp;String&nbsp;REQUEST_URL&nbsp;=&nbsp;\"https:\/\/api.weixin.qq.com\/sns\/jscode2session?grant_type=authorization_code\";<br>&nbsp;<br>&nbsp; &nbsp; \/\/ \u83b7\u53d6token<strong><br>&nbsp; &nbsp; private<\/strong><strong>&nbsp;static<\/strong><strong>&nbsp;final<\/strong>&nbsp;String&nbsp;TOKEN_URL&nbsp;=&nbsp;\"https:\/\/api.weixin.qq.com\/cgi-bin\/token?grant_type=client_credential\";<br>&nbsp;<br>&nbsp; &nbsp; \/\/ \u83b7\u53d6\u624b\u673a\u53f7<strong><br>&nbsp; &nbsp; private<\/strong><strong>&nbsp;static<\/strong><strong>&nbsp;final<\/strong>&nbsp;String&nbsp;PHONE_REQUEST_URL&nbsp;=&nbsp;\"https:\/\/api.weixin.qq.com\/wxa\/business\/getuserphonenumber?access_token=\";<strong><br>&nbsp;<br>&nbsp;<br>&nbsp; &nbsp; @Value(\"${wechat.appId}\")<\/strong><strong><br>&nbsp; &nbsp; private<\/strong>&nbsp;String appid;<strong><br>&nbsp;<br>&nbsp; &nbsp; @Value(\"${wechat.appSecret}\")<\/strong><strong><br>&nbsp; &nbsp; private<\/strong>&nbsp;String secret;<br>&nbsp;<br>&nbsp;<br>&nbsp; &nbsp; \/**<br>&nbsp; &nbsp; &nbsp;* \u83b7\u53d6openid<br>&nbsp; &nbsp; &nbsp;*&nbsp;@param&nbsp;code<br>&nbsp; &nbsp; &nbsp;*&nbsp;@return<br>&nbsp; &nbsp; &nbsp;*\/<strong><br>&nbsp; &nbsp; @Override<\/strong><strong><br>&nbsp; &nbsp; public<\/strong>&nbsp;String&nbsp;getOpenid(String code)&nbsp;{<br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u83b7\u53d6\u516c\u5171\u53c2\u6570<br>&nbsp; &nbsp; &nbsp; &nbsp; Map&lt;String,Object&gt; paramMap = getAppConfig();<br>&nbsp; &nbsp; &nbsp; &nbsp; paramMap.put(\"js_code\",code);<br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp;result&nbsp;=&nbsp;HttpUtil.get(REQUEST_URL, paramMap);<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u662f\u4e00\u4e2amap<br>&nbsp; &nbsp; &nbsp; &nbsp; JSONObject&nbsp;jsonObject&nbsp;=&nbsp;JSONUtil.parseObj(result);<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u5224\u65ad\u63a5\u53e3\u54cd\u5e94\u662f\u5426\u51fa\u9519<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; if<\/strong>(ObjectUtil.isNotEmpty(jsonObject.getInt(\"errcode\"))){<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw<\/strong><strong>&nbsp;new<\/strong>&nbsp;RuntimeException(jsonObject.getStr(\"errmsg\"));<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp;openid&nbsp;=&nbsp;jsonObject.getStr(\"openid\");<strong><br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; return<\/strong>&nbsp;openid;<br>&nbsp; &nbsp; }<br>&nbsp;<br>&nbsp; &nbsp; \/**<br>&nbsp; &nbsp; &nbsp;* \u5c01\u88c5\u516c\u5171\u53c2\u6570<br>&nbsp; &nbsp; &nbsp;*&nbsp;@return<br>&nbsp; &nbsp; &nbsp;*\/<strong><br>&nbsp; &nbsp; private<\/strong>&nbsp;Map&lt;String, Object&gt;&nbsp;getAppConfig()&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; Map&lt;String, Object&gt; paramMap =<strong>&nbsp;new<\/strong>&nbsp;HashMap&lt;&gt;();<br>&nbsp; &nbsp; &nbsp; &nbsp; paramMap.put(\"appid\",appid);<br>&nbsp; &nbsp; &nbsp; &nbsp; paramMap.put(\"secret\",secret);<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; return<\/strong>&nbsp;paramMap;<br>&nbsp; &nbsp; }<br>&nbsp;<br>&nbsp; &nbsp; \/**<br>&nbsp; &nbsp; &nbsp;* \u83b7\u53d6\u624b\u673a\u53f7<br>&nbsp; &nbsp; &nbsp;*&nbsp;@param&nbsp;detailCode<br>&nbsp; &nbsp; &nbsp;*&nbsp;@return<br>&nbsp; &nbsp; &nbsp;*\/<strong><br>&nbsp; &nbsp; @Override<\/strong><strong><br>&nbsp; &nbsp; public<\/strong>&nbsp;String&nbsp;getPhone(String detailCode)&nbsp;{<br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp;token&nbsp;=&nbsp;getToken();<br>&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp;url&nbsp;=&nbsp;PHONE_REQUEST_URL+token;<br>&nbsp; &nbsp; &nbsp; &nbsp; Map&lt;String, Object&gt; paramMap =<strong>&nbsp;new<\/strong>&nbsp;HashMap&lt;&gt;();<br>&nbsp; &nbsp; &nbsp; &nbsp; paramMap.put(\"code\",detailCode);<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u53d1\u8d77\u8bf7\u6c42<br>&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp;result&nbsp;=&nbsp;HttpUtil.post(url, JSONUtil.toJsonStr(paramMap));<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u662f\u4e00\u4e2amap<br>&nbsp; &nbsp; &nbsp; &nbsp; JSONObject&nbsp;jsonObject&nbsp;=&nbsp;JSONUtil.parseObj(result);<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u5224\u65ad\u63a5\u53e3\u54cd\u5e94\u662f\u5426\u51fa\u9519<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; if<\/strong>(jsonObject.getInt(\"errcode\") !=&nbsp;0){<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw<\/strong><strong>&nbsp;new<\/strong>&nbsp;RuntimeException(jsonObject.getStr(\"errmsg\"));<br>&nbsp; &nbsp; &nbsp; &nbsp; }<strong><br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; return<\/strong>&nbsp;jsonObject.getJSONObject(\"phone_info\").getStr(\"phoneNumber\");<br>&nbsp; &nbsp; }<br>&nbsp;<br>&nbsp; &nbsp; \/**<br>&nbsp; &nbsp; &nbsp;* \u83b7\u53d6token<br>&nbsp; &nbsp; &nbsp;*&nbsp;@return<br>&nbsp; &nbsp; &nbsp;*\/<strong><br>&nbsp; &nbsp; private<\/strong>&nbsp;String&nbsp;getToken()&nbsp;{<br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; Map&lt;String, Object&gt; paramMap = getAppConfig();<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u53d1\u8d77\u8bf7\u6c42<br>&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp;result&nbsp;=&nbsp;HttpUtil.get(TOKEN_URL, paramMap);<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u662f\u4e00\u4e2amap<br>&nbsp; &nbsp; &nbsp; &nbsp; JSONObject&nbsp;jsonObject&nbsp;=&nbsp;JSONUtil.parseObj(result);<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u5224\u65ad\u63a5\u53e3\u54cd\u5e94\u662f\u5426\u51fa\u9519<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; if<\/strong>(ObjectUtil.isNotEmpty(jsonObject.getInt(\"errcode\"))){<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw<\/strong><strong>&nbsp;new<\/strong>&nbsp;RuntimeException(jsonObject.getStr(\"errmsg\"));<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp;token&nbsp;=&nbsp;jsonObject.getStr(\"access_token\");<strong><br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; return<\/strong>&nbsp;token;<br>&nbsp;<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u9700\u8981\u8bfb\u53d6\u83b7\u53d6<code>appId<\/code>\u548c<code>appSecret<\/code>\uff0c\u6240\u4ee5\u6211\u4eec\u5728<code>application.yml<\/code>\u914d\u7f6e\u5bf9\u4e8e\u914d\u7f6e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"504\" height=\"99\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024046964.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6575 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024046964.png 504w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024046964-300x59.png 300w\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"504\" height=\"99\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024046964.png\" alt=\"\" class=\"wp-image-6575\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024046964.png 504w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024046964-300x59.png 300w\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" \/><\/noscript><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u5fae\u4fe1\u767b\u5f55\u4e1a\u52a1\u5f00\u53d1<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**<br>&nbsp;* \u5fae\u4fe1\u767b\u5f55<br>&nbsp;*&nbsp;@param&nbsp;userLoginRequestDto<br>&nbsp;*&nbsp;@return<br>&nbsp;*\/<br>LoginVo&nbsp;login(UserLoginRequestDto userLoginRequestDto);<\/code><\/pre>\n\n\n\n<p>\u5b9e\u73b0\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>@Autowired<\/strong><strong><br>private<\/strong>&nbsp;WechatService wechatService;<strong><br>&nbsp;<br>@Autowired<\/strong><strong><br>private<\/strong>&nbsp;TokenService tokenService;<strong><br>&nbsp;<br>static<\/strong>&nbsp;List&lt;String&gt; DEFAULT_NICKNAME_PREFIX = ListUtil.of(\"\u751f\u6d3b\u66f4\u7f8e\u597d\",<br>&nbsp; &nbsp; &nbsp; &nbsp; \"\u5927\u6854\u5927\u5229\",<br>&nbsp; &nbsp; &nbsp; &nbsp; \"\u65e5\u5bcc\u4e00\u65e5\",<br>&nbsp; &nbsp; &nbsp; &nbsp; \"\u597d\u67ff\u5f00\u82b1\",<br>&nbsp; &nbsp; &nbsp; &nbsp; \"\u67ff\u67ff\u5982\u610f\",<br>&nbsp; &nbsp; &nbsp; &nbsp; \"\u4e00\u6930\u66b4\u5bcc\",<br>&nbsp; &nbsp; &nbsp; &nbsp; \"\u5927\u67da\u6240\u4e3a\",<br>&nbsp; &nbsp; &nbsp; &nbsp; \"\u6768\u6885\u5410\u6c14\",<br>&nbsp; &nbsp; &nbsp; &nbsp; \"\u5929\u751f\u8354\u679d\"<br>);<br>&nbsp;<br>\/**<br>&nbsp;* \u5c0f\u7a0b\u5e8f\u7aef\u767b\u5f55<br>&nbsp;*&nbsp;@param&nbsp;userLoginRequestDto<br>&nbsp;*&nbsp;@return<br>&nbsp;*\/<strong><br>@Override<\/strong><strong><br>public<\/strong>&nbsp;LoginVo&nbsp;login(UserLoginRequestDto userLoginRequestDto)&nbsp;{<br>&nbsp; &nbsp; \/\/1.\u8c03\u7528\u5fae\u4fe1api,\u6839\u636ecode\u83b7\u53d6openId<br>&nbsp; &nbsp; String&nbsp;openId&nbsp;=&nbsp;wechatService.getOpenid(userLoginRequestDto.getCode());<br>&nbsp;<br>&nbsp; &nbsp; \/\/2.\u6839\u636eopenId\u67e5\u8be2\u7528\u6237<br>&nbsp; &nbsp; FamilyMember&nbsp;familyMember&nbsp;=&nbsp;getOne(Wrappers.&lt;FamilyMember&gt;lambdaQuery(FamilyMember.class)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .eq(FamilyMember::getOpenId, openId));<br>&nbsp;<br>&nbsp; &nbsp; \/\/3.\u5982\u679c\u7528\u6237\u4e3a\u7a7a\uff0c\u5219\u65b0\u589e<strong><br>&nbsp; &nbsp; if<\/strong>&nbsp;(ObjectUtil.isEmpty(familyMember)) {<br>&nbsp; &nbsp; &nbsp; &nbsp; familyMember = FamilyMember.builder().openId(openId).build();<br>&nbsp; &nbsp; }<br>&nbsp;<br>&nbsp; &nbsp; \/\/4.\u8c03\u7528\u5fae\u4fe1api\u83b7\u53d6\u7528\u6237\u7ed1\u5b9a\u7684\u624b\u673a\u53f7<br>&nbsp; &nbsp; String&nbsp;phone&nbsp;=&nbsp;wechatService.getPhone(userLoginRequestDto.getPhoneCode());<br>&nbsp;<br>&nbsp; &nbsp; \/\/5.\u4fdd\u5b58\u6216\u4fee\u6539\u7528\u6237<br>&nbsp; &nbsp; saveOrUpdateFamilyMember(familyMember, phone);<br>&nbsp;<br>&nbsp; &nbsp; \/\/6.\u5c06\u7528\u6237id\u5b58\u5165token,\u8fd4\u56de<br>&nbsp; &nbsp; Map&lt;String, Object&gt; claims =<strong>&nbsp;new<\/strong>&nbsp;HashMap&lt;&gt;();<br>&nbsp; &nbsp; claims.put(\"userId\", familyMember.getId());<br>&nbsp; &nbsp; claims.put(\"userName\", familyMember.getName());<br>&nbsp;<br>&nbsp; &nbsp; String&nbsp;token&nbsp;=&nbsp;tokenService.createToken(claims);<br>&nbsp; &nbsp; LoginVo&nbsp;loginVo&nbsp;=<strong>&nbsp;new<\/strong>&nbsp;LoginVo();<br>&nbsp; &nbsp; loginVo.setToken(token);<br>&nbsp; &nbsp; loginVo.setNickName(familyMember.getName());<strong><br>&nbsp; &nbsp; return<\/strong>&nbsp;loginVo;<br>}<br>&nbsp;<br>\/**<br>&nbsp;* \u4fdd\u5b58\u6216\u4fee\u6539\u5ba2\u6237<br>&nbsp;*&nbsp;@param&nbsp;member<br>&nbsp;*&nbsp;@param&nbsp;phone<br>&nbsp;*\/<strong><br>private<\/strong><strong>&nbsp;void<\/strong>&nbsp;saveOrUpdateFamilyMember(FamilyMember member, String phone)&nbsp;{<br>&nbsp;<br>&nbsp; &nbsp; \/\/1.\u5224\u65ad\u53d6\u5230\u7684\u624b\u673a\u53f7\u4e0e\u6570\u636e\u5e93\u4e2d\u4fdd\u5b58\u7684\u624b\u673a\u53f7\u4e0d\u4e00\u6837<strong><br>&nbsp; &nbsp; if<\/strong>(ObjectUtil.notEqual(phone, member.getPhone())){<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u8bbe\u7f6e\u624b\u673a\u53f7<br>&nbsp; &nbsp; &nbsp; &nbsp; member.setPhone(phone);<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; \/\/2.\u5224\u65adid\u5b58\u5728<strong><br>&nbsp; &nbsp; if<\/strong>&nbsp;(ObjectUtil.isNotEmpty(member.getId())) {<br>&nbsp; &nbsp; &nbsp; &nbsp; updateById(familyMember);<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; return<\/strong>;<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; \/\/3.\u4fdd\u5b58\u65b0\u7684\u7528\u6237<br>&nbsp; &nbsp; \/\/\u968f\u673a\u7ec4\u88c5\u6635\u79f0\uff0c\u8bcd\u7ec4+\u624b\u673a\u53f7\u540e\u56db\u4f4d<br>&nbsp; &nbsp; String&nbsp;nickName&nbsp;=&nbsp;DEFAULT_NICKNAME_PREFIX.get((int) (Math.random() * DEFAULT_NICKNAME_PREFIX.size()))<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + StringUtils.substring(member.getPhone(),&nbsp;7);<br>&nbsp;<br>&nbsp; &nbsp; member.setName(nickName);<br>&nbsp; &nbsp; save(member);<br>}<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5c0f\u7a0b\u5e8f\u6240\u6709\u8bf7\u6c42\u4e0d\u8d70\u540e\u53f0\u7684\u7528\u6237\uff0c\u6240\u4ee5\u5728\u65b0\u589e\u6216\u4fee\u6539\u7684\u65f6\u5019\uff0c\u4e0d\u9700\u8981\u81ea\u52a8\u586b\u5145\u521b\u5efa\u4eba\u548c\u4fee\u6539\u4eba\uff0c\u4fee\u6539MP\u7684\u81ea\u52a8\u586b\u5145\u3002<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong>&nbsp;com.zzyl.framework.interceptor;<strong><br>&nbsp;<br>import<\/strong>&nbsp;com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;<strong><br>import<\/strong>&nbsp;com.zzyl.common.core.domain.model.LoginUser;<strong><br>import<\/strong>&nbsp;com.zzyl.common.utils.SecurityUtils;<strong><br>import<\/strong>&nbsp;lombok.SneakyThrows;<strong><br>import<\/strong>&nbsp;org.apache.commons.lang3.ObjectUtils;<strong><br>import<\/strong>&nbsp;org.apache.ibatis.reflection.MetaObject;<strong><br>import<\/strong>&nbsp;org.springframework.beans.factory.annotation.Autowired;<strong><br>import<\/strong>&nbsp;org.springframework.stereotype.Component;<strong><br>&nbsp;<br>import<\/strong>&nbsp;javax.servlet.http.HttpServletRequest;<strong><br>import<\/strong>&nbsp;java.util.ArrayList;<strong><br>import<\/strong>&nbsp;java.util.Date;<strong><br>import<\/strong>&nbsp;java.util.List;<strong><br>&nbsp;<br>@Component<\/strong><strong><br>public<\/strong><strong>&nbsp;class<\/strong>&nbsp;MyMetaObjectHandler<strong>&nbsp;implements<\/strong>&nbsp;MetaObjectHandler&nbsp;{<strong><br>&nbsp;<br>&nbsp; &nbsp; @Autowired<\/strong><strong><br>&nbsp; &nbsp; private<\/strong>&nbsp;HttpServletRequest request;<strong><br>&nbsp;<br>&nbsp; &nbsp; @SneakyThrows<\/strong><strong><br>&nbsp; &nbsp; public<\/strong>&nbsp;boolean&nbsp;isExclude()&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp;requestURI&nbsp;=&nbsp;request.getRequestURI();<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; if<\/strong>(requestURI.startsWith(\"\/member\")){<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return<\/strong><strong>&nbsp;false<\/strong>;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; return<\/strong><strong>&nbsp;true<\/strong>;<br>&nbsp; &nbsp; }<strong><br>&nbsp;<br>&nbsp; &nbsp; @Override<\/strong><strong><br>&nbsp; &nbsp; public<\/strong><strong>&nbsp;void<\/strong>&nbsp;insertFill(MetaObject metaObject)&nbsp;{<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; this<\/strong>.strictInsertFill(metaObject,&nbsp;\"createTime\", Date.class,<strong>&nbsp;new<\/strong>&nbsp;Date());<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; if<\/strong>(isExclude()){<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this<\/strong>.strictInsertFill(metaObject,&nbsp;\"createBy\", String.class, loadUserId() +&nbsp;\"\");<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp;<br>&nbsp; &nbsp; }<strong><br>&nbsp;<br>&nbsp; &nbsp; @Override<\/strong><strong><br>&nbsp; &nbsp; public<\/strong><strong>&nbsp;void<\/strong>&nbsp;updateFill(MetaObject metaObject)&nbsp;{<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; this<\/strong>.setFieldValByName(\"updateTime\",<strong>&nbsp;new<\/strong>&nbsp;Date(), metaObject);<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; if<\/strong>(isExclude()){<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this<\/strong>.setFieldValByName(\"updateBy\", loadUserId() +&nbsp;\"\", metaObject);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp;<br>&nbsp; &nbsp; }<br>&nbsp;<br>&nbsp; &nbsp; \/**<br>&nbsp; &nbsp; &nbsp;* \u83b7\u53d6\u5f53\u524d\u767b\u5f55\u4eba\u7684ID<br>&nbsp; &nbsp; &nbsp;*<br>&nbsp; &nbsp; &nbsp;*&nbsp;@return<br>&nbsp; &nbsp; &nbsp;*\/<strong><br>&nbsp; &nbsp; private<\/strong><strong>&nbsp;static<\/strong>&nbsp;Long&nbsp;loadUserId()&nbsp;{<br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u83b7\u53d6\u5f53\u524d\u767b\u5f55\u4eba\u7684id<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; try<\/strong>&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LoginUser&nbsp;loginUser&nbsp;=&nbsp;SecurityUtils.getLoginUser();<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if<\/strong>&nbsp;(ObjectUtils.isNotEmpty(loginUser)) {<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return<\/strong>&nbsp;loginUser.getUserId();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return<\/strong>&nbsp;1L;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<strong>&nbsp;catch<\/strong>&nbsp;(Exception e) {<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return<\/strong>&nbsp;1L;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u6821\u9a8cToken<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">\u601d\u8def\u5206\u6790<\/h3>\n\n\n\n<p>\u7528\u6237\u767b\u5f55\u6210\u529f\u4e4b\u540e\uff0c\u8fd4\u56de\u524d\u7aef\u4e00\u4e2atoken\uff0c\u8fd9\u4e2atoken\u5c31\u662f\u7528\u6765\u9a8c\u8bc1\u7528\u6237\u4fe1\u606f\u7684\uff0c\u7528\u6237\u70b9\u51fb\u5c0f\u7a0b\u5e8f\u4e2d\u7684\u5176\u4ed6\u64cd\u4f5c\uff0c\u5c31\u4f1atoken\u643a\u5e26\u8bf7\u6c42\u5934<code>header<\/code>\u4e2d\uff0c\u65b9\u4fbf\u540e\u53f0\u53bb\u9a8c\u8bc1\u83b7\u53d6\u7528\u6237\u4fe1\u606f\uff0c\u6d41\u7a0b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"475\" height=\"528\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024127124.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6577 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024127124.png 475w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024127124-270x300.png 270w\" sizes=\"auto, (max-width: 475px) 100vw, 475px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"475\" height=\"528\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024127124.png\" alt=\"\" class=\"wp-image-6577\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024127124.png 475w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024127124-270x300.png 270w\" sizes=\"auto, (max-width: 475px) 100vw, 475px\" \/><\/noscript><\/figure>\n\n\n\n<p>\u5982\u679c\u8981\u9a8c\u8bc1\u7528\u6237\u7684token\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u62e6\u622a\u5668\u5b9e\u73b0\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"408\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024136427-1024x408.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6578 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024136427-1024x408.png 1024w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024136427-300x119.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024136427-768x306.png 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024136427.png 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"408\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024136427-1024x408.png\" alt=\"\" class=\"wp-image-6578\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024136427-1024x408.png 1024w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024136427-300x119.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024136427-768x306.png 768w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024136427.png 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/noscript><\/figure>\n\n\n\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong>&nbsp;com.zzyl.framework.interceptor;<strong><br>&nbsp;<br>import<\/strong>&nbsp;cn.hutool.core.map.MapUtil;<strong><br>import<\/strong>&nbsp;cn.hutool.core.util.ObjectUtil;<strong><br>import<\/strong>&nbsp;com.zzyl.common.exception.base.BaseException;<strong><br>import<\/strong>&nbsp;com.zzyl.common.utils.StringUtils;<strong><br>import<\/strong>&nbsp;com.zzyl.common.utils.UserThreadLocal;<strong><br>import<\/strong>&nbsp;com.zzyl.framework.web.service.TokenService;<strong><br>import<\/strong>&nbsp;org.springframework.beans.factory.annotation.Autowired;<strong><br>import<\/strong>&nbsp;org.springframework.stereotype.Component;<strong><br>import<\/strong>&nbsp;org.springframework.web.method.HandlerMethod;<strong><br>import<\/strong>&nbsp;org.springframework.web.servlet.HandlerInterceptor;<strong><br>&nbsp;<br>import<\/strong>&nbsp;javax.servlet.http.HttpServletRequest;<strong><br>import<\/strong>&nbsp;javax.servlet.http.HttpServletResponse;<strong><br>import<\/strong>&nbsp;java.util.Map;<strong><br>&nbsp;<br>@Component<\/strong><strong><br>public<\/strong><strong>&nbsp;class<\/strong>&nbsp;MemberInterceptor<strong>&nbsp;implements<\/strong>&nbsp;HandlerInterceptor&nbsp;{<strong><br>&nbsp;<br>&nbsp; &nbsp; @Autowired<\/strong><strong><br>&nbsp; &nbsp; private<\/strong>&nbsp;TokenService tokenService;<strong><br>&nbsp;<br>&nbsp; &nbsp; @Override<\/strong><strong><br>&nbsp; &nbsp; public<\/strong>&nbsp;boolean&nbsp;preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)<strong>&nbsp;throws<\/strong>&nbsp;Exception {<br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u5224\u65ad\u5f53\u524d\u8bf7\u6c42\u662f\u5426\u662fhandler()<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; if<\/strong>(!(handler<strong>&nbsp;instanceof<\/strong>&nbsp;HandlerMethod)){<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return<\/strong><strong>&nbsp;true<\/strong>;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u83b7\u53d6token<br>&nbsp; &nbsp; &nbsp; &nbsp; String&nbsp;token&nbsp;=&nbsp;request.getHeader(\"authorization\");<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; if<\/strong>(StringUtils.isEmpty(token)){<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw<\/strong><strong>&nbsp;new<\/strong>&nbsp;BaseException(\"\u8ba4\u8bc1\u5931\u8d25\");<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u89e3\u6790token<br>&nbsp; &nbsp; &nbsp; &nbsp; Map&lt;String, Object&gt; claims = &nbsp;tokenService.parseToken(token);<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; if<\/strong>(ObjectUtil.isEmpty(claims)){<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw<\/strong><strong>&nbsp;new<\/strong>&nbsp;BaseException(\"\u8ba4\u8bc1\u5931\u8d25\");<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; Long&nbsp;userId&nbsp;=&nbsp;MapUtil.get(claims,&nbsp;\"userId\", Long.class);<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; if<\/strong>(ObjectUtil.isEmpty(userId)){<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw<\/strong><strong>&nbsp;new<\/strong>&nbsp;BaseException(\"\u8ba4\u8bc1\u5931\u8d25\");<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u628a\u6570\u636e\u5b58\u50a8\u5230\u7ebf\u7a0b\u4e2d<br>&nbsp; &nbsp; &nbsp; &nbsp; UserThreadLocal.set(userId);<strong><br>&nbsp; &nbsp; &nbsp; &nbsp; return<\/strong><strong>&nbsp;true<\/strong>;<br>&nbsp;<br>&nbsp; &nbsp; }<strong><br>&nbsp;<br>&nbsp; &nbsp; @Override<\/strong><strong><br>&nbsp; &nbsp; public<\/strong><strong>&nbsp;void<\/strong>&nbsp;afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)<strong>&nbsp;throws<\/strong>&nbsp;Exception {<br>&nbsp; &nbsp; &nbsp; &nbsp; UserThreadLocal.remove();<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<p>\u4f7f\u62e6\u622a\u5668\u751f\u6548\uff08<code>WebMvcConfigurer<\/code>\u5b9e\u73b0\u7c7b\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**<br>&nbsp;* \u81ea\u5b9a\u4e49\u62e6\u622a\u89c4\u5219<br>&nbsp;*\/<strong><br>@Override<\/strong><strong><br>public<\/strong><strong>&nbsp;void<\/strong>&nbsp;addInterceptors(InterceptorRegistry registry)<br>{<br>&nbsp; &nbsp; registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns(\"\/**\");<br>&nbsp; &nbsp; registry.addInterceptor(membersInterceptor).excludePathPatterns(EXCLUDE_PATH_PATTERNS).addPathPatterns(\"\/member\/**\");<br>}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u603b\u7ed3<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u2022\u00a0<code>openId<\/code>\u662f\u7528\u6237\u5728\u8fd9\u4e2a\u5c0f\u7a0b\u5e8f\u7684\u552f\u4e00\u6807\u8bc6\uff0c<code>unionId<\/code>\u662f\u5fae\u4fe1\u662f\u4f60\u5728\u5fae\u4fe1\u5f00\u53d1\u5e73\u53f0\u7684\u552f\u4e00\u6807\u8bc6\uff0c\u5c31\u662f\u591a\u4e2a\u5c0f\u7a0b\u5e8f\u4e2d\u4f60\u7684<code>unionId<\/code>\u90fd\u662f\u4e00\u6837\u7684\u3002<\/li>\n\n\n\n<li>\u2022 \u524d\u7aef<code>wx.login<\/code>\u83b7\u53d6\u4e34\u65f6\u767b\u5f55code\uff0c\u4f20\u7ed9\u540e\u7aef\uff0c\u540e\u7aef\u7528\u6765\u6362\u53d6<code>openId<\/code>\u3002<\/li>\n\n\n\n<li>\u2022 \u83b7\u53d6\u624b\u673a\u53f7\u9700\u8981\u5148\u83b7\u53d6token\uff0c\u7136\u540e\u518d\u53bb\u83b7\u53d6\u624b\u673a\u53f7\u3002<\/li>\n<\/ul>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u7a0b\u5e8f\u767b\u5f55\u5728\u5f00\u53d1\u4e2d\u662f\u6700\u5e38\u89c1\u7684\u9700\u6c42\uff0c\u54ea\u6015\u5c0f\u7a0b\u5e8f\u767b\u5f55\u4e0d\u662f\u4f60\u505a\uff0c\u4f60\u8fd8\u662f\u8981\u4e86\u89e3\u4e00\u4e0b\u6d41\u7a0b\uff0c\u540e\u7eed\u90fd\u8981\u4f7f\u7528\u5230openId\u548cunionId\uff0c\u4f60\u9700\u8981 &#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":[7],"tags":[],"class_list":["post-6565","post","type-post","status-publish","format-standard","hentry","category-spring-boot"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023613719.png","id":"image1"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023634164.png","id":"image2"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023634164.png","id":"image3"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023720853.png","id":"image4"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023720853.png","id":"image5"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023748614.png","id":"image6"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023748614.png","id":"image7"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023834843-1024x485.png","id":"image8"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023834843-1024x485.png","id":"image9"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023853995-1024x724.png","id":"image10"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023853995-1024x724.png","id":"image11"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023905147-1024x743.png","id":"image12"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023905147-1024x743.png","id":"image13"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023919533-1024x702.png","id":"image14"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929023919533-1024x702.png","id":"image15"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024019911-722x1024.png","id":"image16"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024019911-722x1024.png","id":"image17"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024046964.png","id":"image18"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024046964.png","id":"image19"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024127124.png","id":"image20"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024127124.png","id":"image21"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024136427-1024x408.png","id":"image22"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929024136427-1024x408.png","id":"image23"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Spring Boot","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":190,"next_post_id":6595,"next_post_title":"SpringBoot \u5b9e\u73b0\u591a\u79cd\u6765\u6e90\u7684 Zip \u591a\u5c42\u76ee\u5f55\u6253\u5305\u4e0b\u8f7d\uff08\u672c\u5730\u6587\u4ef6&amp;HTTP\u6df7\u5408\uff09","previous_post_id":6588,"previous_post_title":"SpringBoot+Thumbnailator\u7b49\u4e8eJava\u754c\u7684\u7f8e\u56fe\u79c0\u79c0\uff0c\u7f29\u56fe\uff0c\u6c34\u5370\uff0cgif\u62c6\u5e27\u538b\u7f29","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6565","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=6565"}],"version-history":[{"count":2,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6565\/revisions"}],"predecessor-version":[{"id":6579,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6565\/revisions\/6579"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=6565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=6565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=6565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}