/// <summary>
        /// 处理视频请求
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override async Task <IResponseMessageBase> OnVideoRequestAsync(RequestMessageVideo requestMessage)
        {
            try
            {
                var opid      = requestMessage.FromUserName;
                var entitymsg = new MpEventRequestMsgLogDto();

                entitymsg.MpID    = mpId;
                entitymsg.OpenID  = opid;
                entitymsg.MsgType = requestMessage.MsgType.ToString();
                entitymsg.MsgId   = requestMessage.MsgId.ToString();
                entitymsg.MediaId = requestMessage.MediaId;
                await _mpEventRequestMsgLogAppService.Create(entitymsg);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("MPID{0}记录视频回复信息出错:原因{1}", mpId, ex.Message));
            }


            #region 客服逻辑处理
            var kefuHandler = _iocResolver.Resolve <IKeFuMessageHandler>();
            if (await kefuHandler.IsAsking(mpId, requestMessage.FromUserName))
            {
                await kefuHandler.Ask(mpId, requestMessage.FromUserName, requestMessage.MsgType.ToString(), requestMessage.MediaId);

                return(requestMessage.CreateResponseMessage <ResponseMessageNoResponse>());
            }
            #endregion

            return(await DefaultResponseMessageAsync(requestMessage));
        }
 /// <summary>
 /// 处理链接消息请求
 /// </summary>
 /// <param name="requestMessage"></param>
 /// <returns></returns>
 public override async Task <IResponseMessageBase> OnLinkRequestAsync(RequestMessageLink requestMessage)
 {
     try
     {
         var opid      = requestMessage.FromUserName;
         var entitymsg = new MpEventRequestMsgLogDto();
         entitymsg.MpID        = mpId;
         entitymsg.OpenID      = opid;
         entitymsg.MsgType     = requestMessage.MsgType.ToString();
         entitymsg.MsgId       = requestMessage.MsgId.ToString();
         entitymsg.Title       = requestMessage.Title;
         entitymsg.Description = requestMessage.Description;
         entitymsg.AUrl        = requestMessage.Url;
         await _mpEventRequestMsgLogAppService.Create(entitymsg);
     }
     catch (Exception ex)
     {
         _logger.Error(string.Format("MPID{0}记录链接回复信息出错:原因{1}", mpId, ex.Message));
     }
     return(await DefaultResponseMessageAsync(requestMessage));
 }
        /// <summary>
        /// 处理文字请求
        /// </summary>
        /// <returns></returns>
        public override async Task <IResponseMessageBase> OnTextRequestAsync(RequestMessageText requestMessage)
        {
            var defaultMessage = await DefaultResponseMessageAsync(requestMessage);

            if (string.IsNullOrEmpty(requestMessage.Content))
            {
                return(defaultMessage);
            }
            #region 记录日志
            try
            {
                var opid      = requestMessage.FromUserName;
                var entitymsg = new MpEventRequestMsgLogDto();

                entitymsg.MpID    = mpId;
                entitymsg.OpenID  = opid;
                entitymsg.MsgType = requestMessage.MsgType.ToString();
                entitymsg.MsgId   = requestMessage.MsgId.ToString();
                entitymsg.Content = requestMessage.Content;
                await _mpEventRequestMsgLogAppService.Create(entitymsg);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("MPID{0}记录文本回复信息出错:原因{1}", mpId, ex.Message));
            }
            #endregion

            _logger.Info($"开始处理文本消息 {requestMessage.FromUserName} {requestMessage.Content}");
            #region 春雨医生逻辑处理
            var chunyuHandler = _iocResolver.Resolve <IChunYuMessageHandler>();
            if (await chunyuHandler.IsAsking(mpId, requestMessage.FromUserName))
            {
                _logger.Info($"春雨医生正在会话 {requestMessage.FromUserName} {requestMessage.Content}");
                await chunyuHandler.Ask(mpId, requestMessage.FromUserName, requestMessage.MsgType.ToString(), requestMessage.Content);

                return(requestMessage.CreateResponseMessage <ResponseMessageNoResponse>());
            }
            #endregion

            #region 客服逻辑处理
            _logger.Info($"春雨医生没有会话 {requestMessage.FromUserName} {requestMessage.Content}");
            var kefuHandler = _iocResolver.Resolve <IKeFuMessageHandler>();
            if (await kefuHandler.IsAsking(mpId, requestMessage.FromUserName))
            {
                _logger.Info($"客服正在会话 {requestMessage.FromUserName} {requestMessage.Content}");
                await kefuHandler.Ask(mpId, requestMessage.FromUserName, requestMessage.MsgType.ToString(), requestMessage.Content);

                return(requestMessage.CreateResponseMessage <ResponseMessageNoResponse>());
            }
            _logger.Info($"客服没有会话 {requestMessage.FromUserName} {requestMessage.Content}");
            #endregion

            var account = await _mpAccountAppService.GetCache(mpId);

            var rs = await _cacheManager.GetCache(AppConsts.Cache_CallBack).GetOrDefaultAsync(string.Format("TextRequest_{0}_{1}", account.AppId, requestMessage.Content));

            var rstype = await _cacheManager.GetCache(AppConsts.Cache_CallBack).GetOrDefaultAsync(string.Format("TextRequest_{0}_{1}_Type", account.AppId, requestMessage.Content));

            var rsid = await _cacheManager.GetCache(AppConsts.Cache_CallBack).GetOrDefaultAsync(string.Format("TextRequest_{0}_{1}_Id", account.AppId, requestMessage.Content));

            var firstkey = await _cacheManager.GetCache(AppConsts.Cache_FirstKeyWordReply).GetOrDefaultAsync(requestMessage.FromUserName);


            #region 短时间内输入过一级回复,则查询当次输入是否属于二级回复
            if (firstkey != null)
            {
                var keyid = Convert.ToInt32(firstkey);
                var srs   = await _cacheManager.GetCache(AppConsts.Cache_CallBack).GetOrDefaultAsync(string.Format("TextRequest_{0}_{1}_{2}_Second", account.AppId, keyid, requestMessage.Content));

                var srstype = await _cacheManager.GetCache(AppConsts.Cache_CallBack).GetOrDefaultAsync(string.Format("TextRequest_{0}_{1}_{2}_Second_Type", account.AppId, keyid, requestMessage.Content));

                if (srs == null || srstype == null)
                {
                    var mpSecondKeyWordReplyAppService = _iocResolver.Resolve <IMpSecondKeyWordReplyAppService>();
                    var reply = await mpSecondKeyWordReplyAppService.GetEntityByKeyWordAsync(requestMessage.Content, keyid);

                    if (reply != null)
                    {
                        await _cacheManager.GetCache(AppConsts.Cache_CallBack).SetAsync(string.Format("TextRequest_{0}_{1}_{2}_Second_Type", account.AppId, keyid, requestMessage.Content), reply.ReplyType);

                        var res = await GetEntityResponse(reply.ReplyType, reply.ImageMediaID, reply.Content, reply.VoiceMediaID, (reply.VideoID ?? -1).ToString(), (reply.ArticleID ?? -1).ToString(), (reply.ArticleGroupID ?? -1).ToString());

                        if (res != null)
                        {
                            await _cacheManager.GetCache(AppConsts.Cache_CallBack).SetAsync(string.Format("TextRequest_{0}_{1}_{2}_Second", account.AppId, keyid, requestMessage.Content), res);

                            return(res);
                        }
                        else
                        {
                            return(requestMessage.CreateResponseMessage <ResponseMessageNoResponse>());
                        }
                    }
                }
                else
                {
                    var res = await GetCacheResponse(srstype.ToString(), srs);

                    if (res != null)
                    {
                        return(res);
                    }
                }
            }
            #endregion

            #region 没有命中二级回复,则查询一级回复
            if (rs == null || rstype == null || rsid == null)
            {
                //关键字回复
                var entity = await _mpKeyWordReplyAppService.GetEntityByKeyWordAsync(requestMessage.Content, mpId);

                if (entity != null)
                {
                    await _cacheManager.GetCache(AppConsts.Cache_FirstKeyWordReply).SetAsync(requestMessage.FromUserName, entity.Id);

                    await _cacheManager.GetCache(AppConsts.Cache_CallBack).SetAsync(string.Format("TextRequest_{0}_{1}_Type", account.AppId, requestMessage.Content), entity.ReplyType);

                    await _cacheManager.GetCache(AppConsts.Cache_CallBack).SetAsync(string.Format("TextRequest_{0}_{1}_Id", account.AppId, requestMessage.Content), entity.Id);

                    var res = await GetEntityResponse(entity.ReplyType, entity.ImageMediaID, entity.Content, entity.VoiceMediaID, (entity.VideoID ?? -1).ToString(), (entity.ArticleID ?? -1).ToString(), (entity.ArticleGroupID ?? -1).ToString(), requestMessage);

                    if (res != null)
                    {
                        await _cacheManager.GetCache(AppConsts.Cache_CallBack).SetAsync(string.Format("TextRequest_{0}_{1}", account.AppId, requestMessage.Content), res);

                        return(res);
                    }
                    else
                    {
                        var none = requestMessage.CreateResponseMessage <ResponseMessageNoResponse>();
                        await _cacheManager.GetCache(AppConsts.Cache_CallBack).SetAsync(string.Format("TextRequest_{0}_{1}", account.AppId, requestMessage.Content), none);

                        return(none);
                    }
                }
                //其他回复
                else
                {
                    return(defaultMessage);
                }
            }
            else
            {
                var replyType = (string)await _cacheManager.GetCache(AppConsts.Cache_CallBack).GetOrDefaultAsync(string.Format("TextRequest_{0}_{1}_Type", account.AppId, requestMessage.Content));

                if (replyType == ReplyMsgType.kf.ToString())
                {
                    var kefuMessageHandler = _iocResolver.Resolve <IKeFuMessageHandler>();
                    return(await kefuMessageHandler.InCustomer(mpId, requestMessage));
                }
                else
                {
                    var res = await GetCacheResponse(rstype.ToString(), rs, requestMessage);

                    if (res != null)
                    {
                        await _cacheManager.GetCache(AppConsts.Cache_FirstKeyWordReply).SetAsync(requestMessage.FromUserName, Convert.ToInt32(rsid));

                        return(res);
                    }
                }
            }
            #endregion
            return(defaultMessage);
        }