Пример #1
0
        /// <summary>
        /// 准备待发送消息
        /// </summary>
        /// <param name="xmlMsg"></param>
        /// <returns></returns>
        public ContextXMLMessage PrepareSendMessage(ContextXMLMessage xmlMsg)
        {
            //赋予基础信息
            ContextXMLMessage sendMsg = new ContextXMLMessage()
            {
                ToUserName = xmlMsg.FromUserName,
                FromUserName = xmlMsg.ToUserName,
                CreateTime = xmlMsg.SendTime,
                MsgType = "text"
            };

            //准备要发送的消息 - [这里应该有判断逻辑]
            if (string.IsNullOrEmpty(this.TxtType)) { sendMsg.OpeMessage = new TextContentMessage() { Content = @"Email:[email protected]" }; }
            else
            {
                switch (TxtType)
                {
                    case "zzsc_Contect":
                        sendMsg.OpeMessage = new TextContentMessage() { Content = ZZSCResource.DnmSystemConfig.SystemConfig.SendMessage.zzsc_Contect };
                        break;

                    default:
                        break;
                }
            }

            return sendMsg;
        }
Пример #2
0
        /// <summary>
        /// 根据公众号传递过来信息,准备反馈信息
        /// </summary>
        /// <param name="xmlMsg"></param>
        /// <returns></returns>
        public ContextXMLMessage PrepareSendMessage(ContextXMLMessage xmlMsg)
        {
            //创建发送消息对象

            //赋予基础信息
            ContextXMLMessage sendMsg = new ContextXMLMessage()
            {
                ToUserName = xmlMsg.FromUserName,
                FromUserName = xmlMsg.ToUserName,
                CreateTime = xmlMsg.SendTime
            };

            //将热门图文消息Down下来
            string strArticle = TokenHelper.RequestArticleItemByID("Tgcd98f3zywgWc7T0E_Pw5VNjRQWIvhKqpGrolB-oOw");

            if (!string.IsNullOrEmpty(strArticle))
            { //不为空

                dynamic dnm = JsonConvert.DeserializeObject(strArticle);

                //开始赋予业务逻辑信息
                BestArticleMessage opeMsg = new BestArticleMessage();
                opeMsg.MsgType = "news";
                opeMsg.ArticleCont = 1;
                opeMsg.Articles = new List<ArticleItem>()
                {
                    new ArticleItem() { Title = dnm.news_item[0].title, Description = dnm.news_item[0].digest, PicUrl = dnm.news_item[0].thumb_url, Url = dnm.news_item[0].url }
                };

                sendMsg.OpeMessage = opeMsg;
            }

            return sendMsg;
        }
Пример #3
0
        /// <summary>
        /// 套模板
        /// </summary>
        /// <param name="sendMsg"></param>
        /// <returns></returns>
        public string FormatMessage(ContextXMLMessage sendMsg)
        {
            TextContentMessage txtContent = sendMsg.OpeMessage as TextContentMessage;

            string strSend = string.Format(SendMessageTemplate.TextContentTpl,
                                            sendMsg.ToUserName,
                                            sendMsg.FromUserName,
                                            sendMsg.CreateTime,
                                            sendMsg.MsgType,
                                            txtContent.Content);

            return strSend;
        }
Пример #4
0
        /// <summary>
        /// 根据待发送消息封装对象,进行字符串转换
        /// </summary>
        /// <param name="sendMsg"></param>
        /// <returns></returns>
        public string FormatMessage(ContextXMLMessage sendMsg)
        {
            BestArticleMessage bestArticleMsg = sendMsg.OpeMessage as BestArticleMessage;

            string strSend = string.Format(SendMessageTemplate.BestArticleTpl,
                                            sendMsg.ToUserName,
                                            sendMsg.FromUserName,
                                            sendMsg.CreateTime,
                                            bestArticleMsg.MsgType,
                                            bestArticleMsg.ArticleCont,
                                            bestArticleMsg.Articles[0].Title,
                                            bestArticleMsg.Articles[0].Description,
                                            bestArticleMsg.Articles[0].PicUrl,
                                            bestArticleMsg.Articles[0].Url);

            return strSend;
        }
Пример #5
0
        /// <summary>
        /// 解析 公众号传递XML消息,根据指定业务逻辑对象
        /// </summary>
        /// <param name="strXML"></param>
        /// <returns></returns>
        public Tuple<ContextXMLMessage, XmlDocument> HandleRequestXMLMessage(string strXML)
        {
            //1.读取
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(strXML);

            //2.封装对象
            ContextXMLMessage ctxtMsg = new ContextXMLMessage();
            ctxtMsg.ToUserName = xmlDoc.SelectSingleNode("/xml/ToUserName").InnerText;
            ctxtMsg.FromUserName = xmlDoc.SelectSingleNode("/xml/FromUserName").InnerText;
            ctxtMsg.CreateTime = int.Parse(xmlDoc.SelectSingleNode("/xml/CreateTime").InnerText);
            ctxtMsg.MsgType = xmlDoc.SelectSingleNode("/xml/MsgType").InnerText;

            //3.封装业务对象
            //ctxtMsg.OpeMessage = ope.MessageAnalyze(xmlDoc);

            return new Tuple<ContextXMLMessage, XmlDocument>(ctxtMsg, xmlDoc);
        }