You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/Mobile/Views/WeChatHandler/Index.aspx.cs

69 lines
2.1 KiB
C#

2 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DSWeb.Areas.Mobile.DAL;
using System.Web.Security;
namespace DSWeb.Areas.Mobile.Views.WeChatHandler
{
public partial class Index : System.Web.Mvc.ViewPage
{
/// <summary>
/// 微信服务器开发验证类
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load ( object sender, EventArgs e )
{
Response.Write(Valid());
Response.End();
DBLog.Log(Request.RequestContext.ToString());
}
private string Valid ( )
{
string rtnStr = "";
string echoStr = Request.QueryString["echoStr"].ToString();
DBLog.Log("Valid1");
if (CheckSignature())
{
DBLog.Log("Valid2");
if (!string.IsNullOrEmpty(echoStr))
{
DBLog.Log("Valid3");
rtnStr = echoStr;
DBLog.Log("echoStr-" + echoStr);
}
}
DBLog.Log("Valid4");
return rtnStr;
}
private bool CheckSignature ( )
{
DBLog.Log("CheckSignature-1");
string signature = Request.QueryString["signature"].ToString();
string timestamp = Request.QueryString["timestamp"].ToString();
string nonce = Request.QueryString["nonce"].ToString();
string[] ArrTmp = { "Token", timestamp, nonce };
Array.Sort(ArrTmp); //字典排序
string tmpStr = string.Join("", ArrTmp);
tmpStr = FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");
DBLog.Log("CheckSignature-2");
tmpStr = tmpStr.ToLower();
if (tmpStr == signature)
{
DBLog.Log("CheckSignature-3");
return true;
}
else
{
DBLog.Log("CheckSignature-4");
return false;
}
}
}
}