{"id":31199,"date":"2024-11-25T17:59:08","date_gmt":"2024-11-25T09:59:08","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31199\/"},"modified":"2024-11-25T17:59:08","modified_gmt":"2024-11-25T09:59:08","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8furl%e4%b8%8etoken%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31199\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8furl\u4e0etoken\u5982\u4f55\u8bbe\u7f6e"},"content":{"rendered":"<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8furl\u4e0etoken\u8bbe\u7f6e\u8be6\u89e3\u7684\u76f8\u5173\u8d44\u6599,\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\u89e3\u51b3\u7c7b\u4f3c\u95ee\u9898\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\u3002<\/p>\n<p><strong>\u5fae\u4fe1\u5c0f\u7a0b\u5e8furl\u4e0etoken\u8bbe\u7f6e\u8be6\u89e3<\/strong><\/p>\n<p>\u65b0\u6d6a\u4e91\u5e94\u7528sae\u7684\u4ee3\u7801\u91cc\u521b\u5efa\u4e00\u4e2aweixin.php\u6587\u4ef6\uff0c\u5199\u5165\u4ee5\u4e0b\u4ee3\u7801<\/p>\n<pre>define(\"TOKEN\",\"myToken\");\/\/&nbsp;\u540e\u53f0\u586b\u5199\u7684token\uff0c\u5728\u5fae\u4fe1\u516c\u4f17\u5e73\u53f0\u542f\u7528\r\n$wechatObj&nbsp;=&nbsp;new&nbsp;wechatAPI();\r\n$wechatObj-&amp;gt;isValid();\r\nclass&nbsp;wechatAPI\r\n{\r\n&nbsp;&nbsp;public&nbsp;function&nbsp;isValid()\/\/\u9a8c\u8bc1\u5fae\u4fe1\u63a5\u53e3\uff0c\u9a8c\u8bc1\u51fd\u6570\u4ee5\u5916\u7684\u4ee3\u7801\u548c\u5fae\u4fe1\u516c\u4f17\u53f7\u5f00\u53d1token\u8bbe\u7f6e\u76f8\u540c\r\n&nbsp;&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$echoStr&nbsp;=&nbsp;$_GET[\"echostr\"];\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;($this-&amp;gt;checkSignature())&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;header('content-type:text');\/\/add\uff0c\u4e00\u5b9a\u8981\u52a0\u5165header\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;$echoStr;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\r\n&nbsp;&nbsp;}\r\n&nbsp;&nbsp;private&nbsp;function&nbsp;checkSignature()&nbsp;&nbsp;\/\/\u5b98\u65b9\u7684\u9a8c\u8bc1\u51fd\u6570\r\n&nbsp;&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$signature&nbsp;=&nbsp;$_GET[\"signature\"];\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$timestamp&nbsp;=&nbsp;$_GET[\"timestamp\"];\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$nonce&nbsp;=&nbsp;$_GET[\"nonce\"];\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$token&nbsp;=&nbsp;TOKEN;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$tmpArr&nbsp;=&nbsp;array($token,&nbsp;$timestamp,&nbsp;$nonce);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort($tmpArr,&nbsp;SORT_STRING);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$tmpStr&nbsp;=&nbsp;implode(&nbsp;$tmpArr&nbsp;);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$tmpStr&nbsp;=&nbsp;sha1(&nbsp;$tmpStr&nbsp;);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(&nbsp;$tmpStr&nbsp;==&nbsp;$signature&nbsp;){\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\r\n&nbsp;&nbsp;}\r\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4fdd\u5b58\u540e\u901a\u8fc7url\u8bbf\u95ee\uff0c\u5728\u5730\u5740\u680f\u590d\u5236url\uff0c\u5199\u5165\u5fae\u4fe1\u516c\u4f17\u5e73\u53f0\u4e2d<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/4c348dd2952446fbec4891a1c239ff68-0.jpg\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8furl\u4e0etoken\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8furl\u4e0etoken\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe\" \/><\/p>\n<p>\u5728\u5fae\u4fe1\u516c\u4f17\u5e73\u53f0\u7684\u5f00\u53d1\u8bbe\u7f6e\u4e2d\uff0c\u586b\u5165\u4ee5\u4e0a\u83b7\u5f97\u7684url\u548c\u8bbe\u7f6e\u7684token\uff0c\u81ea\u52a8\u751f\u6210EncodingASEKey<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/4c348dd2952446fbec4891a1c239ff68-1.jpg\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8furl\u4e0etoken\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe1\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8furl\u4e0etoken\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe1\" \/><\/p>\n<p>\u8bbe\u7f6e\u5b8c\u6210<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/4c348dd2952446fbec4891a1c239ff68-2.jpg\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8furl\u4e0etoken\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe2\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8furl\u4e0etoken\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe2\" \/><\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a<\/p>\n<\/p>\n<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8furl\u4e0etoken\u5982\u4f55\u8bbe\u7f6e\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>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8furl\u4e0etoken\u8bbe\u7f6e\u8be6\u89e3\u7684\u76f8\u5173\u8d44\u6599,\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\u89e3\u51b3\u7c7b\u4f3c\u95ee\u9898\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\u3002 \u5fae\u4fe1\u5c0f\u7a0b\u5e8furl\u4e0etoken\u8bbe\u7f6e\u8be6\u89e3 \u65b0\u6d6a\u4e91\u5e94\u7528sae\u7684\u4ee3\u7801\u91cc\u521b\u5efa\u4e00\u4e2aweixin.php\u6587\u4ef6\uff0c\u5199\u5165\u4ee5\u4e0b\u4ee3\u7801 define(&#8220;TOKEN&#8221;,&#8221;myToken&#8221;);\/\/&nbsp;\u540e\u53f0\u586b\u5199\u7684token\uff0c\u5728\u5fae\u4fe1\u516c\u4f17\u5e73\u53f0\u542f\u7528 $wechatObj&nbsp;=&nbsp;new&nbsp;wechatAPI(); $wechatObj-&amp;gt;isValid(); class&nbsp;wechatAPI { &nbsp;&nbsp;public&nbsp;function&nbsp;isValid()\/\/\u9a8c\u8bc1\u5fae\u4fe1\u63a5\u53e3\uff0c\u9a8c\u8bc1\u51fd\u6570\u4ee5\u5916\u7684\u4ee3\u7801\u548c\u5fae\u4fe1\u516c\u4f17\u53f7\u5f00\u53d1token\u8bbe\u7f6e\u76f8\u540c &nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$echoStr&nbsp;=&nbsp;$_GET[&#8220;echostr&#8221;]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;($this-&amp;gt;checkSignature())&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;header(&#8216;content-type:text&#8217;);\/\/add\uff0c\u4e00\u5b9a\u8981\u52a0\u5165header &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;$echoStr; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;} &nbsp;&nbsp;private&nbsp;function&nbsp;checkSignature()&nbsp;&nbsp;\/\/\u5b98\u65b9\u7684\u9a8c\u8bc1\u51fd\u6570 &nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$signature&nbsp;=&nbsp;$_GET[&#8220;signature&#8221;]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$timestamp&nbsp;=&nbsp;$_GET[&#8220;timestamp&#8221;]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$nonce&nbsp;=&nbsp;$_GET[&#8220;nonce&#8221;]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$token&nbsp;=&nbsp;TOKEN; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$tmpArr&nbsp;=&nbsp;array($token,&nbsp;$timestamp,&nbsp;$nonce); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sort($tmpArr,&nbsp;SORT_STRING); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$tmpStr&nbsp;=&nbsp;implode(&nbsp;$tmpArr&nbsp;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$tmpStr&nbsp;=&nbsp;sha1(&nbsp;$tmpStr&nbsp;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(&nbsp;$tmpStr&nbsp;==&nbsp;$signature&nbsp;){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;} }; \u767b\u5f55\u540e\u590d\u5236 \u4fdd\u5b58\u540e\u901a\u8fc7url\u8bbf\u95ee\uff0c\u5728\u5730\u5740\u680f\u590d\u5236url\uff0c\u5199\u5165\u5fae\u4fe1\u516c\u4f17\u5e73\u53f0\u4e2d \u5728\u5fae\u4fe1\u516c\u4f17\u5e73\u53f0\u7684\u5f00\u53d1\u8bbe\u7f6e\u4e2d\uff0c\u586b\u5165\u4ee5\u4e0a\u83b7\u5f97\u7684url\u548c\u8bbe\u7f6e\u7684token\uff0c\u81ea\u52a8\u751f\u6210EncodingASEKey \u8bbe\u7f6e\u5b8c\u6210 \u76f8\u5173\u63a8\u8350\uff1a \u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8furl\u4e0etoken\u5982\u4f55\u8bbe\u7f6e\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":[19],"tags":[],"class_list":["post-31199","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31199","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=31199"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31199\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}