Esempio n. 1
0
        public async Task <string> ExecuteAsync()
        {
            var result = "";

            if (!string.IsNullOrEmpty(HttpRequest.QueryString["echostr"]))
            {
                WeiXinRequest = new ValidRequest(this);
            }
            else
            {
                try
                {
                    _logger.LogInformation("后台接收到数据流:{0}", XDoc.ToString());
                    Type type = RequestTypes.Find(T => T.Name.Equals(string.Format("{0}Request", XDoc.Root.Element("MsgType").Value), StringComparison.CurrentCultureIgnoreCase));

                    if (type != null)
                    {
                        WeiXinRequest = (WeiXinRequest)Activator.CreateInstance(type, new object[1] {
                            this
                        });
                    }
                    else
                    {
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogInformation("命令执行出错:{0}", ex.StackTrace);
                }
            }

            ICommand command = Commands.Find(C => C.CanExecute);

            if (command != null)
            {
                try
                {
                    WeiXinResponse = await command.ExecuteAsync();

                    result = WeiXinResponse.ToString();
                }
                catch (Exception ex)
                {
                    _logger.LogInformation("命令执行出错:{0}", ex.StackTrace);
                }
            }

            return(result);
        }