Ejemplo n.º 1
0
        public string HandleText(RQBase info)
        {
            string xml = string.Empty;

            //文字处理
            try
            {
                switch (info.Content)
                {
                case "美女":    //输入美女
                    xml = new Btgirl().Execute(info.xmlmsg);
                    break;

                case "头条":    //头条
                    xml = new TouTiao().Execute(info.xmlmsg);
                    break;

                default:
                    RequestText voice = new RequestText();
                    voice.xmlmsg = info.xmlmsg;
                    //xml = new replyText().ReplyExecute(voice);
                    //xml = new DeepQA().Execute(info.xmlmsg);
                    break;
                }
            }
            catch (Exception ex)
            {
                TracingHelper.Error(ex, typeof(WeixinApiDispatch), ex.Message);
            }
            TracingHelper.Info(" HandleText  " + xml);
            return(xml);
        }
Ejemplo n.º 2
0
        public string Execute(string postStr)
        {
//            postStr = @"<xml><ToUserName><![CDATA[gh_c6fe4fcbb3a9]]></ToUserName>
//<FromUserName><![CDATA[oD2h5s1xkurbt56bcfJFMb1sSUA4]]></FromUserName>
//<CreateTime>1464576964</CreateTime>
//<MsgType><![CDATA[text]]></MsgType>
//<Content><![CDATA[美女]]></Content>
//<MsgId>6290310163258790975</MsgId>
//</xml>";
            string content = msgFinal();

            try
            {
                RQBase rqInfo = SerializeHelper.XmlDeserialize(postStr);
                //TracingHelper.Info(rqInfo.xmlmsg.ToUserName + " " + rqInfo.xmlmsg.FromUserName);
                if (rqInfo != null)
                {
                    string FromUserName = rqInfo.xmlmsg.ToUserName;
                    string ToUserName   = rqInfo.xmlmsg.FromUserName;
                    rqInfo.xmlmsg.ToUserName   = ToUserName;
                    rqInfo.xmlmsg.FromUserName = FromUserName;
                    switch (rqInfo.xmlmsg.MsgType)
                    {
                    //文本、位置、链接。回复默认
                    case InfoType.text:
                    case InfoType.location:
                    case InfoType.link:
                        content = HandleText(rqInfo);
                        break;

                    case InfoType.image:
                        content = HandleImage(rqInfo);
                        break;

                    case InfoType.voice:
                        content = HandleVoice(rqInfo);
                        break;

                    case InfoType.video:
                    case InfoType.shortvideo:
                        content = HandleVideo(rqInfo);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                TracingHelper.Error(ex, typeof(WeixinApiDispatch), ex.Message);
            }
            return(content);
        }
Ejemplo n.º 3
0
        public string Execute(string postStr)
        {
            string content = string.Empty;

            try
            {
                RQBase rqInfo = SerializeHelper.XmlDeserialize(postStr);
                //TracingHelper.Info(rqInfo.xmlmsg.ToUserName + " " + rqInfo.xmlmsg.FromUserName);
                if (rqInfo != null)
                {
                    string FromUserName = rqInfo.xmlmsg.ToUserName;
                    string ToUserName   = rqInfo.xmlmsg.FromUserName;
                    rqInfo.xmlmsg.ToUserName   = ToUserName;
                    rqInfo.xmlmsg.FromUserName = FromUserName;
                    switch (rqInfo.xmlmsg.MsgType)
                    {
                    //文本、位置、链接。回复默认
                    case InfoType.text:
                    case InfoType.location:
                    case InfoType.link:
                        content = HandleText(rqInfo);
                        break;

                    case InfoType.image:
                        content = HandleImage(rqInfo);
                        break;

                    case InfoType.voice:
                        content = HandleVoice(rqInfo);
                        break;

                    case InfoType.video:
                    case InfoType.shortvideo:
                        content = HandleVideo(rqInfo);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                TracingHelper.Error(ex, typeof(WeixinApiDispatch), ex.Message);
            }
            return(content);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 返回视频
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public string HandleVideo(RQBase info)
        {
            //发送什么,返回什么

            string xml = string.Empty;

            try
            {
                RequestVideo video = new RequestVideo();
                video.xmlmsg = info.xmlmsg;
                video.Video  = new Video()
                {
                    MediaId = info.MediaId, Title = info.Title, Description = info.Description
                };
                xml = new replyVideo().ReplyExecute(video);
            }
            catch (Exception ex)
            {
                TracingHelper.Error(ex, typeof(WeixinApiDispatch), ex.Message);
            }
            TracingHelper.Info("   HandleVideo" + xml);
            return(xml);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 返回声音
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public string HandleVoice(RQBase info)
        {
            //发送什么,返回什么

            string xml = string.Empty;

            try
            {
                RequestVoice voice = new RequestVoice();
                voice.xmlmsg = info.xmlmsg;
                voice.Voice  = new VoiceImage()
                {
                    MediaId = info.MediaId
                };
                xml = new replyVoice().ReplyExecute(voice);
            }
            catch (Exception ex)
            {
                TracingHelper.Error(ex, typeof(WeixinApiDispatch), ex.Message);
            }
            TracingHelper.Info("  HandleVoice " + xml);
            return(xml);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 返回图片
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public string HandleImage(RQBase info)
        {
            //发送什么,返回什么

            string xml = string.Empty;

            try
            {
                RequestImage imgeInfo = new RequestImage();
                imgeInfo.xmlmsg = info.xmlmsg;
                imgeInfo.Image  = new VoiceImage()
                {
                    MediaId = info.MediaId
                };
                xml = new replyImage().ReplyExecute(imgeInfo);
            }
            catch (Exception ex)
            {
                TracingHelper.Error(ex, typeof(WeixinApiDispatch), ex.Message);
            }
            // string xml = SerializeHelper.XmlSerialize<RequestImage>(imgeInfo);
            TracingHelper.Info(" HandleImage  " + xml);
            return(xml);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 处理消息类
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static RQBase XmlDeserialize(string xml)
        {
            try
            {
                //封装请求类
                XmlDocument requestDocXml = new XmlDocument();
                requestDocXml.LoadXml(xml);
                XmlElement rootElement = requestDocXml.DocumentElement;
                //XmlNodeList xnl = rootElement.ChildNodes;
                //foreach (XmlNode xn in xnl)
                //{
                //    XmlElement xe = (XmlElement)xn;


                //}
                RQBase WxXmlModel = new RQBase();
                WxXmlModel.xmlmsg.ToUserName   = rootElement.SelectSingleNode("ToUserName").InnerText;
                WxXmlModel.xmlmsg.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText;
                WxXmlModel.xmlmsg.CreateTime   = rootElement.SelectSingleNode("CreateTime").InnerText;
                WxXmlModel.xmlmsg.MsgType      = rootElement.SelectSingleNode("MsgType").InnerText;
                WxXmlModel.MsgId = rootElement.SelectSingleNode("MsgId").InnerText;

                switch (WxXmlModel.xmlmsg.MsgType)
                {
                case InfoType.text:
                    WxXmlModel.Content = rootElement.SelectSingleNode("Content").InnerText;
                    break;

                case InfoType.image:
                    WxXmlModel.PicUrl  = rootElement.SelectSingleNode("PicUrl").InnerText;
                    WxXmlModel.MediaId = rootElement.SelectSingleNode("MediaId").InnerText;
                    break;

                case InfoType.voice:
                    WxXmlModel.MediaId     = rootElement.SelectSingleNode("MediaId").InnerText;
                    WxXmlModel.Format      = rootElement.SelectSingleNode("Format").InnerText;
                    WxXmlModel.Recognition = rootElement.SelectSingleNode("Recognition").InnerText;
                    break;

                case InfoType.video:
                case InfoType.shortvideo:
                    WxXmlModel.MediaId      = rootElement.SelectSingleNode("MediaId").InnerText;
                    WxXmlModel.ThumbMediaId = rootElement.SelectSingleNode("ThumbMediaId").InnerText;
                    break;

                case InfoType.location:
                    WxXmlModel.Location_X = rootElement.SelectSingleNode("Location_X").InnerText;
                    WxXmlModel.Location_Y = rootElement.SelectSingleNode("Location_Y").InnerText;
                    WxXmlModel.Scale      = rootElement.SelectSingleNode("Scale").InnerText;
                    WxXmlModel.Label      = WxXmlModel.Content = rootElement.SelectSingleNode("Label").InnerText;
                    break;

                case InfoType.link:
                    WxXmlModel.Title       = WxXmlModel.Content = rootElement.SelectSingleNode("Title").InnerText;
                    WxXmlModel.Description = rootElement.SelectSingleNode("Description").InnerText;
                    WxXmlModel.Url         = rootElement.SelectSingleNode("Url").InnerText;
                    break;
                }
                return(WxXmlModel);
            }
            catch (Exception ex)
            {
                TracingHelper.Error(ex, typeof(SerializeHelper), ex.Message);
                return(null);
            }
        }