/// <summary>
        /// 调用。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <returns>任务。</returns>
        public override Task Invoke(IHandlerContext context)
        {
            var dependencyResolver    = context.GetDependencyResolver();
            var requestMessageFactory = dependencyResolver.GetService <IRequestMessageFactory>();

            var content    = context.Content;
            var parameters = context.GetRequestParameters();


            if (parameters.ContainsKey("encrypt_type"))
            {
                var nonce     = parameters["nonce"];
                var signature = parameters["msg_signature"];
                var timestamp = parameters["timestamp"];

                var baseInfo       = context.GetMessageHandlerBaseInfo();
                var appId          = baseInfo.AppId;
                var encodingAesKey = baseInfo.EncodingAesKey;
                var token          = baseInfo.Token;

                var wxBizMsgCrypt = new WXBizMsgCrypt(token, encodingAesKey, appId);
                wxBizMsgCrypt.DecryptMsg(signature, timestamp, nonce, content, ref content);
            }


            context.SetRequestMessage(requestMessageFactory.CreateRequestMessage(content));

            return(Next.Invoke(context));
        }
        /// <summary>
        /// 调用。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <returns>任务。</returns>
        public override Task Invoke(IHandlerContext context)
        {
            var request               = context.Request;
            var dependencyResolver    = context.GetDependencyResolver();
            var requestMessageFactory = dependencyResolver.GetService <IRequestMessageFactory>();

            var content = Encoding.UTF8.GetString(request.InputStream.ReadBytes());

            #region Decrypt

            var encryptType = request.QueryString["encrypt_type"];

            if (encryptType != null)
            {
                var nonce     = request.QueryString["nonce"];
                var signature = request.QueryString["msg_signature"];
                var timestamp = request.QueryString["timestamp"];

                var baseInfo       = context.GetMessageHandlerBaseInfo();
                var appId          = baseInfo.AppId;
                var encodingAesKey = baseInfo.EncodingAesKey;
                var token          = baseInfo.Token;

                var wxBizMsgCrypt = new WXBizMsgCrypt(token, encodingAesKey, appId);
                wxBizMsgCrypt.DecryptMsg(signature, timestamp, nonce, content, ref content);
            }

            #endregion Decrypt

            context.SetRequestMessage(requestMessageFactory.CreateRequestMessage(content));

            return(Next.Invoke(context));
        }
        /// <summary>
        /// ���á�
        /// </summary>
        /// <param name="context">���������ġ�</param>
        /// <returns>����</returns>
        public override Task Invoke(IHandlerContext context)
        {
            var request = context.Request;
            var dependencyResolver = context.GetDependencyResolver();
            var requestMessageFactory = dependencyResolver.GetService<IRequestMessageFactory>();

            var content = Encoding.UTF8.GetString(request.InputStream.ReadBytes());

            #region Decrypt

            var encryptType = request.QueryString["encrypt_type"];

            if (encryptType != null)
            {
                var nonce = request.QueryString["nonce"];
                var signature = request.QueryString["msg_signature"];
                var timestamp = request.QueryString["timestamp"];

                var baseInfo = context.GetMessageHandlerBaseInfo();
                var appId = baseInfo.AppId;
                var encodingAesKey = baseInfo.EncodingAesKey;
                var token = baseInfo.Token;

                var wxBizMsgCrypt = new WXBizMsgCrypt(token, encodingAesKey, appId);
                wxBizMsgCrypt.DecryptMsg(signature, timestamp, nonce, content, ref content);
            }

            #endregion Decrypt

            context.SetRequestMessage(requestMessageFactory.CreateRequestMessage(content));

            return Next.Invoke(context);
        }
示例#4
0
        /// <summary>
        /// 调用。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <returns>任务。</returns>
        public override Task Invoke(IHandlerContext context)
        {
            _sessionCollection = context.GetDependencyResolver().GetService <IUserSessionCollection>();

            var requestMessage = context.GetRequestMessage();

            //设置用户会话。
            context.SetSession(_sessionCollection.GetOrAdd(requestMessage.FromUserName));

            return(Next.Invoke(context));
        }
