/// <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);
        }
Beispiel #2
0
        public virtual ResponseMessageBase ToResponseMessage()
        {
            var res = new ResponseMessageTransfer_Customer_Service();

            foreach (var tras in this.TransInfo)
            {
                var a = new CustomerServiceAccount()
                {
                    KfAccount = tras.KfAccount,
                };
                res.TransInfo.Add(a);
            }
            return(res);
        }
Beispiel #3
0
        //<?xml version="1.0" encoding="utf-8"?>
        //<xml>
        //  <ToUserName><![CDATA[olPjZjsXuQPJoV0HlruZkNzKc91E]]></ToUserName>
        //  <FromUserName><![CDATA[gh_a96a4a619366]]></FromUserName>
        //  <CreateTime>63497820384</CreateTime>
        //  <MsgType>text</MsgType>
        //  <Content><![CDATA[您刚才发送了文字信息:中文
        //您还可以发送【位置】【图片】【语音】信息,查看不同格式的回复。
        //SDK官方地址:http://sdk.weixin.senparc.com]]></Content>
        //  <FuncFlag>0</FuncFlag>
        //</xml>

        /// <summary>
        /// 获取XDocument转换后的IResponseMessageBase实例(通常在反向读取日志的时候用到)。
        /// 如果MsgType不存在,抛出UnknownRequestMsgTypeException异常
        /// </summary>
        /// <returns></returns>
        public static IResponseMessageBase GetResponseEntity(XDocument doc)
        {
            ResponseMessageBase responseMessage = null;
            ResponseMsgType     msgType;

            try
            {
                msgType = MsgTypeHelper.GetResponseMsgType(doc);
                switch (msgType)
                {
                case ResponseMsgType.Text:
                    responseMessage = new ResponseMessageText();
                    break;

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

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

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

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

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

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

                default:
                    throw new UnknownRequestMsgTypeException(string.Format("MsgType:{0} 在ResponseMessageFactory中没有对应的处理程序!", msgType), new ArgumentOutOfRangeException());
                }
                EntityHelper.FillEntityWithXml(responseMessage, doc);
            }
            catch (ArgumentException ex)
            {
                throw new WeixinException(string.Format("ResponseMessage转换出错!可能是MsgType不存在!,XML:{0}", doc.ToString()), ex);
            }
            return(responseMessage);
        }