Пример #1
0
        //验证微信开发者
        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"];

            WechatLogHelper.Info(signature);
            string[] ArrTmp = { token, timestamp, nonce };

            Array.Sort(ArrTmp);
            string tmpStr = string.Join("", ArrTmp);

            tmpStr = WechatEncrypt.SHA1(tmpStr);

            tmpStr = tmpStr.ToLower();

            WechatLogHelper.Info(tmpStr);


            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();
            }
        }
Пример #2
0
        public static string GetSignature(string jsapi_ticket, string nonceStr, string timestamp, string currentUrl)
        {
            string string1 = string.Format("jsapi_ticket={0}&noncestr={1}&timestamp={2}&url={3}", jsapi_ticket, nonceStr, timestamp, currentUrl);

            //      string string1 = "jsapi_ticket=" + jsapi_ticket +"&noncestr=" + "zhaozhengo" +"&timestamp=" + "1414587487" +"&url=" + currentUrl;
            return(WechatEncrypt.SHA1(string1));
        }