/// <summary>
        /// 获取响应消息和实体之间的映射结果
        /// </summary>
        /// <param name="responseMsgType"></param>
        /// <returns></returns>
        public override IResponseMessageBase GetResponseEntityMappingResult(ResponseMsgType responseMsgType, XDocument doc = null)
        {
            ResponseMessageBase responseMessage;

            switch (responseMsgType)
            {
            case ResponseMsgType.Text:
                responseMessage = new ResponseMessageText();
                break;

            case ResponseMsgType.News:
                responseMessage = new ResponseMessageNews();
                break;

            case ResponseMsgType.Music:
                responseMessage = new ResponseMessageMusic();
                break;

            case ResponseMsgType.Image:
                responseMessage = new ResponseMessageImage();
                break;

            case ResponseMsgType.Voice:
                responseMessage = new ResponseMessageVoice();
                break;

            case ResponseMsgType.Video:
                responseMessage = new ResponseMessageVideo();
                break;

            case ResponseMsgType.Transfer_Customer_Service:
                responseMessage = new ResponseMessageTransfer_Customer_Service();
                break;

            case ResponseMsgType.NoResponse:
                responseMessage = new ResponseMessageNoResponse();
                break;

            case ResponseMsgType.SuccessResponse:
                responseMessage = new SuccessResponseMessage();
                break;

                #region 扩展类型
            case ResponseMsgType.MultipleNews:
            case ResponseMsgType.LocationMessage:
            case ResponseMsgType.UseApi:
                #endregion

            case ResponseMsgType.MpNews:
            case ResponseMsgType.Unknown:
            case ResponseMsgType.Other:
            default:
                responseMessage = new ResponseMessageUnknownType()
                {
                    ResponseDocument = doc
                };
                break;
            }
            return(responseMessage);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 订阅(关注)事件
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage)
        {
            Task.Run(() =>
            {
                string openId = requestMessage.FromUserName;
                var replyItem = MpEventBll.GetByKey("ych_subscribe");
                if (replyItem != null)
                {
                    switch (replyItem.ReplyType)
                    {
                    case "text":
                        CustomApi.SendText(BaseClass.AppId, openId, EConvert.ConvertEmojiHtml(Senparc.Weixin.HttpUtility.RequestUtility.UrlDecode(replyItem.ReplyContent)));
                        break;

                    case "img":
                        CustomApi.SendImage(BaseClass.AppId, openId, replyItem.ReplyContent);
                        break;
                    }
                }
            });
            //将消息转发到客服
            var responseMessage = new SuccessResponseMessage();

            return(responseMessage);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Click事件接收
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            Task.Run(() =>
            {
                try
                {
                    string key    = requestMessage.EventKey;
                    string openId = requestMessage.FromUserName;
                    var replyItem = MpEventBll.GetByKey(key);
                    if (replyItem != null)
                    {
                        switch (replyItem.ReplyType)
                        {
                        case "text":
                            CustomApi.SendText(BaseClass.AppId, openId, replyItem.ReplyContent);
                            break;

                        case "img":
                            CustomApi.SendImage(BaseClass.AppId, openId, replyItem.ReplyContent);
                            break;

                        case "news":
                            CustomApi.SendMpNews(BaseClass.AppId, openId, replyItem.ReplyContent);
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    LogHandler.Error($"错误位置:微信CLIKC事件回复\n请求数据:{JsonConvert.SerializeObject(requestMessage)}\n错误信息:{e.StackTrace}");
                }
            });
            var responseMessage = new SuccessResponseMessage();

            return(responseMessage);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取响应消息
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <param name="responseConfigs"></param>
        /// <param name="messageHandler"></param>
        /// <param name="accessTokenOrApi"></param>
        /// <returns></returns>
        private IResponseMessageBase GetResponseMessage(IRequestMessageBase requestMessage, List <Response> responseConfigs, IMessageHandlerEnlightener messageHandler, string accessTokenOrApi)
        {
            IResponseMessageBase responseMessage = null;

            responseConfigs = responseConfigs ?? new List <Response>();
            if (responseConfigs.Count == 0)
            {
                return(null);
            }

            //扩展响应,会在消息回复之前发送
            var extendReponses = responseConfigs.Count > 1
                    ? responseConfigs.Take(responseConfigs.Count - 1).ToList()
                    : new List <Response>();

            //获取最后一个响应设置
            var lastResponse = responseConfigs.Last();//取最后一个

            //处理特殊情况
            if (messageHandler.MessageEntityEnlightener.PlatformType == PlatformType.WeChat_MiniProgram)
            {
                //小程序,所有的请求都使用客服消息接口,回填取出的最后一个
                extendReponses.Add(lastResponse);
                lastResponse = new Response()
                {
                    Type = ResponseMsgType.SuccessResponse
                };                                                                       //返回成功信息
                responseMessage = new SuccessResponseMessage();
            }

            //第一项,优先使用消息回复
            switch (lastResponse.Type)
            {
            case ResponseMsgType.Text:
                responseMessage = RenderResponseMessageText(requestMessage, lastResponse, messageHandler.MessageEntityEnlightener);

                break;

            case ResponseMsgType.News:
                responseMessage = RenderResponseMessageNews(requestMessage, lastResponse, messageHandler.MessageEntityEnlightener);
                break;

            case ResponseMsgType.Music:
                break;

            case ResponseMsgType.Image:
                responseMessage = RenderResponseMessageImage(requestMessage, lastResponse, messageHandler.MessageEntityEnlightener);
                break;

            case ResponseMsgType.Voice:
                break;

            case ResponseMsgType.Video:
                break;

            case ResponseMsgType.Transfer_Customer_Service:
                break;

            case ResponseMsgType.MultipleNews:
                break;

            case ResponseMsgType.LocationMessage:
                break;

            case ResponseMsgType.NoResponse:
                responseMessage = RenderResponseMessageNoResponse(requestMessage, lastResponse, messageHandler.MessageEntityEnlightener);
                break;

            case ResponseMsgType.SuccessResponse:
                responseMessage = RenderResponseMessageSuccessResponse(requestMessage, lastResponse, messageHandler.MessageEntityEnlightener);
                break;

            case ResponseMsgType.UseApi:    //常规官方平台转发的请求不会到达这里
                break;

            default:
                break;
            }

            //使用客服接口(高级接口)发送
            ExecuteApi(extendReponses, requestMessage, messageHandler.ApiEnlightener, accessTokenOrApi, requestMessage.FromUserName);

            return(responseMessage);
        }