62,025
社区成员
发帖
与我相关
我的任务
分享
public class Certificate {
/// <summary>
/// 微信认证
/// </summary>
public static string Renzhen(string signature, string timestamp, string nonce, string echostr)
{
string res = "";
string token = "token";
if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(signature) || string.IsNullOrEmpty(timestamp) || string.IsNullOrEmpty(nonce) || string.IsNullOrEmpty(echostr))
{
res = "error";
}
else
{
ArrayList arr = new ArrayList() { token, signature, nonce };
arr.Sort();
string signature1 = GetSHA1(arr[0].ToString() + arr[1].ToString() + arr[2].ToString());
if (signature1.ToLower() == signature)
{
res = echostr;
}
else
{
res = "error";
}
}
return res;
}
/// <summary>
/// 加密字符串
/// </summary>
/// <param name="password"></param>
/// <returns></returns>
public static string GetSHA1(string password)
{
string sha1string = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "SHA1");
return sha1string;
}
}
public void ProcessRequest(HttpContext context)
{
// context.Response.ContentType = "text/plain";
string signature = context.Request.QueryString["signature"];
string timestamp = context.Request.QueryString["timestamp"];
string nonce = context.Request.QueryString["nonce"];
string echostr = context.Request.QueryString["echostr"];
string res = Certificate.Renzhen(signature, timestamp, nonce, echostr);
context.Response.Write(res);
context.Response.End();
}