微信开发者验证

上代码

 1 using System;
 2 using System.Collections.Generic;
 3 using System.IO;
 4 using System.Linq;
 5 using System.Web;
 6 using System.Web.UI;
 7 using System.Web.UI.WebControls;
 8 using System.Web.Security;
 9 
10 public partial class wx_Default : System.Web.UI.Page
11 {
12     protected void Page_Load(object sender, EventArgs e)
13     {
14         HttpContext context = HttpContext.Current;
15         string _signature = Request.QueryString["signature"];
16         string _timestamp = Request.QueryString["timestamp"];
17         string _nonce = Request.QueryString["nonce"];
18         string _echostr = Request.QueryString["echostr"];
19         string token = "linkideas";
20 
21         string[] stringArray = { token, _timestamp, _nonce };
22         Array.Sort(stringArray);
23         string mergeString = string.Concat(stringArray);
24 
25         mergeString = FormsAuthentication.HashPasswordForStoringInConfigFile(mergeString, "SHA1").ToLower();
26 
27         if (_signature == mergeString)
28         {
29             Response.Clear();
30             Response.ContentType = "text/plain";
31             Response.Write(_echostr);
32             Response.End();
33         }
34     }
35 }

下边重写,易于理解,作用同上

 1 using System;
 2 using System.Collections.Generic;
 3 using System.IO;
 4 using System.Linq;
 5 using System.Web;
 6 using System.Web.UI;
 7 using System.Web.UI.WebControls;
 8 using System.Web.Security;
 9 
10 public partial class wx_Default : System.Web.UI.Page
11 {
12     protected void Page_Load(object sender, EventArgs e)
13     {
14         valid();
15     }
16 
17     HttpContext context = HttpContext.Current;
18     public void valid()
19     {
20         var echostr = context.Request["echoStr"].ToString();
21         if (checkSignature() && !string.IsNullOrEmpty(echostr))
22         {
23             Response.Clear();
24             Response.ContentType = "text/plain";
25             Response.Write(echostr);
26             Response.End();
27         }
28     }
29     public bool checkSignature()
30     {
31         var signature = context.Request["signature"].ToString();
32         var timestamp = context.Request["timestamp"].ToString();
33         var nonce = context.Request["nonce"].ToString();
34         var token = "linkideas";
35 
36         string[] ArrTmp = { token, timestamp, nonce };
37         Array.Sort(ArrTmp);//字典排序
38         string mergeString = string.Concat(ArrTmp);//作用相同 string mergeString = string.Join("", ArrTmp);
39 
40         mergeString = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(mergeString, "SHA1");
41         mergeString = mergeString.ToLower();
42         if (mergeString == signature)
43         {
44             return true;
45         }
46         else
47         {
48             return false;
49         }
50     }
51 }

 

转载于:https://www.cnblogs.com/duanyong/articles/3443495.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值