{"id":29179,"date":"2024-11-25T11:43:12","date_gmt":"2024-11-25T03:43:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/29179\/"},"modified":"2024-11-25T11:43:12","modified_gmt":"2024-11-25T03:43:12","slug":"%e5%be%ae%e4%bf%a1%e5%bc%80%e5%8f%91asp-net%e6%8e%a5%e5%85%a5%e6%96%b9%e6%b3%95%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/29179\/","title":{"rendered":"\u5fae\u4fe1\u5f00\u53d1asp.net\u63a5\u5165\u65b9\u6cd5\u4ecb\u7ecd"},"content":{"rendered":"<p style=\"text-align: left\">\u6211\u4eec\u8981\u8fdb\u884c\u5fae\u4fe1\u516c\u4f17\u5e73\u53f0\u7684\u5f00\u53d1\uff0c\u7b2c\u4e00\u6b65\u5f53\u7136\u662f\u8981\u6709\u516c\u4f17\u53f7\u4e86\u3002\u4ec0\u4e48\uff1f\u4e0d\u77e5\u9053\u4ec0\u4e48\u662f\u5fae\u4fe1\u516c\u4f17\u53f7\uff0c\u770b\u6765\u4f60\u8fd8\u8981\u5148\u56de\u7089\u70bc\u70bc\u4e86\uff0c\u5475\u5475\u3002\u901a\u4fd7\u7684\u8bf4\uff0c\u6211\u4eec\u5fae\u4fe1\u5e73\u53f0\u5c31\u597d\u50cf\u662f\u4e00\u4e2a\u5927\u793e\u4f1a\uff0c\u91cc\u9762\u6709\u4e2a\u4f53\u4eba\uff0c\u4e5f\u6709\u5404\u79cd\u7ec4\u7ec7\u673a\u6784\u3002<\/p>\n<p style=\"text-align: left\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u60f3\u8981\u5fae\u4fe1\u5f00\u53d1\uff0c\u9996\u5148\u8981\u6709\u4e2a\u670d\u52a1\u5668\uff0c\u4f46\u662f\u81ea\u5df1\u6ca1\u6709\u3002\u8fd9\u65f6\u5019\u53ef\u4ee5\u7528\u82b1\u751f\u58f3\uff0c\u5c06\u5185\u7f51\u6620\u5c04\u5230\u516c\u7f51\u4e0a\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728\u516c\u7f51\u8bbf\u95ee\u81ea\u5df1\u7684\u7f51\u7ad9\u4e86\u3002<\/p>\n<p style=\"text-align: left\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u7136\u540e\u8981\u5199\u4e00\u4e2a\u63a5\u5165\u4ee3\u7801\uff0c\u800c\u5fae\u4fe1\u4e0a\u53ea\u6709php\u662f\u793a\u4f8b\u3002\u8fd9\u91cc\u9644\u4e0a\u7684\u793a\u4f8b\u3002<\/p>\n<p style=\"text-align: left\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&nbsp;\u9996\u5148\u521b\u5efa\u4e00\u4e2aDefault.aspx<\/strong>\u3002\u5728<span style=\"color: #ff0000\">Page_Load<\/span>\u91cc\u8fdb\u884c\u68c0\u9a8c\uff1a\uff08MyLog\u662f\uff0c\u53ef\u4ee5\u5ffd\u7565\uff09&nbsp;&nbsp;&nbsp;\u5173\u4e8echeckSignature()\u5c31\u548c\u6240\u67e5\u5230\u7684\u5dee\u4e0d\u591a\u4e86\u3002\u8fd9\u91cc\u8d34\u4e00\u4e0b&nbsp;&nbsp;<\/p>\n<pre> MyLog.DebugInfo(\"request default.aspx\");\r\n String echoStr = Request.QueryString[\"echostr\"];\r\n MyLog.DebugInfo(\"echoStr:\"+echoStr);\r\n if (this.checkSignature())\r\n {\r\n if(!string.IsNullOrEmpty(echoStr)){\r\n MyLog.DebugInfo(\"echostr:\" + echoStr);\r\n Response.Write(echoStr);\r\n Response.End();\r\n }\r\n \r\n }<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align: left\">\u6700\u6700\u4e3b\u8981\u7684\u662f\u90a3\u53e5Response.End()\uff0c\u4e0d\u52a0\u8fd9\u4e00\u53e5\u600e\u4e48\u6837\u90fd\u63a5\u4e0d\u8fdb\u53bb\uff08\u5e0c\u671b\u6709\u5927\u795e\u544a\u77e5\uff09\u3002 \u5173\u4e8echeckSignature()\u5c31\u548c\u6240\u67e5\u5230\u7684\u5dee\u4e0d\u591a\u4e86\u3002\u8fd9\u91cc\u8d34\u4e00\u4e0b<\/p>\n<pre>private bool checkSignature()\r\n{\r\n \r\n string signature = Request[\"signature\"];\r\n string timestamp = Request[\"timestamp\"];\r\n string nonce = Request[\"nonce\"];\r\n MyLog.DebugInfo(String.Format(\"signature:{0},timestamp:{1},nonce:{2}\", signature, timestamp, nonce));\r\n string token = TOKEN;\r\n string[] tmpArr = new string[] { token, timestamp, nonce };\r\n Array.Sort(tmpArr);\r\n string tmpStr = string.Join(\"\", tmpArr);\r\n \/\/sha1\u52a0\u5bc6\r\n System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();\r\n byte[] secArr = sha1.ComputeHash(System.Text.Encoding.Default.GetBytes(tmpStr));\r\n tmpStr = BitConverter.ToString(secArr).Replace(\"-\", \"\").ToLower();\r\n MyLog.DebugInfo(String.Format(\"after parse:{0}\", tmpStr));\r\n if (tmpStr == signature)\r\n {\r\n MyLog.DebugInfo(\"true\");\r\n return true;\r\n }\r\n else\r\n {\r\n return false;\r\n }\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align: left\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u8fd9\u91cc\u4e3b\u8981\u662f\u56e0\u4e3a\u90a3\u4e2a<span style=\"color: #ff0000\">Response.End()<\/span>\u7684\u95ee\u9898\uff0c\u5bfc\u81f4\u6211\u641e\u4e86\u8bb8\u4e45\uff0c\u7279\u6b64\u8bb0\u5f55\u4e00\u4e0b\uff0c\u5e0c\u671b\u5e2e\u52a9\u80fd\u5e2e\u52a9\u5230\u7684\u4eba\u3002<\/p>\n<p style=\"text-align: left\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u8fd8\u6709\u4e00\u70b9\u53ef\u80fd\u662f\u56e0\u4e3a\u5fae\u4fe1\u670d\u52a1\u5668\u7684\u539f\u56e0Token\u9a8c\u8bc1\u5931\u8d25\uff0c\u591a\u70b92\u6b21\u5373\u53ef\uff0c\u522b\u50cf\u6211\u8fd9\u6837\u53ea\u70b9\u4e00\u6b21\u554a\uff01\uff01\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5f00\u53d1asp.net\u63a5\u5165\u65b9\u6cd5\u4ecb\u7ecd\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>\u6211\u4eec\u8981\u8fdb\u884c\u5fae\u4fe1\u516c\u4f17\u5e73\u53f0\u7684\u5f00\u53d1\uff0c\u7b2c\u4e00\u6b65\u5f53\u7136\u662f\u8981\u6709\u516c\u4f17\u53f7\u4e86\u3002\u4ec0\u4e48\uff1f\u4e0d\u77e5\u9053\u4ec0\u4e48\u662f\u5fae\u4fe1\u516c\u4f17\u53f7\uff0c\u770b\u6765\u4f60\u8fd8\u8981\u5148\u56de\u7089\u70bc\u70bc\u4e86\uff0c\u5475\u5475\u3002\u901a\u4fd7\u7684\u8bf4\uff0c\u6211\u4eec\u5fae\u4fe1\u5e73\u53f0\u5c31\u597d\u50cf\u662f\u4e00\u4e2a\u5927\u793e\u4f1a\uff0c\u91cc\u9762\u6709\u4e2a\u4f53\u4eba\uff0c\u4e5f\u6709\u5404\u79cd\u7ec4\u7ec7\u673a\u6784\u3002 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u60f3\u8981\u5fae\u4fe1\u5f00\u53d1\uff0c\u9996\u5148\u8981\u6709\u4e2a\u670d\u52a1\u5668\uff0c\u4f46\u662f\u81ea\u5df1\u6ca1\u6709\u3002\u8fd9\u65f6\u5019\u53ef\u4ee5\u7528\u82b1\u751f\u58f3\uff0c\u5c06\u5185\u7f51\u6620\u5c04\u5230\u516c\u7f51\u4e0a\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728\u516c\u7f51\u8bbf\u95ee\u81ea\u5df1\u7684\u7f51\u7ad9\u4e86\u3002 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u7136\u540e\u8981\u5199\u4e00\u4e2a\u63a5\u5165\u4ee3\u7801\uff0c\u800c\u5fae\u4fe1\u4e0a\u53ea\u6709php\u662f\u793a\u4f8b\u3002\u8fd9\u91cc\u9644\u4e0a\u7684\u793a\u4f8b\u3002 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u9996\u5148\u521b\u5efa\u4e00\u4e2aDefault.aspx\u3002\u5728Page_Load\u91cc\u8fdb\u884c\u68c0\u9a8c\uff1a\uff08MyLog\u662f\uff0c\u53ef\u4ee5\u5ffd\u7565\uff09&nbsp;&nbsp;&nbsp;\u5173\u4e8echeckSignature()\u5c31\u548c\u6240\u67e5\u5230\u7684\u5dee\u4e0d\u591a\u4e86\u3002\u8fd9\u91cc\u8d34\u4e00\u4e0b&nbsp;&nbsp; MyLog.DebugInfo(&#8220;request default.aspx&#8221;); String echoStr = Request.QueryString[&#8220;echostr&#8221;]; MyLog.DebugInfo(&#8220;echoStr:&#8221;+echoStr); if (this.checkSignature()) { if(!string.IsNullOrEmpty(echoStr)){ MyLog.DebugInfo(&#8220;echostr:&#8221; + echoStr); Response.Write(echoStr); Response.End(); } } \u767b\u5f55\u540e\u590d\u5236 \u6700\u6700\u4e3b\u8981\u7684\u662f\u90a3\u53e5Response.End()\uff0c\u4e0d\u52a0\u8fd9\u4e00\u53e5\u600e\u4e48\u6837\u90fd\u63a5\u4e0d\u8fdb\u53bb\uff08\u5e0c\u671b\u6709\u5927\u795e\u544a\u77e5\uff09\u3002 \u5173\u4e8echeckSignature()\u5c31\u548c\u6240\u67e5\u5230\u7684\u5dee\u4e0d\u591a\u4e86\u3002\u8fd9\u91cc\u8d34\u4e00\u4e0b private bool checkSignature() { string signature = Request[&#8220;signature&#8221;]; string timestamp = Request[&#8220;timestamp&#8221;]; string nonce = Request[&#8220;nonce&#8221;]; MyLog.DebugInfo(String.Format(&#8220;signature:{0},timestamp:{1},nonce:{2}&#8221;, signature, timestamp, nonce)); string token = TOKEN; string[] tmpArr = new string[] { [&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-29179","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29179","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=29179"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29179\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=29179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=29179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=29179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}