asp.net mvc微信项目开发(一)
是不是很多人卡在这一步?
接口信息配置就是不成功
其原理是,当你提交后,微信服务器会去你提交的地址请求进行验证,因此我们需要后台写一些验证方法,代码如下:
protected void Page_Load(object sender, EventArgs e)
{
#region 验证token
string echoString = Request.QueryString["echoStr"];
string signature = Request.QueryString["signature"];
string timestamp = Request.QueryString["timestamp"];
string nonce = Request.QueryString["nonce"];
if (CheckSignature())
{
if (!string.IsNullOrEmpty(echoString))
{
LogHelper.WriteLog("echoStr="+echoString+",signature="+signature+",timestamp="+timestamp+",nonce="+nonce)
Response.Write(echoString);
}
}
#endregion
}
private bool CheckSignature()
{
string Token = "weixin";
string signature = Request.QueryString["signature"];
string timestamp = Request.QueryString["timestamp"];
string nonce = Request.QueryString["nonce"];
string[] ArrTmp = { Token, timestamp, nonce };
Array.Sort(ArrTmp); //字典排序
string tmpStr = string.Join("", ArrTmp);
tmpStr = FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");
tmpStr = tmpStr.ToLower();
if (tmpStr == signature)
{
return true;
}
else
{
return false;
}
}
这段代码完成后,即可验证成功(我是在我们自己的服务器上做的开发项目,因此没有写关于如何让微信服务器访问这个地址)
解决你的问题是第一位,如果对你有所帮助,请打赏1元(不强制,我博文里还有很多问题解决的方法,请欢迎关注)