您现在的位置是:网站首页> 编程资料编程资料
微信开发(一) asp.net接入_实用技巧_
2023-05-24
463人已围观
简介 微信开发(一) asp.net接入_实用技巧_
想要微信开发,首先要有个服务器,但是自己没有。这时候可以用花生壳,将内网映射到公网上,这样就可以在公网访问自己的网站了。具体见:https://www.jb51.net/article/83783.htm
然后要写一个接入代码,而微信上只有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次即可,别像我这样只点一次啊!!!
您可能感兴趣的文章:
相关内容
- ASP.NET调用WebService服务的方法详解_实用技巧_
- ASP.NET使用xslt将xml转换成Excel_实用技巧_
- ASP.NET生成图形验证码的方法详解_实用技巧_
- 简单几步 实现vs2010对html5的支持_实用技巧_
- 细说SQL Server中的视图_自学过程_
- 解决Visual Studio 2012 Update 4 RC启动调试失败的方案_实用技巧_
- ASP.NET web.config中 数据库连接字符串加密解密_实用技巧_
- ASP.NET 修复 IIS 映射具体实现步骤_实用技巧_
- 使用aspnet_regiis.exe重新注册.NET Framework_实用技巧_
- aspnet_regiis.exe命令使用方法_实用技巧_
