Ejemplo n.º 1
0
        public string GetView(RequestXML requestXML, string url)
        {
            string resxml = string.Format(@"<xml>
<ToUserName><![CDATA[{0}]]></ToUserName>
<FromUserName><![CDATA[{1}]]></FromUserName>
<CreateTime>{2}</CreateTime>
<MsgType><![CDATA[url]]></MsgType>
<Url><![CDATA[{3}]]></Url>
</xml>", requestXML.FromUserName, requestXML.ToUserName, GetStamp(), url);

            return(resxml);
        }
Ejemplo n.º 2
0
        public string GetText(RequestXML requestXML, string text)
        {
            string resxml = string.Format(@"<xml>
<ToUserName><![CDATA[{0}]]></ToUserName>
<FromUserName><![CDATA[{1}]]></FromUserName>
<CreateTime>{2}</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[{3}]]></Content>
</xml>", requestXML.FromUserName, requestXML.ToUserName, GetStamp(), text);

            return(resxml);
        }
Ejemplo n.º 3
0
        public string GetImage(RequestXML requestXML, string media_id)
        {
            string resxml = string.Format(@"<xml>
<ToUserName><![CDATA[{0}]]></ToUserName>
<FromUserName><![CDATA[{1}]]></FromUserName>
<CreateTime>{2}</CreateTime>
<MsgType><![CDATA[image]]></MsgType>
<Image>
<MediaId><![CDATA[{3}]]></MediaId>
</Image>
</xml>", requestXML.FromUserName, requestXML.ToUserName, GetStamp(), media_id);

            return(resxml);
        }
Ejemplo n.º 4
0
        public string GetNewsXml(RequestXML requestXML, string title, string content, string url)
        {
            string resxml = string.Format(@"<xml>
<ToUserName><![CDATA[{0}]]></ToUserName>
<FromUserName><![CDATA[{1}]]></FromUserName>
<CreateTime>{2}</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<ArticleCount>1</ArticleCount>
<Articles>
<item>
<Title><![CDATA[{3}]]></Title> 
<Description><![CDATA[{4}]]></Description>
<PicUrl><![CDATA[http://library.gufe.edu.cn/weixin/images/house.jpg]]></PicUrl>
<Url><![CDATA[{5}]]></Url>
</item>
</Articles>
</xml>", requestXML.FromUserName, requestXML.ToUserName, GetStamp(), title, content, url);

            return(resxml);
        }
Ejemplo n.º 5
0
        public RequestXML Handle(string postStr)
        {
            //封装请求类
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(postStr);
            XmlElement rootElement = doc.DocumentElement;
            //MsgType
            XmlNode MsgType = rootElement.SelectSingleNode("MsgType");
            //接收的值--->接收消息类(也称为消息推送)
            RequestXML requestXML = new RequestXML();

            requestXML.ToUserName   = rootElement.SelectSingleNode("ToUserName").InnerText;
            requestXML.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText;
            requestXML.CreateTime   = rootElement.SelectSingleNode("CreateTime").InnerText;
            requestXML.MsgType      = MsgType.InnerText;

            //根据不同的类型进行不同的处理
            switch (requestXML.MsgType)
            {
            case "text":     //文本消息
                requestXML.Content = rootElement.SelectSingleNode("Content").InnerText;
                break;

            case "image":     //图片
                requestXML.PicUrl  = rootElement.SelectSingleNode("PicUrl").InnerText;
                requestXML.MediaId = rootElement.SelectSingleNode("MediaId").InnerText;
                break;

            case "event":     //事件推送 支持V4.5+
                requestXML.Events   = rootElement.SelectSingleNode("Event").InnerText;
                requestXML.EventKey = rootElement.SelectSingleNode("EventKey").InnerText;
                if (requestXML.Events == "scancode_push")
                {
                    XmlNode ScanCodeInfo = rootElement.SelectSingleNode("ScanCodeInfo");
                    requestXML.ScanType   = ScanCodeInfo.SelectSingleNode("ScanType").InnerText;
                    requestXML.ScanResult = ScanCodeInfo.SelectSingleNode("ScanResult").InnerText;
                }
                break;

            case "location":     //位置
                requestXML.Location_X = rootElement.SelectSingleNode("Location_X").InnerText;
                requestXML.Location_Y = rootElement.SelectSingleNode("Location_Y").InnerText;
                requestXML.Scale      = rootElement.SelectSingleNode("Scale").InnerText;
                requestXML.Label      = rootElement.SelectSingleNode("Label").InnerText;
                break;

            case "link":     //链接
                requestXML.Url = rootElement.SelectSingleNode("Url").InnerText;
                break;

            case "voice":     //语音
                requestXML.Recognition = rootElement.SelectSingleNode("Recognition").InnerText;
                requestXML.MediaId     = rootElement.SelectSingleNode("MediaId").InnerText;
                break;

            case "video":      //视频
            case "shortvideo": //小视频
                requestXML.ThumbMediaId = rootElement.SelectSingleNode("ThumbMediaId").InnerText;
                requestXML.MediaId      = rootElement.SelectSingleNode("MediaId").InnerText;
                break;
            }
            return(requestXML);
        }