public static string GetSignature(string jsapi_ticket, string nonceStr, string timestamp, string currentUrl) { string string1 = string.Format("jsapi_ticket={0}&noncestr={1}×tamp={2}&url={3}", jsapi_ticket, nonceStr, timestamp, currentUrl); // string string1 = "jsapi_ticket=" + jsapi_ticket +"&noncestr=" + "zhaozhengo" +"×tamp=" + "1414587487" +"&url=" + currentUrl; return(SkyEncrypt.SHA1(string1)); }
public static void Auth() { Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); AppSettingsSection appsection = config.GetSection("appSettings") as AppSettingsSection; string token = appsection.Settings["WechatToken"].Value.ToString(); string echoString = HttpContext.Current.Request.QueryString["echoStr"]; string signature = HttpContext.Current.Request.QueryString["signature"]; string timestamp = HttpContext.Current.Request.QueryString["timestamp"]; string nonce = HttpContext.Current.Request.QueryString["nonce"]; string[] ArrTmp = { token, timestamp, nonce }; Array.Sort(ArrTmp); string tmpStr = string.Join("", ArrTmp); tmpStr = SkyEncrypt.SHA1(tmpStr); tmpStr = tmpStr.ToLower(); if (tmpStr == signature) { System.Web.HttpContext.Current.Response.Write(echoString); System.Web.HttpContext.Current.Response.End(); } else { System.Web.HttpContext.Current.Response.Write("验证不通过"); System.Web.HttpContext.Current.Response.End(); } }