微信公众平台校验

 

 

public partial class MPVerify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var echostr = Request.QueryString["echostr"].ToString();
        if (Verify())
        {
            Response.Write(echostr);
            Response.End();
        }
        else
        {
            
            Response.End();
        }
    }

    private bool Verify()
    {
        var signature = Request.QueryString["signature"].ToString();
        var timestamp = Request.QueryString["timestamp"].ToString();
        var nonce = Request.QueryString["nonce"].ToString();
        var token = "yy2056";

        string[] ArrTmp = { token, timestamp, nonce };
        Array.Sort(ArrTmp);     //字典排序
        string tmpStr = string.Join("", ArrTmp);
        tmpStr = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");
        tmpStr = tmpStr.ToLower();
        if (tmpStr == signature)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

 

微信公众平台校验

上一篇:接收微信公众号post数据中文乱码


下一篇:微信朋友圈广告详细说明