{"id":22898,"date":"2024-11-21T14:03:17","date_gmt":"2024-11-21T06:03:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22898\/"},"modified":"2024-11-21T14:03:17","modified_gmt":"2024-11-21T06:03:17","slug":"%e5%9c%a8thinkphp%e4%b8%ad%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0url%e4%b8%ad%e6%96%87%e8%bd%ac%e7%a0%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22898\/","title":{"rendered":"\u5728ThinkPHP\u4e2d\u600e\u4e48\u5b9e\u73b0URL\u4e2d\u6587\u8f6c\u7801"},"content":{"rendered":"<\/p>\n<p>\u5728URL\u4e2d\u4f7f\u7528\u4e2d\u6587\u5b57\u7b26\u662f\u5f88\u5e38\u89c1\u7684\u9700\u6c42\uff0c\u4f8b\u5982\u5728\u8bba\u575b\u4e2d\uff0c\u5e16\u5b50\u7684\u6807\u9898\u7ecf\u5e38\u662f\u4e2d\u6587\u7684\uff0c\u9700\u8981\u5c06\u5176\u4f5c\u4e3aURL\u7684\u4e00\u90e8\u5206\u6765\u751f\u6210\u9875\u9762\u5730\u5740\u3002\u4f46\u662f\uff0c\u56e0\u4e3a\u5386\u53f2\u539f\u56e0\u548c\u534f\u8bae\u9650\u5236\uff0cURL\u53ea\u80fd\u4f7f\u7528ASCII\u7801\u8868\u4e2d\u5b58\u5728\u7684\u5b57\u7b26\u3002\u4e3a\u4e86\u80fd\u591f\u4f7f\u7528\u4e2d\u6587\u5b57\u7b26\u751f\u6210URL\u5730\u5740\uff0c\u6211\u4eec\u9700\u8981\u4e00\u79cd\u65b9\u6cd5\u5c06\u8fd9\u4e9b\u5b57\u7b26\u8f6c\u6362\u6210\u5b89\u5168\u7684URL\u5b57\u7b26\u3002<\/p>\n<p>\u4e00\u79cd\u5e38\u89c1\u7684\u8f6c\u7801\u65b9\u6cd5\u662f\u4f7f\u7528urlencode\u51fd\u6570\u3002\u6b64\u51fd\u6570\u7684\u4f5c\u7528\u662f\u5c06\u4e2d\u6587\u5b57\u7b26\u8f6c\u6362\u4e3a\u7279\u6b8a\u7684\u5341\u516d\u8fdb\u5236\u7f16\u7801\uff0c\u4ee5\u907f\u514d\u5728URL\u4e2d\u9020\u6210\u51b2\u7a81\u3002\u5728ThinkPHP\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528url\u51fd\u6570\u8fdb\u884cURL\u7f16\u7801\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>$url&nbsp;=&nbsp;url('\/index\/index',&nbsp;['title'&nbsp;=&amp;gt;&nbsp;urlencode('\u4e2d\u6587\u5185\u5bb9')]);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5c06\u4e2d\u6587\u5185\u5bb9\u8f6c\u6362\u4e3aurlencode\u7f16\u7801\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3atitle\u53c2\u6570\u4f20\u9012\u7ed9\u4e86\u6211\u4eec\u7684\u63a7\u5236\u5668\u65b9\u6cd5\u3002\u5728\u63a7\u5236\u5668\u7684\u65b9\u6cd5\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528urldecode\u51fd\u6570\u6765\u8fd8\u539f\u88ab\u8f6c\u7801\u7684\u4e2d\u6587\u5b57\u7b26\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>public&nbsp;function&nbsp;index($title)\n{\n&nbsp;&nbsp;&nbsp;&nbsp;$title&nbsp;=&nbsp;urldecode($title);\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;...\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u662f\u53ef\u884c\u7684\uff0c\u4f46\u5b83\u6709\u4e00\u4e2a\u663e\u8457\u7684\u7f3a\u70b9\uff0c\u5c31\u662f\u5341\u516d\u8fdb\u5236\u7f16\u7801\u540e\u7684\u5b57\u7b26\u4e32\u901a\u5e38\u6bd4\u539f\u59cb\u7684\u4e2d\u6587\u5b57\u7b26\u4e32\u8981\u957f\u5f88\u591a\uff0c\u8fd9\u4f1a\u5bfc\u81f4URL\u53d8\u5f97\u975e\u5e38\u4e11\u964b\u548c\u96be\u4ee5\u8bb0\u5fc6\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u4e2d\u6587\u5b57\u7b26\u7684URL\u7f16\u7801\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528URL\u5b89\u5168\u7684Base64\u7f16\u7801\u6765\u5b9e\u73b0\uff0c\u4ece\u800c\u89e3\u51b3\u8be5\u95ee\u9898\u3002\u5728ThinkPHP\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528base64url_encode\u548cbase64url_decode\u51fd\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>$url&nbsp;=&nbsp;url('\/index\/index',&nbsp;['title'&nbsp;=&amp;gt;&nbsp;base64url_encode('\u4e2d\u6587\u5185\u5bb9')]);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5c06\u4e2d\u6587\u5185\u5bb9\u4f7f\u7528URL\u5b89\u5168\u7684Base64\u7f16\u7801\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3atitle\u53c2\u6570\u4f20\u9012\u7ed9\u4e86\u6211\u4eec\u7684\u63a7\u5236\u5668\u65b9\u6cd5\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u63a7\u5236\u5668\u65b9\u6cd5\u4e2d\u4f7f\u7528base64url_decode\u51fd\u6570\u5c06\u5176\u89e3\u7801\u6210\u539f\u59cb\u7684\u4e2d\u6587\u5b57\u7b26\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>public&nbsp;function&nbsp;index($title)\n{\n&nbsp;&nbsp;&nbsp;&nbsp;$title&nbsp;=&nbsp;base64url_decode($title);\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;...\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528Base64\u7f16\u7801\u7684\u65b9\u6cd5\u76f8\u6bd4\u4e8eurlencode\u65b9\u6cd5\u6709\u4e00\u4e2a\u660e\u663e\u7684\u4f18\u70b9\uff0c\u90a3\u5c31\u662f\u5b83\u751f\u6210\u7684\u7f16\u7801\u5b57\u7b26\u4e32\u76f8\u5bf9\u8f83\u77ed\uff0c\u66f4\u52a0\u7f8e\u89c2\u3001\u6613\u8bfb\u3002\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u79cd\u65b9\u6cd5\u5728\u751f\u6210URL\u5b89\u5168\u5b57\u7b26\u4e32\u65f6\uff0c\u9700\u8981\u4f7f\u7528\u4e00\u4e9b\u7279\u6b8a\u7684\u5b57\u7b26\u66ff\u6362\u539f\u59cb\u7684Base64\u5b57\u7b26\uff0c\u4f8b\u5982\u5c06\u7b26\u53f7+\u66ff\u6362\u4e3a-\uff0c\u5c06\u7b26\u53f7\/\u66ff\u6362\u4e3a_\uff0c\u5e76\u53bb\u6389\u7ed3\u5c3e\u53ef\u80fd\u51fa\u73b0\u7684=\u7b26\u53f7\u3002<\/p>\n<p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u8f6c\u7801\u65b9\u6cd5\u3002\u65e0\u8bba\u662furlencode\u8fd8\u662fBase64\u7f16\u7801\uff0c\u6211\u4eec\u90fd\u9700\u8981\u6ce8\u610f\u751f\u6210\u7684URL\u662f\u5426\u7b26\u5408\u89c4\u8303\uff0c\u5e76\u4e14\u5728\u63a7\u5236\u5668\u65b9\u6cd5\u4e2d\u8fdb\u884c\u6b63\u786e\u7684\u89e3\u7801\u5904\u7406\uff0c\u4ee5\u4fdd\u8bc1\u6211\u4eec\u7684\u5e94\u7528\u80fd\u591f\u6b63\u5e38\u5904\u7406\u4e2d\u6587\u5b57\u7b26\u7684URL\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5728ThinkPHP\u4e2d\u600e\u4e48\u5b9e\u73b0URL\u4e2d\u6587\u8f6c\u7801\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728URL\u4e2d\u4f7f\u7528\u4e2d\u6587\u5b57\u7b26\u662f\u5f88\u5e38\u89c1\u7684\u9700\u6c42\uff0c\u4f8b\u5982\u5728\u8bba\u575b\u4e2d\uff0c\u5e16\u5b50\u7684\u6807\u9898\u7ecf\u5e38\u662f\u4e2d\u6587\u7684\uff0c\u9700\u8981\u5c06\u5176\u4f5c\u4e3aURL\u7684\u4e00\u90e8\u5206\u6765\u751f\u6210\u9875\u9762\u5730\u5740\u3002\u4f46\u662f\uff0c\u56e0\u4e3a\u5386\u53f2\u539f\u56e0\u548c\u534f\u8bae\u9650\u5236\uff0cURL\u53ea\u80fd\u4f7f\u7528ASCII\u7801\u8868\u4e2d\u5b58\u5728\u7684\u5b57\u7b26\u3002\u4e3a\u4e86\u80fd\u591f\u4f7f\u7528\u4e2d\u6587\u5b57\u7b26\u751f\u6210URL\u5730\u5740\uff0c\u6211\u4eec\u9700\u8981\u4e00\u79cd\u65b9\u6cd5\u5c06\u8fd9\u4e9b\u5b57\u7b26\u8f6c\u6362\u6210\u5b89\u5168\u7684URL\u5b57\u7b26\u3002 \u4e00\u79cd\u5e38\u89c1\u7684\u8f6c\u7801\u65b9\u6cd5\u662f\u4f7f\u7528urlencode\u51fd\u6570\u3002\u6b64\u51fd\u6570\u7684\u4f5c\u7528\u662f\u5c06\u4e2d\u6587\u5b57\u7b26\u8f6c\u6362\u4e3a\u7279\u6b8a\u7684\u5341\u516d\u8fdb\u5236\u7f16\u7801\uff0c\u4ee5\u907f\u514d\u5728URL\u4e2d\u9020\u6210\u51b2\u7a81\u3002\u5728ThinkPHP\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528url\u51fd\u6570\u8fdb\u884cURL\u7f16\u7801\u3002\u4f8b\u5982\uff1a $url&nbsp;=&nbsp;url(&#8216;\/index\/index&#8217;,&nbsp;[&#8216;title&#8217;&nbsp;=&amp;gt;&nbsp;urlencode(&#8216;\u4e2d\u6587\u5185\u5bb9&#8217;)]); \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5c06\u4e2d\u6587\u5185\u5bb9\u8f6c\u6362\u4e3aurlencode\u7f16\u7801\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3atitle\u53c2\u6570\u4f20\u9012\u7ed9\u4e86\u6211\u4eec\u7684\u63a7\u5236\u5668\u65b9\u6cd5\u3002\u5728\u63a7\u5236\u5668\u7684\u65b9\u6cd5\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528urldecode\u51fd\u6570\u6765\u8fd8\u539f\u88ab\u8f6c\u7801\u7684\u4e2d\u6587\u5b57\u7b26\u3002\u4f8b\u5982\uff1a public&nbsp;function&nbsp;index($title) { &nbsp;&nbsp;&nbsp;&nbsp;$title&nbsp;=&nbsp;urldecode($title); &nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;&#8230; } \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u79cd\u65b9\u6cd5\u662f\u53ef\u884c\u7684\uff0c\u4f46\u5b83\u6709\u4e00\u4e2a\u663e\u8457\u7684\u7f3a\u70b9\uff0c\u5c31\u662f\u5341\u516d\u8fdb\u5236\u7f16\u7801\u540e\u7684\u5b57\u7b26\u4e32\u901a\u5e38\u6bd4\u539f\u59cb\u7684\u4e2d\u6587\u5b57\u7b26\u4e32\u8981\u957f\u5f88\u591a\uff0c\u8fd9\u4f1a\u5bfc\u81f4URL\u53d8\u5f97\u975e\u5e38\u4e11\u964b\u548c\u96be\u4ee5\u8bb0\u5fc6\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u4e2d\u6587\u5b57\u7b26\u7684URL\u7f16\u7801\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528URL\u5b89\u5168\u7684Base64\u7f16\u7801\u6765\u5b9e\u73b0\uff0c\u4ece\u800c\u89e3\u51b3\u8be5\u95ee\u9898\u3002\u5728ThinkPHP\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528base64url_encode\u548cbase64url_decode\u51fd\u6570\u3002\u4f8b\u5982\uff1a $url&nbsp;=&nbsp;url(&#8216;\/index\/index&#8217;,&nbsp;[&#8216;title&#8217;&nbsp;=&amp;gt;&nbsp;base64url_encode(&#8216;\u4e2d\u6587\u5185\u5bb9&#8217;)]); \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5c06\u4e2d\u6587\u5185\u5bb9\u4f7f\u7528URL\u5b89\u5168\u7684Base64\u7f16\u7801\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3atitle\u53c2\u6570\u4f20\u9012\u7ed9\u4e86\u6211\u4eec\u7684\u63a7\u5236\u5668\u65b9\u6cd5\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u63a7\u5236\u5668\u65b9\u6cd5\u4e2d\u4f7f\u7528base64url_decode\u51fd\u6570\u5c06\u5176\u89e3\u7801\u6210\u539f\u59cb\u7684\u4e2d\u6587\u5b57\u7b26\u3002\u4f8b\u5982\uff1a public&nbsp;function&nbsp;index($title) { &nbsp;&nbsp;&nbsp;&nbsp;$title&nbsp;=&nbsp;base64url_decode($title); &nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;&#8230; } \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528Base64\u7f16\u7801\u7684\u65b9\u6cd5\u76f8\u6bd4\u4e8eurlencode\u65b9\u6cd5\u6709\u4e00\u4e2a\u660e\u663e\u7684\u4f18\u70b9\uff0c\u90a3\u5c31\u662f\u5b83\u751f\u6210\u7684\u7f16\u7801\u5b57\u7b26\u4e32\u76f8\u5bf9\u8f83\u77ed\uff0c\u66f4\u52a0\u7f8e\u89c2\u3001\u6613\u8bfb\u3002\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u79cd\u65b9\u6cd5\u5728\u751f\u6210URL\u5b89\u5168\u5b57\u7b26\u4e32\u65f6\uff0c\u9700\u8981\u4f7f\u7528\u4e00\u4e9b\u7279\u6b8a\u7684\u5b57\u7b26\u66ff\u6362\u539f\u59cb\u7684Base64\u5b57\u7b26\uff0c\u4f8b\u5982\u5c06\u7b26\u53f7+\u66ff\u6362\u4e3a-\uff0c\u5c06\u7b26\u53f7\/\u66ff\u6362\u4e3a_\uff0c\u5e76\u53bb\u6389\u7ed3\u5c3e\u53ef\u80fd\u51fa\u73b0\u7684=\u7b26\u53f7\u3002 \u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u8f6c\u7801\u65b9\u6cd5\u3002\u65e0\u8bba\u662furlencode\u8fd8\u662fBase64\u7f16\u7801\uff0c\u6211\u4eec\u90fd\u9700\u8981\u6ce8\u610f\u751f\u6210\u7684URL\u662f\u5426\u7b26\u5408\u89c4\u8303\uff0c\u5e76\u4e14\u5728\u63a7\u5236\u5668\u65b9\u6cd5\u4e2d\u8fdb\u884c\u6b63\u786e\u7684\u89e3\u7801\u5904\u7406\uff0c\u4ee5\u4fdd\u8bc1\u6211\u4eec\u7684\u5e94\u7528\u80fd\u591f\u6b63\u5e38\u5904\u7406\u4e2d\u6587\u5b57\u7b26\u7684URL\u3002 \u4ee5\u4e0a\u5c31\u662f\u5728ThinkPHP\u4e2d\u600e\u4e48\u5b9e\u73b0URL\u4e2d\u6587\u8f6c\u7801\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-22898","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22898","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=22898"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22898\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}