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
{
///
/// 微信服务器开发验证类
///
///
///
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;
}
}
}
}