微信接口对接验证

    //接口对接验证

        public static string Validation(HttpContext context)

        {

            string token = JobBase.GetConfParamValue(ParamEnum.Token);

            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[] ArrayParam = { timestamp, nonce, token };

            Array.Sort(ArrayParam);

            string Clear = string.Empty;

            foreach (string param in ArrayParam)

            {

                Clear += param;

            }

            string NewSignature = Cryptography.SHA1_EncryptToFormat(Clear);

            Logger.Write("OriginalString:" + context.Request.Url.OriginalString + ";Query:" + context.Request.Url.Query + ";token" + token + ";NewSignature:" + NewSignature);

            if (NewSignature == signature)

            {

                Logger.Write("验证成功");

                return echostr;

            }

            return echostr;

        }

 

你可能感兴趣的:(接口)