示例#5
0
        /// <summary>
        /// 调用。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <returns>任务。</returns>
        public override Task Invoke(IHandlerContext context)
        {
            var responseMessage = context.GetResponseMessage();

            if (responseMessage == null)
            {
                context.ResponseXml = string.Empty;
            }
            else
            {
                var requestMessage = context.GetRequestMessage();

                //基本信息初始化。
                responseMessage.CreateTime   = DateTime.Now;
                responseMessage.FromUserName = requestMessage.ToUserName;
                responseMessage.ToUserName   = requestMessage.FromUserName;

                var dependencyResolver     = context.GetDependencyResolver();
                var responseMessageFactory = dependencyResolver.GetService <IResponseMessageFactory>();
                var content = responseMessageFactory.GetXmlByReponseMessage(responseMessage);

                #region Encrypt

                if (!string.IsNullOrWhiteSpace(content))
                {
                    var request     = context.Request;
                    var encryptType = request.QueryString["encrypt_type"];

                    if (encryptType != null)
                    {
                        var nonce     = request.QueryString["nonce"];
                        var timestamp = request.QueryString["timestamp"];

                        var baseInfo       = context.GetMessageHandlerBaseInfo();
                        var appId          = baseInfo.AppId;
                        var encodingAesKey = baseInfo.EncodingAesKey;
                        var token          = baseInfo.Token;

                        var wxBizMsgCrypt = new WXBizMsgCrypt(token, encodingAesKey, appId);
                        wxBizMsgCrypt.EncryptMsg(content, timestamp, nonce, ref content);
                    }
                }

                #endregion Encrypt

                context.ResponseXml = content;
            }

            return(Next.Invoke(context));
        }
        /// <summary>
        /// 调用。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <returns>任务。</returns>
        public override Task Invoke(IHandlerContext context)
        {
            var responseMessage = context.GetResponseMessage();

            if (responseMessage == null)
            {
                context.ResponseXml = string.Empty;
            }
            else
            {
                var requestMessage = context.GetRequestMessage();

                //基本信息初始化。
                responseMessage.CreateTime = DateTime.Now;
                responseMessage.FromUserName = requestMessage.ToUserName;
                responseMessage.ToUserName = requestMessage.FromUserName;

                var dependencyResolver = context.GetDependencyResolver();
                var responseMessageFactory = dependencyResolver.GetService<IResponseMessageFactory>();
                var content = responseMessageFactory.GetXmlByReponseMessage(responseMessage);

                #region Encrypt

                if (!string.IsNullOrWhiteSpace(content))
                {
                    var request = context.Request;
                    var encryptType = request.QueryString["encrypt_type"];

                    if (encryptType != null)
                    {
                        var nonce = request.QueryString["nonce"];
                        var timestamp = request.QueryString["timestamp"];

                        var baseInfo = context.GetMessageHandlerBaseInfo();
                        var appId = baseInfo.AppId;
                        var encodingAesKey = baseInfo.EncodingAesKey;
                        var token = baseInfo.Token;

                        var wxBizMsgCrypt = new WXBizMsgCrypt(token, encodingAesKey, appId);
                        wxBizMsgCrypt.EncryptMsg(content, timestamp, nonce, ref content);
                    }
                }

                #endregion Encrypt

                context.ResponseXml = content;
            }

            return Next.Invoke(context);
        }
        /// <summary>
        /// 调用。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <returns>任务。</returns>
        public override Task Invoke(IHandlerContext context)
        {
            var request = context.Request;
            var signature = request.QueryString["signature"];
            var timestamp = request.QueryString["timestamp"];
            var nonce = request.QueryString["nonce"];
            var token = context.GetMessageHandlerBaseInfo().Token;

            var dependencyResolver = context.GetDependencyResolver();
            var signatureService = dependencyResolver.GetService<ISignatureService>();
            if (!signatureService.Check(signature, timestamp, nonce, token))
                throw new Exception("非法请求。");

            return Next.Invoke(context);
        }
        /// <summary>
        /// 调用。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <returns>任务。</returns>
        public override Task Invoke(IHandlerContext context)
        {
            var request   = context.Request;
            var signature = request.QueryString["signature"];
            var timestamp = request.QueryString["timestamp"];
            var nonce     = request.QueryString["nonce"];
            var token     = context.GetMessageHandlerBaseInfo().Token;

            var dependencyResolver = context.GetDependencyResolver();
            var signatureService   = dependencyResolver.GetService <ISignatureService>();

            if (!signatureService.Check(signature, timestamp, nonce, token))
            {
                throw new Exception("非法请求。");
            }

            return(Next.Invoke(context));
        }
        /// <summary>
        /// 调用。
        /// </summary>
        /// <param name="context">处理上下文。</param>
        /// <returns>任务。</returns>
        public override Task Invoke(IHandlerContext context)
        {
            _sessionCollection = context.GetDependencyResolver().GetService<IUserSessionCollection>();

            var requestMessage = context.GetRequestMessage();
            //设置用户会话。
            context.SetSession(_sessionCollection.GetOrAdd(requestMessage.FromUserName));

            return Next.Invoke(context);
        }