{"id":29574,"date":"2024-11-25T15:04:48","date_gmt":"2024-11-25T07:04:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/29574\/"},"modified":"2024-11-25T15:04:48","modified_gmt":"2024-11-25T07:04:48","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f-%e6%b6%88%e6%81%af%e6%8e%a8%e9%80%81php%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%aa%8c%e8%af%81%e5%ae%9e%e4%be%8b%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/29574\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u6d88\u606f\u63a8\u9001php\u670d\u52a1\u5668\u9a8c\u8bc1\u5b9e\u4f8b\u8be6\u89e3"},"content":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u6d88\u606f\u63a8\u9001php\u670d\u52a1\u5668\u9a8c\u8bc1\u5b9e\u4f8b\u8be6\u89e3\u7684\u76f8\u5173\u8d44\u6599,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/p>\n<p><strong>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u6d88\u606f\u63a8\u9001php\u670d\u52a1\u5668\u9a8c\u8bc1\u5b9e\u4f8b\u8be6\u89e3<\/strong><\/p>\n<p>\u5fae\u4fe1\u6587\u6863\uff08\u9760\u4e0b\u6709\u4e2a\u201c\u63a5\u5165\u6307\u5f15\u201d\uff09\uff1ahttps:\/\/mp.weixin.qq.com\/debug\/wxadoc\/dev\/api\/custommsg\/callback_help.html<\/p>\n<p>\u8bbe\u7f6e\u9875\u9762\uff08\u201c\u8bbe\u7f6e\u201d&gt;&gt;\u201c\u5f00\u53d1\u8bbe\u7f6e\u201d\uff09\uff1a<\/p>\n<p>https:\/\/mp.weixin.qq.com\/wxopen\/initprofile?action=home&#038;lang=zh_CN<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>1.\u8bbe\u7f6e\u670d\u52a1\u5668\u57df\u540d<\/strong><\/p>\n<p>\u6bd4\u5982\uff1ahttps:\/\/hosts.com<\/p>\n<p>\u6ce8\u610fhttp\u548chttps\u534f\u8bae\u7684\u4e0d\u540c\u3002<\/p>\n<p><strong>2.\u8bbe\u7f6e\u6d88\u606f\u63a8\u9001<\/strong><\/p>\n<p>2.1 \u5728\u4f60\u7684\u670d\u52a1\u5668\u91cc\u6dfb\u52a0\u670d\u52a1\u5668\u63a5\u53e3test.php\uff0ctest.php\u63a5\u53e3\u5185\u5bb9\u4e3b\u8981\u662f\u901a\u8fc7token\u9a8c\u8bc1\u6d88\u606f\u662f\u5426\u4e3a\u5fae\u4fe1\u53d1\u6765\u7684\uff0c\u4ee3\u7801\u53c2\u7167\u5b98\u65b9\u7684\u4f8b\u5b50\uff1a<\/p>\n<p><\/p>\n<pre>define(\"TOKEN\",\"xxxxx\");\/&nbsp;\u540e\u53f0\u586b\u5199\u7684token\r\n$wechatObj&nbsp;=&nbsp;new&nbsp;wechatAPI();\r\n$wechatObj-&amp;gt;isValid();\r\nclass&nbsp;wechatAPI\r\n{\r\npublic&nbsp;function&nbsp;isValid()\/\/\u9a8c\u8bc1\u5fae\u4fe1\u63a5\u53e3\uff0c\u5982\u679c\u786e\u8ba4\u662f\u5fae\u4fe1\u5c31\u8fd4\u56de\u5b83\u4f20\u6765\u7684echostr\u53c2\u6570\r\n{\r\n&nbsp;$echoStr&nbsp;=&nbsp;$_GET[\"echostr\"];\r\n&nbsp;if&nbsp;($this-&amp;gt;checkSignature())&nbsp;{\r\n&nbsp;echo&nbsp;$echoStr;\r\n&nbsp;exit;\r\n&nbsp;}\r\n}\r\nprivate&nbsp;function&nbsp;checkSignature()&nbsp;\/\/\u5b98\u65b9\u7684\u9a8c\u8bc1\u51fd\u6570\r\n{\r\n&nbsp;$signature&nbsp;=&nbsp;$_GET[\"signature\"];\r\n&nbsp;$timestamp&nbsp;=&nbsp;$_GET[\"timestamp\"];\r\n&nbsp;$nonce&nbsp;=&nbsp;$_GET[\"nonce\"];\r\n&nbsp;$token&nbsp;=&nbsp;TOKEN;\r\n&nbsp;$tmpArr&nbsp;=&nbsp;array($token,&nbsp;$timestamp,&nbsp;$nonce);\r\n&nbsp;sort($tmpArr,&nbsp;SORT_STRING);\r\n&nbsp;$tmpStr&nbsp;=&nbsp;implode(&nbsp;$tmpArr&nbsp;);\r\n&nbsp;$tmpStr&nbsp;=&nbsp;sha1(&nbsp;$tmpStr&nbsp;);\r\n&nbsp;if(&nbsp;$tmpStr&nbsp;==&nbsp;$signature&nbsp;){\r\n&nbsp;return&nbsp;true;\r\n&nbsp;}else{\r\n&nbsp;return&nbsp;false;\r\n&nbsp;}\r\n}\r\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>2.2 \u8bbe\u7f6e\u5c0f\u7a0b\u5e8f\u540e\u53f0\u6d88\u606f\u63a8\u9001\u76f8\u5173\u4fe1\u606f<\/p>\n<p>URL(\u670d\u52a1\u5668\u5730\u5740)\uff1ahttps:\/\/hosts.com\/xx\/test.php<\/p>\n<p>Token: \u4efb\u610f\u7b26\u5408\u89c4\u8303\u7684\u5b57\u7b26\u4e32\uff0c\u5982\u4e0a\u9762\u5b9a\u4e49\u7684&#8221;xxxxx&#8221;<\/p>\n<p>EncodingAESKey(\u6d88\u606f\u52a0\u5bc6\u5bc6\u94a5)\uff1a\uff08\u968f\u673a\u751f\u6210\uff0c\u81ea\u5df1\u4fdd\u5b58\u5c31\u597d\u4e86\uff0c\u8fd9\u4e2a\u52a0\u89e3\u5bc6\u624d\u7528\uff09<\/p>\n<p>\u6d88\u606f\u52a0\u5bc6\u65b9\u5f0f\uff1a\u6682\u65f6\u9009\u62e9\u660e\u6587\uff0c\u4e0d\u7528\u53bb\u8003\u8651\u52a0\u5bc6\u89e3\u5bc6\u7684\u95ee\u9898\u3002<\/p>\n<p>\u6570\u636e\u683c\u5f0f\uff1a\u6839\u636e\u9700\u6c42\u9009\u62e9\u3002<\/p>\n<p>\u63d0\u4ea4\uff0c\u5982\u679c\u6ca1\u6709\u95ee\u9898\u5c31\u4f1a\u6210\u529f\u4e86\u3002\uff08\u5982\u679c\u6709\u95ee\u9898\u4f60\u53ef\u4ee5\u7528\u5047\u7684\u6570\u636e\u901a\u8fc7\u6d4f\u89c8\u5668\u6d4b\u8bd5\uff09<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u6d88\u606f\u63a8\u9001php\u670d\u52a1\u5668\u9a8c\u8bc1\u5b9e\u4f8b\u8be6\u89e3\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>\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u6d88\u606f\u63a8\u9001php\u670d\u52a1\u5668\u9a8c\u8bc1\u5b9e\u4f8b\u8be6\u89e3\u7684\u76f8\u5173\u8d44\u6599,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b \u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u6d88\u606f\u63a8\u9001php\u670d\u52a1\u5668\u9a8c\u8bc1\u5b9e\u4f8b\u8be6\u89e3 \u5fae\u4fe1\u6587\u6863\uff08\u9760\u4e0b\u6709\u4e2a\u201c\u63a5\u5165\u6307\u5f15\u201d\uff09\uff1ahttps:\/\/mp.weixin.qq.com\/debug\/wxadoc\/dev\/api\/custommsg\/callback_help.html \u8bbe\u7f6e\u9875\u9762\uff08\u201c\u8bbe\u7f6e\u201d&gt;&gt;\u201c\u5f00\u53d1\u8bbe\u7f6e\u201d\uff09\uff1a https:\/\/mp.weixin.qq.com\/wxopen\/initprofile?action=home&#038;lang=zh_CN \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b 1.\u8bbe\u7f6e\u670d\u52a1\u5668\u57df\u540d \u6bd4\u5982\uff1ahttps:\/\/hosts.com \u6ce8\u610fhttp\u548chttps\u534f\u8bae\u7684\u4e0d\u540c\u3002 2.\u8bbe\u7f6e\u6d88\u606f\u63a8\u9001 2.1 \u5728\u4f60\u7684\u670d\u52a1\u5668\u91cc\u6dfb\u52a0\u670d\u52a1\u5668\u63a5\u53e3test.php\uff0ctest.php\u63a5\u53e3\u5185\u5bb9\u4e3b\u8981\u662f\u901a\u8fc7token\u9a8c\u8bc1\u6d88\u606f\u662f\u5426\u4e3a\u5fae\u4fe1\u53d1\u6765\u7684\uff0c\u4ee3\u7801\u53c2\u7167\u5b98\u65b9\u7684\u4f8b\u5b50\uff1a define(&#8220;TOKEN&#8221;,&#8221;xxxxx&#8221;);\/&nbsp;\u540e\u53f0\u586b\u5199\u7684token $wechatObj&nbsp;=&nbsp;new&nbsp;wechatAPI(); $wechatObj-&amp;gt;isValid(); class&nbsp;wechatAPI { public&nbsp;function&nbsp;isValid()\/\/\u9a8c\u8bc1\u5fae\u4fe1\u63a5\u53e3\uff0c\u5982\u679c\u786e\u8ba4\u662f\u5fae\u4fe1\u5c31\u8fd4\u56de\u5b83\u4f20\u6765\u7684echostr\u53c2\u6570 { &nbsp;$echoStr&nbsp;=&nbsp;$_GET[&#8220;echostr&#8221;]; &nbsp;if&nbsp;($this-&amp;gt;checkSignature())&nbsp;{ &nbsp;echo&nbsp;$echoStr; &nbsp;exit; &nbsp;} } private&nbsp;function&nbsp;checkSignature()&nbsp;\/\/\u5b98\u65b9\u7684\u9a8c\u8bc1\u51fd\u6570 { &nbsp;$signature&nbsp;=&nbsp;$_GET[&#8220;signature&#8221;]; &nbsp;$timestamp&nbsp;=&nbsp;$_GET[&#8220;timestamp&#8221;]; &nbsp;$nonce&nbsp;=&nbsp;$_GET[&#8220;nonce&#8221;]; &nbsp;$token&nbsp;=&nbsp;TOKEN; &nbsp;$tmpArr&nbsp;=&nbsp;array($token,&nbsp;$timestamp,&nbsp;$nonce); &nbsp;sort($tmpArr,&nbsp;SORT_STRING); &nbsp;$tmpStr&nbsp;=&nbsp;implode(&nbsp;$tmpArr&nbsp;); &nbsp;$tmpStr&nbsp;=&nbsp;sha1(&nbsp;$tmpStr&nbsp;); &nbsp;if(&nbsp;$tmpStr&nbsp;==&nbsp;$signature&nbsp;){ &nbsp;return&nbsp;true; &nbsp;}else{ &nbsp;return&nbsp;false; &nbsp;} } }; \u767b\u5f55\u540e\u590d\u5236 2.2 \u8bbe\u7f6e\u5c0f\u7a0b\u5e8f\u540e\u53f0\u6d88\u606f\u63a8\u9001\u76f8\u5173\u4fe1\u606f URL(\u670d\u52a1\u5668\u5730\u5740)\uff1ahttps:\/\/hosts.com\/xx\/test.php Token: \u4efb\u610f\u7b26\u5408\u89c4\u8303\u7684\u5b57\u7b26\u4e32\uff0c\u5982\u4e0a\u9762\u5b9a\u4e49\u7684&#8221;xxxxx&#8221; EncodingAESKey(\u6d88\u606f\u52a0\u5bc6\u5bc6\u94a5)\uff1a\uff08\u968f\u673a\u751f\u6210\uff0c\u81ea\u5df1\u4fdd\u5b58\u5c31\u597d\u4e86\uff0c\u8fd9\u4e2a\u52a0\u89e3\u5bc6\u624d\u7528\uff09 \u6d88\u606f\u52a0\u5bc6\u65b9\u5f0f\uff1a\u6682\u65f6\u9009\u62e9\u660e\u6587\uff0c\u4e0d\u7528\u53bb\u8003\u8651\u52a0\u5bc6\u89e3\u5bc6\u7684\u95ee\u9898\u3002 \u6570\u636e\u683c\u5f0f\uff1a\u6839\u636e\u9700\u6c42\u9009\u62e9\u3002 \u63d0\u4ea4\uff0c\u5982\u679c\u6ca1\u6709\u95ee\u9898\u5c31\u4f1a\u6210\u529f\u4e86\u3002\uff08\u5982\u679c\u6709\u95ee\u9898\u4f60\u53ef\u4ee5\u7528\u5047\u7684\u6570\u636e\u901a\u8fc7\u6d4f\u89c8\u5668\u6d4b\u8bd5\uff09 \u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f [&hellip;]<\/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-29574","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29574","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=29574"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29574\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=29574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=29574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=29574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}