Senparc.Weixin.MP微信开发——(3)微信开发模式URL验证

在微信公众平台填写了URL,TOKEN后,微信服务器会对填写的URL,使用Token进行一次Get方式请求的验证,如果顺利通过,则保存成功,如果不通过,会给出错误信息,并且所填写的信息是无法保存的。

protected void Page_Load(object sender, EventArgs e)
{
string signature = Request["signature"];
string timestamp = Request["timestamp"];
string nonce = Request["nonce"];
string echostr = Request["echostr"];
if (Request.HttpMethod == "GET")
{
//GET-仅在微信后台填写URL验证时触发
if (Senparc.Weixin.MP.CheckSignature.Check(signature, timestamp, nonce, token))
{
WriteContent(echostr); //返回随机字符串则表示验证通过
}
else
{
WriteContent("failed:" + signature + ",token:" + token + " " + Senparc.Weixin.MP.CheckSignature.GetSignature(timestamp, nonce, token) + "。" +
"如果你在浏览器中看到这句话,说明此地址可以被作为微信公众账号后台的Url,请注意保持Token一致。");
}
Response.End();
}
}
/// <summary>
/// 写入文件流
/// </summary>
private void WriteContent(string str)
{
Response.Output.Write(str);
}

 

posted @ 2017-04-27 17:16  花影疏帘  阅读(291)  评论(0)    收藏  举报