300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > c# 微信公众号开发(一)服务器配置 验证token

c# 微信公众号开发(一)服务器配置 验证token

时间:2021-12-26 16:12:10

相关推荐

c# 微信公众号开发(一)服务器配置 验证token

新建一个一般处理程序,WechartInterface.ashx

程序代码

public void ProcessRequest(HttpContext context){context.Response.ContentType = "text/plain";string token = "与网页填写的token保持一致";if (string.IsNullOrEmpty(token)){return;}string echoString = HttpContext.Current.Request.QueryString["echoStr"];string signature = HttpContext.Current.Request.QueryString["signature"];string timestamp = HttpContext.Current.Request.QueryString["timestamp"];string nonce = HttpContext.Current.Request.QueryString["nonce"];if (CheckSignature(token, signature, timestamp, nonce)){if (!string.IsNullOrEmpty(echoString)){HttpContext.Current.Response.Write(echoString);HttpContext.Current.Response.End();}}}/// <summary>/// 验证微信签名/// </summary>public static bool CheckSignature(string token, string signature, string timestamp, string nonce){string[] ArrTmp = { token, timestamp, nonce };//字典排序Array.Sort(ArrTmp);//拼接string tmpStr = string.Join("", ArrTmp);//sha1验证tmpStr = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");//tmpStr = Membership.CreateUser(tmpStr, "SHA1");tmpStr = tmpStr.ToLower();if (tmpStr == signature){return true;}else{return false;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。