{"id":1158,"date":"2024-03-21T20:35:36","date_gmt":"2024-03-21T12:35:36","guid":{"rendered":"http:\/\/ericw.top\/?p=1158"},"modified":"2024-04-01T11:15:52","modified_gmt":"2024-04-01T03:15:52","slug":"%e7%9f%ad%e4%bf%a1%e6%a1%88%e4%be%8b-vuespringboot%e5%89%8d%e5%90%8e%e7%ab%afdemo","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=1158","title":{"rendered":"\u77ed\u4fe1\u6848\u4f8b &#8211; Vue+SpringBoot\u524d\u540e\u7aefdemo"},"content":{"rendered":"\n<p>\u4eca\u5929\u6765\u65f6\u7ed9\u5e03\u7f6e\u4e86\u4e00\u4e2a\u521d\u5b66\u8005\u5c0f\u4efb\u52a1\uff0c\u505a\u4e00\u4e2a\u7b80\u5355\u7684\u77ed\u4fe1\u9a8c\u8bc1demo<br>\u9700\u8981\u7528\u5230\u7684\u6280\u672f\u6709<code class=\"prettyprint\" >Vue <\/code> +  <code class=\"prettyprint\" >SpringBoot<\/code>  +  <code class=\"prettyprint\" >\u963f\u91cc\u4e91\u77ed\u4fe1\u670d\u52a1<\/code><\/p>\n\n\n\n<p>\u53ef\u80fd\u9879\u76ee\u6bd4\u8f83<strong>\u7b80\u5355<\/strong>\uff0c\u770b\u8d77\u6765\u6bd4\u8f83\u504f\u5411<strong>\u65b0\u624b<\/strong>\uff0c\u9002\u5408<strong>\u4f4e\u57fa\u7840<\/strong>\u7684<code class=\"prettyprint\" >vue+springboot<\/code>\u5165\u95e8\u5236\u4f5c\uff0c\u5e76\u4e14\u6ca1\u6709\u8fdb\u884c\u4f18\u5316\u548c\u968f\u673a\u6570\u636e\u3001\u6570\u636e\u4fdd\u5b58\u7b49\u64cd\u4f5c......(\u61d2\u5f97\u5f04\u4e86)<\/p>\n\n\n\n<p>\u4e0b\u9762\u5c31\u662f\u5728\u5236\u4f5c\u8fd9\u4e2a\u5c0fdemo\u7684\u6d41\u7a0b\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-0\">\u963f\u91cc\u4e91\u77ed\u4fe1\u670d\u52a1\u6d41\u7a0b<\/h2>\n\n\n\n<p><strong>1\u3001\u9996\u5148\uff0c\u6211\u4eec\u8981\u6709\u4e00\u4e2a\u6709\u4f59\u989d\u7684\u963f\u91cc\u4e91\u77ed\u4fe1\u670d\u52a1\uff08<\/strong>\u5728\u6211\u8fd9\u91cc\uff0c\u8001\u5e08\u7ed9\u6211\u63d0\u4f9b\u4e86\u516c\u53f8\u8d26\u53f7\u4f7f\u7528\uff09<br>\uff08\u60a8\u4e5f\u53ef\u4ee5\u5728\u7f51\u4e0a\u641c\u7d22\u6559\u7a0b\uff0c\u53ef\u4ee5\u7ed9\u60a8\u81ea\u5df1\u7684\u8d26\u53f7\u7533\u8bf7\u514d\u8d39\u7684\u77ed\u4fe1\u4f7f\u7528\u989d\u5ea6\uff09<\/p>\n\n\n\n<p><strong>2\u3001\u6211\u4eec\u8981\u5728\u81ea\u5df1\u7684\u963f\u91cc\u4e91\u8d26\u6237\u4e0a\uff0c\u5f00\u542f\u4e00\u4e2aAccessKey\u5b50\u7528\u6237\u548c\u7528\u6237\u7ec4\uff0c\u5e76\u4e14\u7ed9\u8fd9\u4e2a\u6211\u4eec\u521a\u521a\u521b\u5efa\u7684\u7528\u6237\u7ec4\u6dfb\u52a0sms\u77ed\u4fe1\u670d\u52a1\u6743\u9650<\/strong><\/p>\n\n\n\n<p>\u8be6\u7ec6\u64cd\u4f5c\u6b65\u9aa4:<\/p>\n\n\n\n<p>1.\u8fdb\u5165AccessKey\u7ba1\u7406\u9875\u9762<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"778\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-1-1024x778.png\" alt=\"\" class=\"wp-image-1175\" style=\"width:562px;height:auto\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-1-1024x778.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-1-300x228.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-1-768x584.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-1-1536x1168.png 1536w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-1.png 1584w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>2.\u521b\u5efa\u4e00\u4e2a\u6211\u4eec\u4f7f\u7528\u7684\u5b50\u7528\u6237<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"493\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-4-1024x493.png\" alt=\"\" class=\"wp-image-1178\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-4-1024x493.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-4-300x145.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-4-768x370.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-4-1536x740.png 1536w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-4.png 1584w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>3.\u521b\u5efa\u4e00\u4e2a\u7528\u6237\u7ec4\uff0c\u7528\u4e8e\u6211\u4eec\u5b66\u4e60\u4f7f\u7528<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"423\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-2-1024x423.png\" alt=\"\" class=\"wp-image-1176\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-2-1024x423.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-2-300x124.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-2-768x317.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-2-1536x634.png 1536w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-2.png 1584w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>4.\u5c06\u6211\u4eec\u521a\u521a\u521b\u5efa\u7684\u5b50\u7528\u6237\u6dfb\u52a0\u5230\u6211\u4eec\u7684\u7528\u6237\u7ec4\u91cc\u9762<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"779\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-3-1024x779.png\" alt=\"\" class=\"wp-image-1177\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-3-1024x779.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-3-300x228.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-3-768x584.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-3-1536x1168.png 1536w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-3.png 1584w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>5.\u7ed9\u6211\u4eec\u7684\u7528\u6237\u7ec4\u65b0\u589e\u4e00\u4e2a\u6743\u9650\u7ba1\u7406\uff0c\u627e\u5230sms\u7ba1\u7406\u77ed\u4fe1\u670d\u52a1\u7684\u6743\u9650<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"887\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-5-1024x887.png\" alt=\"\" class=\"wp-image-1179\" style=\"width:641px;height:auto\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-5-1024x887.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-5-300x260.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-5-768x665.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-5-1536x1330.png 1536w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-5.png 1584w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>6.\u63a5\u4e0b\u6765\u70b9\u51fb \u7528\u6237 --  \u7136\u540e\u70b9\u51fb\u8fdb\u5165\u6211\u4eec\u521a\u521a\u7684\u7528\u6237\u4e3b\u9875\uff0c\u5f80\u4e0b\u6ed1\uff0c\u9009\u62e9\u521b\u5efaAccessKey\uff0c\u7136\u540e\u4f1a\u968f\u673a\u751f\u6210\u4e00\u6bb5ID\u548c\u5bc6\u7801\uff0c\u6211\u4eec\u9700\u8981\u8bb0\u4f4f\u8fd9\u4e2aID\u548c\u5bc6\u7801\uff0c\u4e4b\u540e\u8981\u7528\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"562\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-6-1024x562.png\" alt=\"\" class=\"wp-image-1180\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-6-1024x562.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-6-300x165.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-6-768x421.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-6-1536x842.png 1536w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-6.png 1579w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>3\u3001\u63a5\u4e0b\u6765\u6211\u4eec\u8fdb\u5165SMS\u77ed\u4fe1\u670d\u52a1\u9875\u9762\uff0c\u5f00\u901a\u670d\u52a1\uff0c\u7136\u540e\u8fdb\u5165\u5feb\u901f\u5b66\u4e60\u548c\u6d4b\u8bd5\uff0c\u9009\u62e9API\u53d1\u9001\u6d4b\u8bd5\uff0c\u9009\u62e9\u7ed1\u5b9a\u6d4b\u8bd5\u624b\u673a\u53f7\u7801\uff0c\u4e4b\u540e\u53ef\u4ee5\u6dfb\u52a0\u6211\u4eec\u7684\u6d4b\u8bd5\u6a21\u677f\u6216\u8005\u60a8\u81ea\u5df1\u7533\u8bf7\u4e00\u4e2a\u81ea\u5b9a\u4e49\u6a21\u677f\uff0c\u8fd9\u91cc\u6211\u4eec\u5c31\u7528\u4e13\u7528\u6d4b\u8bd5\u6a21\u677f\u6765\u4f7f\u7528<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"990\" height=\"1024\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-7-990x1024.png\" alt=\"\" class=\"wp-image-1181\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-7-990x1024.png 990w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-7-290x300.png 290w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-7-768x794.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-7.png 1478w\" sizes=\"(max-width: 990px) 100vw, 990px\" \/><\/figure>\n\n\n\n<p><strong>4\u3001\u8fdb\u5165API\u6d4b\u8bd5\u9875\u9762\uff0c\u5de6\u8fb9\u680f\u4f1a\u6709\u5404\u79cd\u6d4b\u8bd5\u529f\u80fd\u9009\u62e9\uff0c\u5927\u5bb6\u53ef\u4ee5\u81ea\u884c\u63a2\u7d22\uff0c\u7136\u540e\u4e2d\u95f4\u586b\u5199\u6d4b\u8bd5\u53c2\u6570\uff0c\u6211\u4eec\u81ea\u5df1\u586b\u5199\u5c31\u53ef\u4ee5\uff0c\u4e4b\u540e\u5728\u53f3\u8fb9\u9009\u62e9SDK\u793a\u4f8b\uff0c\u6211\u4eec\u76f4\u63a5\u590d\u5236\u4f7f\u7528\u5373\u53ef<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"570\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-8-1024x570.png\" alt=\"\" class=\"wp-image-1182\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-8-1024x570.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-8-300x167.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-8-768x427.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-8-1536x855.png 1536w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-8-2048x1140.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-1\">SpringBoot\u540e\u7aef\u670d\u52a1\u6d41\u7a0b<\/h2>\n\n\n\n<p><strong>5\u3001\u5c06\u6211\u4eec\u590d\u5236\u7684\u4ee3\u7801\u653e\u5230\u4e00\u4e2a\u65b0\u7684SpringBoot\u9879\u76ee\u4e2d\uff0c\u8fd9\u4e2a\u9879\u76ee\u6211\u4eec\u91c7\u7528\u7684\u662fmaven\u4f9d\u8d56\u5bfc\u5165<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;dependencies&gt;\n&lt;!-- springboot web\u670d\u52a1\u4f9d\u8d56 --&gt;\n&lt;dependency&gt;\n&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n&lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;!-- springboot \u6d4b\u8bd5\u670d\u52a1\u4f9d\u8d56 --&gt;\n&lt;dependency&gt;\n&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n&lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;\n&lt;scope&gt;test&lt;\/scope&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;!-- \u963f\u91cc\u4e91SDK\u670d\u52a1\u4f9d\u8d56 --&gt;\n&lt;dependency&gt;\n&lt;groupId&gt;com.aliyun&lt;\/groupId&gt;\n&lt;artifactId&gt;aliyun-java-sdk-core&lt;\/artifactId&gt;\n&lt;version&gt;4.1.0&lt;\/version&gt;\n&lt;\/dependency&gt;\n\n\n&lt;!-- fastjson\u5e93\u4f9d\u8d56 \u8f6cJSON\u5b57\u7b26\u4e32\u4f7f\u7528 --&gt;\n&lt;dependency&gt;\n&lt;groupId&gt;com.alibaba&lt;\/groupId&gt;\n&lt;artifactId&gt;fastjson&lt;\/artifactId&gt;\n&lt;version&gt;1.2.62&lt;\/version&gt;\n&lt;\/dependency&gt;\n&lt;\/dependencies&gt;\n<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u4e00\u822c\u4f1a\u5728\u6211\u4eec\u9879\u76ee\u7684\u6d4b\u8bd5\u7c7b\u4e2d\u6d4b\u8bd5\u4f7f\u7528:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >import com.alibaba.fastjson.JSONObject;\nimport com.aliyuncs.CommonRequest;\nimport com.aliyuncs.CommonResponse;\nimport com.aliyuncs.DefaultAcsClient;\nimport com.aliyuncs.IAcsClient;\nimport com.aliyuncs.exceptions.ClientException;\nimport com.aliyuncs.exceptions.ServerException;\nimport com.aliyuncs.http.MethodType;\nimport com.aliyuncs.profile.DefaultProfile;\nimport org.junit.jupiter.api.Test;\nimport org.springframework.boot.test.context.SpringBootTest;\n \nimport java.util.HashMap;\n \n@SpringBootTest\nclass DemoApplicationTests {\n \n    @Test\n    void contextLoads() {\n        \/\/\u8fde\u63a5\u963f\u91cc\u4e91\n        DefaultProfile profile = DefaultProfile.getProfile(&quot;cn-hangzhou&quot;, &quot;ID&quot;, &quot;\u5bc6\u7801&quot;);\/\/accessKeyId\u548caccessSecret\u8981\u66ff\u6362\u6210\u7b2c\u4e00\u6b65\u7533\u8bf7\u5230\u7684\u503c\n        \n        IAcsClient client = new DefaultAcsClient(profile);\n \n        \/\/\u6784\u5efa\u8bf7\u6c42\n        CommonRequest request = new CommonRequest();\n        request.setMethod(MethodType.POST);\n        request.setDomain(&quot;dysmsapi.aliyuncs.com&quot;);\/\/\u4e0d\u8981\u4fee\u6539\n        request.setVersion(&quot;2017-05-25&quot;);\/\/\u4e0d\u8981\u4fee\u6539\n        request.setAction(&quot;SendSms&quot;);\n \n        request.putQueryParameter(&quot;PhoneNumbers&quot;, &quot;\u7535\u8bdd&quot;);\/\/\u66ff\u8981\u53d1\u9001\u5230\u7684\u624b\u673a\u53f7\u7801\n        request.putQueryParameter(&quot;SignName&quot;, &quot;\u6d4b\u8bd5\u7b7e\u540d&quot;);\/\/\u77ed\u4fe1\u7b7e\u540d\n        request.putQueryParameter(&quot;TemplateCode&quot;, &quot;SMS_189762676&quot;);\/\/\u77ed\u4fe1\u6a21\u677f\u53f7\n        \/\/\u6784\u5efa\u4e00\u4e2a\u77ed\u4fe1\u9a8c\u8bc1\u7801\n        HashMap&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();\n        map.put(&quot;code&quot;,1688);\n        request.putQueryParameter(&quot;TemplateParam&quot;, JSONObject.toJSONString(map));\n        try {\n            CommonResponse response = client.getCommonResponse(request);\n            System.out.println(response.getData());\n        } catch (ServerException e) {\n            e.printStackTrace();\n        } catch (ClientException e) {\n            e.printStackTrace();\n        }\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>\u5c06\u6211\u4eec\u521a\u521a\u590d\u5236\u7684\u4ee3\u7801\uff0c\u7c98\u8d34\u5230\u6211\u4eec\u7684\u6d4b\u8bd5\u7c7b\u4e2d\u4f7f\u7528\uff0c\u8981\u4fee\u6539\u5bf9\u5e94\u7684\u6570\u636e\uff1a<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"has-vivid-cyan-blue-color has-text-color has-link-color wp-elements-d42285cdbaf9e218ca289d0ab18aacb0\">1.accessKeyId\u548caccessSecret\u8981\u66ff\u6362\u6210\u7b2c\u4e00\u6b65\u7533\u8bf7\u5230\u7684\u503c<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-link-color wp-elements-f152002e8c1c933f83fe928731f41c3f\">2.(\"PhoneNumbers\", \"\u7535\u8bdd\");\/\/\u66ff\u8981\u53d1\u9001\u5230\u7684\u624b\u673a\u53f7\u7801<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-link-color wp-elements-a4515d16b5dd8a0f6d430d4c62c03a65\">3.(\"SignName\", \"\u6d4b\u8bd5\u7b7e\u540d\");\/\/\u77ed\u4fe1\u7b7e\u540d<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-link-color wp-elements-863ab8ad54c00d15e69b563182fc1c36\">4.(\"TemplateCode\", \"SMS_189762676\");\/\/\u77ed\u4fe1\u6a21\u677f\u53f7<\/p>\n<\/div><\/div>\n\n\n\n<p>\u7136\u540e\u8fd0\u884c\u5355\u5143\u6d4b\u8bd5\u7c7b\uff0c\u6536\u5230\u77ed\u4fe1\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"1014\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-9-1024x1014.png\" alt=\"\" class=\"wp-image-1183\" style=\"width:339px;height:auto\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-9-1024x1014.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-9-300x297.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-9-150x150.png 150w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-9-768x761.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-9.png 1072w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>OK\uff01 \u8fd9\u91cc\u8bf4\u660e\u6211\u4eec\u7684\u77ed\u4fe1\u670d\u52a1\u6d4b\u8bd5\u6210\u529f\u4e86\uff01\uff01\uff01<\/p>\n\n\n\n<p><strong>6\u3001\u7136\u540e\uff0c\u6211\u4eec\u5c06\u521a\u521a\u6d4b\u8bd5\u597d\u7684\u4ee3\u7801\uff0c\u6539\u7f16\u6210\u63a5\u53e3\u7c7b<\/strong><br>\u5728Controller\u7c7b\u4e2d\u6dfb\u52a0\u6ce8\u89e3<code class=\"prettyprint\" >@GetMapping(&quot;\/sms&quot;)<\/code> \u4f7f\u4ed6\u6210\u4e3a\u63a5\u53e3\uff0c\u8ba9\u6211\u4eec\u7684\u524d\u7aef\u53ef\u4ee5\u8c03\u7528<br>\u7136\u540e\u4f7f\u4ed6\u5f3a\u884c\u8fd4\u56de\u4e00\u4e2ajson\u6570\u636e\uff0c\u8fd9\u91cc\u6ca1\u6709\u505a\uff0c\u76f4\u63a5\u8ba9\u4ed6\u8fd4\u56de\u4e86smscode=1688<br>\u5927\u5bb6\u53ef\u4ee5\u81ea\u884c\u4fee\u6539\uff0c\u968f\u673a\u9a8c\u8bc1\u7801\uff0c\u9a8c\u8bc1\u7801\u5b58\u50a8\u548c\u8fd4\u56de\uff0c\u6211\u8fd9\u91cc\u5c31\u4e0d\u505a\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\n@Controller\npublic class smsController {\n    @GetMapping(&quot;\/sms&quot;)\n    public void contextLoads(HttpServletRequest request, HttpServletResponse response) {\n        \/\/ Connect to Alibaba Cloud\n        DefaultProfile profile = DefaultProfile.getProfile(&quot;cn-hangzhou&quot;, &quot;ID&quot;, &quot;\u5bc6\u7801&quot;);\n\n        IAcsClient client = new DefaultAcsClient(profile);\n\n        \/\/ Build request\n        CommonRequest request1 = new CommonRequest();\n        request1.setMethod(MethodType.POST);\n        request1.setDomain(&quot;dysmsapi.aliyuncs.com&quot;);\n        request1.setVersion(&quot;2017-05-25&quot;);\n        request1.setAction(&quot;SendSms&quot;);\n\n        request1.putQueryParameter(&quot;PhoneNumbers&quot;, &quot;\u7535\u8bdd\u53f7&quot;);\n        request1.putQueryParameter(&quot;SignName&quot;, &quot;\u963f\u91cc\u4e91\u77ed\u4fe1\u6d4b\u8bd5&quot;);\n        request1.putQueryParameter(&quot;TemplateCode&quot;, &quot;SMS_154950909&quot;);\n\n        \/\/ Build a SMS verification code\n        HashMap&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();\n        map.put(&quot;code&quot;, 1688);\n        request1.putQueryParameter(&quot;TemplateParam&quot;, JSONObject.toJSONString(map));\n\n        try {\n            CommonResponse response1 = client.getCommonResponse(request1);\n            System.out.println(response1.getData());\n\n            \/\/ Return the smscode=1688 to the front-end\n            response.getWriter().write(&quot;{\\&quot;smscode\\&quot;:\\&quot;1688\\&quot;}&quot;);\n        } catch (ServerException e) {\n            e.printStackTrace();\n        } catch (ClientException e) {\n            e.printStackTrace();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u6211\u4eec\u8fd0\u884c\u8fd0\u884c\u7c7b\uff0c\u8c03\u7528\u63a5\u53e3  <code class=\"prettyprint\" >localhost:8080\/sms<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-2\">Vue\u524d\u7aef\u6d41\u7a0b<\/h2>\n\n\n\n<p><strong>7\u3001\u7136\u540e\u6211\u4eec\u7b80\u5355\u7684\u505a\u4e00\u4e2a\u524d\u7aef\u9875\u9762<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;template&gt;\n  &lt;div id=&quot;app&quot;&gt;\n&lt;div class=&quot;login&quot;&gt;\n    &lt;div class=&quot;container&quot;&gt;\n      &lt;div class=&quot;title&quot;&gt;\n        &lt;h3&gt;\u624b\u673a\u53f7\u767b\u5f55&lt;\/h3&gt;\n        &lt;p&gt;\u672a\u6ce8\u518c\u7684\u624b\u673a\u53f7\u767b\u5f55\u540e\u5c06\u81ea\u52a8\u6ce8\u518c&lt;\/p&gt;\n      &lt;\/div&gt;\n\n      &lt;div class=&quot;form&quot;&gt;\n        &lt;div class=&quot;form-item&quot;&gt;\n          &lt;input\n            class=&quot;inp&quot;\n            maxlength=&quot;11&quot;\n            placeholder=&quot;\u8bf7\u8f93\u5165\u624b\u673a\u53f7\u7801&quot;\n            type=&quot;text&quot;\n            v-model=&quot;number&quot;\n\n          \/&gt;\n        &lt;\/div&gt;\n        &lt;div class=&quot;form-item&quot;&gt;\n          &lt;input class=&quot;inp&quot; placeholder=&quot;\u8bf7\u8f93\u5165\u77ed\u4fe1\u9a8c\u8bc1\u7801&quot; type=&quot;text&quot; v-model=&quot;code&quot; \/&gt;\n          &lt;button @click=&quot;getSmsCode&quot;&gt;\u83b7\u53d6\u9a8c\u8bc1\u7801&lt;\/button&gt;\n        &lt;\/div&gt;\n      &lt;\/div&gt;\n\n      &lt;button class=&quot;login-btn&quot; @click=&quot;login&quot;&gt;\u767b\u5f55&lt;\/button&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\n\nexport default {\n  name: &#039;App&#039;,\nexport default {\n  name: &quot;App&quot;,\n  data() {\n    return {\n      code: &quot;&quot;,\n      smsCode:&quot;&quot;,\n      number: &quot;\u8bf7\u8f93\u5165\u624b\u673a\u53f7\u7801&quot;,\n    };\n  },\n}\n&lt;\/script&gt;\n\n&lt;style lang=&quot;less&quot; scoped&gt;\n.container {\n  padding: 49px 29px;\n\n  .title {\n    margin-bottom: 20px;\n    h3 {\n      font-size: 26px;\n      font-weight: normal;\n    }\n    p {\n      line-height: 40px;\n      font-size: 14px;\n      color: #b8b8b8;\n    }\n  }\n\n  .form-item {\n    border-bottom: 1px solid #f3f1f2;\n    padding: 8px;\n    margin-bottom: 14px;\n    display: flex;\n    align-items: center;\n    .inp {\n      display: block;\n      border: none;\n      outline: none;\n      height: 32px;\n      font-size: 14px;\n      flex: 1;\n    }\n    img {\n      width: 94px;\n      height: 31px;\n    }\n    button {\n      height: 31px;\n      border: none;\n      font-size: 13px;\n      color: #cea26a;\n      background-color: transparent;\n      padding-right: 9px;\n    }\n  }\n\n  .login-btn {\n    width: 100%;\n    height: 42px;\n    margin-top: 39px;\n    background: linear-gradient(90deg, #ecb53c, #ff9211);\n    color: #fff;\n    border-radius: 39px;\n    box-shadow: 0 10px 20px 0 rgba(0, 0, 0, 0.1);\n    letter-spacing: 2px;\n    display: flex;\n    justify-content: center;\n    align-items: center;\n  }\n}\n&lt;\/style&gt;\n<\/code><\/pre>\n\n\n\n<p><strong>8\u3001\u4e4b\u540e\u7ed9\u83b7\u53d6\u9a8c\u8bc1\u7801\u548c\u767b\u5f55\u6309\u94ae\u6dfb\u52a0\u70b9\u51fb\u4e8b\u4ef6\uff0c\u7ed1\u5b9a\u4e00\u4e2a\u65b9\u6cd5<\/strong><br>\u83b7\u53d6\u9a8c\u8bc1\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >getSmsCode() {\n      if (this.number.length != 11) {\n        alert(&quot;\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u624b\u673a\u53f7&quot;);\n        return;\n      }\n      alert(&quot;\u77ed\u4fe1\u9a8c\u8bc1\u7801\u83b7\u53d6\u6210\u529f&quot;);\n      axios\n        .get(&quot;http:\/\/localhost:8080\/sms&quot;, {\n          phoneNumber: &quot;15735463521&quot;,\n          signName: &quot;\u963f\u91cc\u4e91\u77ed\u4fe1\u6d4b\u8bd5&quot;,\n          templateCode: &quot;SMS_154950909&quot;,\n        })\n        .then((response) =&gt; {\n          this.smsCode = response.data.smscode;\n          console.log(&quot;SMS code:&quot;, this.smsCode);\n        })\n        .catch((error) =&gt; {\n          console.error(&quot;Error sending SMS:&quot;, error);\n        });\n    },<\/code><\/pre>\n\n\n\n<p>\u767b\u5f55\u63a5\u53e3\uff08\u6ca1\u6709\u505a\u8be6\u7ec6\u903b\u8f91\uff0c\u76f4\u63a5\u505a\u4e00\u4e2a\u5224\u65ad\u7136\u540e\u8fd4\u56de\uff0c\u5927\u5bb6\u53ef\u4ee5\u81ea\u884c\u8bbe\u8ba1\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >login() {\n      console.log(&quot;\u77ed\u4fe1\u9a8c\u8bc1\u7801\uff1a&quot;, this.smsCode);\n      console.log(&quot;code\u9a8c\u8bc1\u7801\uff1a&quot;, this.code);\n      if (this.number.length != 11) {\n        alert(&quot;\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u624b\u673a\u53f7&quot;);\n        return;\n      }\n      if (this.smsCode.length != 4) {\n        alert(&quot;\u8bf7\u7b49\u5f85\u9a8c\u8bc1\u7801\u53d1\u9001&quot;);\n        return;\n      }\n      \/\/ \u5224\u65adcode\u662f\u5426\u7b49\u4e8esmscode\n      if (this.code == this.smsCode) {\n        \/\/ \u5f39\u51fa\u63d0\u793a\u6846\uff0c\u663e\u793a\u767b\u5f55\u6210\u529f\n        alert(&quot;\u767b\u5f55\u6210\u529f&quot;);\n        return;\n      }\n      alert(&quot;\u767b\u5f55\u5931\u8d25&quot;);\n      return;\n    },<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6837\uff0c\u6211\u4eec\u4e00\u4e2a\u7b80\u5355\u7684\u77ed\u4fe1\u9a8c\u8bc1\u7684\u5c0fdemo\u5c31\u505a\u597d\u5566\uff01\uff01<\/p>\n\n\n\n<p><strong>9\u3001\u5c55\u793a\u9875\u9762\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"741\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-10-1024x741.png\" alt=\"\" class=\"wp-image-1188\" style=\"width:840px;height:auto\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-10-1024x741.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-10-300x217.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-10-768x556.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-10.png 1422w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"794\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-11-1024x794.png\" alt=\"\" class=\"wp-image-1193\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-11-1024x794.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-11-300x233.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-11-768x596.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/04\/image-11.png 1431w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u6765\u65f6\u7ed9\u5e03\u7f6e\u4e86\u4e00\u4e2a\u521d\u5b66\u8005\u5c0f\u4efb\u52a1\uff0c\u505a\u4e00\u4e2a\u7b80\u5355\u7684\u77ed\u4fe1\u9a8c\u8bc1demo\u9700\u8981\u7528\u5230\u7684\u6280\u672f\u6709Vue + SpringBoot [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/1158"}],"collection":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1158"}],"version-history":[{"count":18,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/1158\/revisions"}],"predecessor-version":[{"id":1204,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/1158\/revisions\/1204"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1158"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}