Esempio n. 1
0
        /// <summary>
        /// 输出图文消息类型
        /// </summary>
        /// <param name="um">用户消息对象</param>
        /// <param name="newsCount">图文数量,不得超过10条</param>
        /// <param name="news">新闻数组</param>
        /// <returns>返回消息文本</returns>
        public string outNews(userMsg um, int newsCount, newsClass[] news)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<xml>");
            sb.AppendFormat("<ToUserName>{0}</ToUserName><FromUserName>{1}</FromUserName><CreateTime>{2}</CreateTime>", um.FromUserName, um.ToUserName, um.CreateTime);
            sb.AppendFormat("<MsgType>news</MsgType>");
            sb.AppendFormat("<ArticleCount>{0}</ArticleCount>", newsCount);
            sb.Append("<Articles>");
            for (int i = 0; i < newsCount; i++)
            {
                sb.Append("<item>");
                sb.AppendFormat("<Title>{0}</Title>", news[i].Title, news[i].Url);

                //非必填项判断 不存在就不输出
                if (news[i].Description != null)
                {
                    sb.AppendFormat("<Description>{0}</Description>", news[i].Description);
                }
                if (news[i].PicUrl != null)
                {
                    sb.AppendFormat("<PicUrl>{0}</PicUrl>", news[i].PicUrl);
                }

                sb.AppendFormat("<Url>{0}</Url>", news[i].Url);
                sb.Append("</item>");
            }
            sb.Append("</Articles>");
            sb.Append("</xml>");

            return(sb.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// 转发给客服
        /// </summary>
        /// <param name="um">用户消息对象</param>
        /// <returns>返回消息文本</returns>
        public string outClient(userMsg um)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<xml>");
            sb.AppendFormat("<ToUserName>{0}</ToUserName><FromUserName>{1}</FromUserName><CreateTime>{2}</CreateTime>", um.FromUserName, um.ToUserName, um.CreateTime);
            sb.AppendFormat("<MsgType>transfer_customer_service</MsgType>");
            sb.Append("</xml>");

            return(sb.ToString());
        }
Esempio n. 3
0
        /// <summary>
        /// 输出文本消息类型
        /// </summary>
        /// <param name="um">用户消息对象</param>
        /// <param name="outText">输出的文本</param>
        /// <returns>返回消息文本</returns>
        public string outText(userMsg um, string outText)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<xml>");
            sb.AppendFormat("<ToUserName>{0}</ToUserName><FromUserName>{1}</FromUserName><CreateTime>{2}</CreateTime>", um.FromUserName, um.ToUserName, um.CreateTime);
            sb.AppendFormat("<MsgType>text</MsgType>");
            sb.AppendFormat("<Content>{0}</Content>", outText);
            sb.Append("</xml>");

            return(sb.ToString());
        }
Esempio n. 4
0
 /// <summary>
 /// 接收到的未知数据输入到用户消息对象
 /// </summary>
 /// <param name="um">用户消息对象</param>
 /// <param name="xml">接收到的XML数据</param>
 /// <returns>无错误返回真</returns>
 private bool intoNull(userMsg um, XmlElement xml)
 {
     try
     {
         um.ToUserName   = xml["ToUserName"].InnerText;
         um.FromUserName = xml["FromUserName"].InnerText;
         um.CreateTime   = xml["CreateTime"].InnerText;
         um.MsgType      = xml["MsgType"].InnerText;
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// 接收到的图片数据输入到用户消息对象
 /// </summary>
 /// <param name="um">用户消息对象</param>
 /// <param name="xml">接收到的XML数据</param>
 /// <returns>无错误返回真</returns>
 private bool intoImage(userMsg um, XmlElement xml)
 {
     try
     {
         um.ToUserName   = xml["ToUserName"].InnerText;
         um.FromUserName = xml["FromUserName"].InnerText;
         um.CreateTime   = xml["CreateTime"].InnerText;
         um.MsgType      = xml["MsgType"].InnerText;
         um.PicUrl       = xml["PicUrl"].InnerText;
         um.MediaId      = xml["MediaId"].InnerText;
         um.MsgId        = xml["MsgId"].InnerText;
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// 接收到的语音数据输入到用户消息对象
 /// </summary>
 /// <param name="um">用户消息对象</param>
 /// <param name="xml">接收到的XML数据</param>
 /// <returns>无错误返回真</returns>
 private bool intoVoice(userMsg um, XmlElement xml)
 {
     try
     {
         um.ToUserName   = xml["ToUserName"].InnerText;
         um.FromUserName = xml["FromUserName"].InnerText;
         um.CreateTime   = xml["CreateTime"].InnerText;
         um.MsgType      = xml["MsgType"].InnerText;
         um.MediaId      = xml["MediaId"].InnerText;
         um.Format       = xml["Format"].InnerText;
         um.MsgId        = xml["MsgId"].InnerText;
         um.Recognition  = xml["Recognition"].InnerText;
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 7
0
        /// <summary>
        /// 接收到的事件数据输入到用户消息对象
        /// </summary>
        /// <param name="um">用户消息对象</param>
        /// <param name="xml">接收到的XML数据</param>
        /// <returns>无错误返回真</returns>
        private bool intoEvent(userMsg um, XmlElement xml)
        {
            try
            {
                um.ToUserName   = xml["ToUserName"].InnerText;
                um.FromUserName = xml["FromUserName"].InnerText;
                um.CreateTime   = xml["CreateTime"].InnerText;
                um.MsgType      = xml["MsgType"].InnerText;
                um.Event        = xml["Event"].InnerText;


                if (um.Event == "scancode_waitmsg")
                {
                    um.EventKey   = xml["EventKey"].InnerText;
                    um.ScanResult = xml["ScanCodeInfo"]["ScanResult"].InnerText;
                    um.ScanType   = xml["ScanCodeInfo"]["ScanType"].InnerText;
                }


                if (um.Event == "subscribe" || um.Event == "SCAN")
                {
                    try
                    {
                        um.EventKey = xml["EventKey"].InnerText;
                        um.Ticket   = xml["Ticket"].InnerText;
                    }
                    catch
                    {
                    }
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }