Exemplo n.º 1
0
        /// <summary>
        /// 在OnText\OnEvent 之后执行
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override Task OnExecutedAsync(CancellationToken cancellationToken)
        {
            if (ResponseMessage is ResponseMessageText)
            {
                if (ResponseMessage != null)
                {
                    (ResponseMessage as ResponseMessageText).Content += "【消息签名】";
                }
            }

            Thread.Sleep(5000);

            EndTime = DateTime.Now;
            var runtime = (EndTime - BeginTime).TotalSeconds;

            //执行时长超过5秒,用户可能就收不到MessageHandler的消息了;
            //所以要想办法给用户消息回复
            if (runtime > 4)
            {
                MessageQueueHandler messageQueueHandler = new MessageQueueHandler();
                var responseMessageResult = messageQueueHandler.SendMessage(base.OpenId, ResponseMessage);
            }

            return(base.OnExecutedAsync(cancellationToken));
        }
        /// <summary>
        /// 业务上适用于添加消息签名,或者消息过滤处理
        /// </summary>
        public override void OnExecuted()
        {
            if (ResponseMessage is ResponseMessageText)
            {
                ((ResponseMessageText)ResponseMessage).Content += "\r\n【消息签名】";

                //开队列或者线程,处理数据库相关问题

                //Thread.Sleep(5000);//这样超出5s没有返回消息给微信Server。

                //有可能超时的时候,借用客服消息返回用户信息
                EndTime = DateTime.Now;
                int runTime = (EndTime - StartTime).Seconds;
                if (runTime > 4)
                {
                    //使用客服消息返回信息
                    ////CustomApi.SendText(Config.AppId, base.WeixinOpenId,
                    ////   ((ResponseMessageText)ResponseMessage).Content + "\r\n" + "【客服消息】");

                    //ResponseMessage = new ResponseMessageNoResponse();

                    MessageQueueHandler messageQueueHandler = new MessageQueueHandler();
                    messageQueueHandler.SendKfMessage(base.WeixinOpenId, ResponseMessage);
                }
            }
            base.OnExecuted();
        }