public static string ConvertResponseToXml(object entity)
        {
            var responseXmlString = string.Empty;

            // Just let it throw when convert entity failed.
            if (entity is IResponseMessageBase responseMessage)
            {
                switch (responseMessage.MsgType)
                {
                case ResponseMessageTypes.Text:
                    responseXmlString = EntityHelper.ConvertEntityToXmlString <TextResponse>(responseMessage);
                    break;

                case ResponseMessageTypes.Image:
                    responseXmlString = EntityHelper.ConvertEntityToXmlString <ImageResponse>(responseMessage);
                    break;

                case ResponseMessageTypes.Voice:
                    responseXmlString = EntityHelper.ConvertEntityToXmlString <VoiceResponse>(responseMessage);
                    break;

                case ResponseMessageTypes.Video:
                    responseXmlString = EntityHelper.ConvertEntityToXmlString <VideoResponse>(responseMessage);
                    break;

                case ResponseMessageTypes.Music:
                    responseXmlString = EntityHelper.ConvertEntityToXmlString <MusicResponse>(responseMessage);
                    break;

                case ResponseMessageTypes.News:
                    responseXmlString = EntityHelper.ConvertEntityToXmlString <NewsResponse>(responseMessage);
                    break;
                }
            }
            else
            {
                responseXmlString = entity.ToString();
            }

            return(responseXmlString);
        }
Exemplo n.º 2
0
        private string OnAttention(RequestMessageEventBase xmlMsg)
        {
            try
            {
                var content = "";
                ResponseMessageBase responseMessage = null;
                //如果是关注,则发送欢迎消息
                switch (xmlMsg.Event)
                {
                case Event.subscribe:
                    var res = (ResponseMessageText)ResponseMessageBase.CreateFromRequestMessage(xmlMsg, ResponseMsgType.Text);
                    res.Content     = "用户关注";
                    responseMessage = res;
                    break;

                case Event.unsubscribe:
                    content = "取消关注";
                    break;

                case Event.scan:
                    content = "扫码";
                    break;

                case Event.TEMPLATESENDJOBFINISH:
                    content = "模板消息";
                    break;

                default:
                    //不处理的消息
                    break;
                }
                return(EntityHelper.ConvertEntityToXmlString(responseMessage));
            }
            catch (Exception ex)
            {
                return("");
            }
        }