想要微信开发,首先要有个服务器,但是自己没有。这时候可以用花生壳,将内网映射到公网上,这样就可以在公网访问自己的网站了。
然后要写一个接入代码,而微信上只有php是示例。这里附上asp.net的示例。
首先创建一个Default.aspx。在Page_Load里进行检验:(MyLog是日志类,可以忽略) 关于checkSignature()就和所查到的差不多了。这里贴一下
MyLog.DebugInfo(request default.aspx); String echoStr = Request.QueryString[echostr]; MyLog.DebugInfo(echoStr:+echoStr); if (this.checkSignature()) { if(!string.IsNullOrEmpty(echoStr)){ MyLog.DebugInfo(echostr: + echoStr); Response.Write(echoStr); Response.End(); } }
最最主要的是那句Response.End(),不加这一句怎么样都接不进去(希望有大神告知)。 关于checkSignature()就和所查到的差不多了。这里贴一下
private bool checkSignature() { string signature = Request[signature]; string timestamp = Request[timestamp]; string nonce = Request[nonce]; MyLog.DebugInfo(String.Format(signature:{0},timestamp:{1},nonce:{2}, signature, timestamp, nonce)); string token = TOKEN; string[] tmpArr = new string[] { token, timestamp, nonce }; Array.Sort(tmpArr); string tmpStr = string.Join(, tmpArr); //sha1加密 System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] secArr = sha1.ComputeHash(System.Text.Encoding.Default.GetBytes(tmpStr)); tmpStr = BitConverter.ToString(secArr).Replace(-, ).ToLower(); MyLog.DebugInfo(String.Format(after parse:{0}, tmpStr)); if (tmpStr == signature) { MyLog.DebugInfo(true); return true; } else { return false; } }
这里主要是因为那个Response.End()的问题,导致我搞了许久,特此记录一下,希望帮助能帮助到的人。
还有一点可能是因为微信服务器的原因Token验证失败,多点2次即可,别像我这样只点一次啊!!!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。