Ejemplo n.º 1
0
        /// <summary>
        ///  回复的图文消息的函数
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="articles">The content.</param>
        /// Author  : 俞立钢
        /// Company : 绍兴标点电子技术有限公司
        /// Created : 2014-10-24 09:57:37
        private static void ProduceNews(Dictionary <string, string> model, List <ArticlesModel> articles)
        {
            SendPicTxt news = new SendPicTxt();

            news.ToUserName   = model.ReadKey(PublicField.FromUserName);
            news.FromUserName = model.ReadKey(PublicField.ToUserName);
            news.CreateTime   = int.Parse(model.ReadKey(PublicField.CreateTime));
            news.MsgType      = "news";
            news.ArticleCount = articles.Count.ToString("D");
            news.Articles     = articles;
            OperateXml.ResponseEnd(Templete.SendNews(news));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  回复的视频消息的函数
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="mediaId">服务器上视频的ID</param>
        /// <param name="title">title</param>
        /// <param name="description">描述</param>
        /// Author  : 俞立钢
        /// Company : 绍兴标点电子技术有限公司
        /// Created : 2014-10-24 10:25:01
        private static void ProduceVideo(Dictionary <string, string> model, int mediaId, string title, string description)
        {
            SendVideo video = new SendVideo();

            video.ToUserName   = model.ReadKey(PublicField.FromUserName);
            video.FromUserName = model.ReadKey(PublicField.ToUserName);
            video.CreateTime   = int.Parse(model.ReadKey(PublicField.CreateTime));
            video.MsgType      = "video";
            video.MediaId      = mediaId;
            video.Title        = title;
            video.Description  = description;
            OperateXml.ResponseEnd(Templete.SendVideo(video));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///  get方式验证
        /// </summary>
        /// Author  : 俞立钢
        /// Company : 绍兴标点电子技术有限公司
        /// Created : 2014-10-10 15:41:54
        public void GetCheck()
        {
            string token      = PublicField.Token;
            string echoString = Request.QueryString["echostr"];
            string signature  = Request.QueryString["signature"];
            string timestamp  = Request.QueryString["timestamp"];
            string nonce      = Request.QueryString["nonce"];

            if (CheckSignature(token, signature, timestamp, nonce))
            {
                OperateXml.ResponseEnd(echoString);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 ///  回复的音乐消息的函数
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="title">音乐标题</param>
 /// <param name="description">音乐描述</param>
 /// <param name="musicUrl">音乐链接</param>
 /// <param name="hqMusicUrl">高质量音乐链接,WIFI环境优先使用该链接播放音乐</param>
 /// <param name="thumbMediaId">缩略图的媒体id,通过上传多媒体文件,得到的id</param>
 /// Author  : 俞立钢
 /// Company : 绍兴标点电子技术有限公司
 /// Created : 2014-10-24 10:25:01
 private static void ProduceMusic(Dictionary<string, string> model, string title, string description, string musicUrl, string hqMusicUrl, int thumbMediaId)
 {
     SendMusic music = new SendMusic();
     music.ToUserName = model.ReadKey(PublicField.FromUserName);
     music.FromUserName = model.ReadKey(PublicField.ToUserName);
     music.CreateTime = int.Parse(model.ReadKey(PublicField.CreateTime));
     music.MsgType = "music";
     music.Title = title;
     music.Description = description;
     music.MusicUrl = musicUrl;
     music.HqMusicUrl = hqMusicUrl;
     music.ThumbMediaId = thumbMediaId;
     OperateXml.ResponseEnd(Templete.SendMusic(music));
 }
Ejemplo n.º 5
0
        /// <summary>
        ///  验证微信签名
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="signature">The signature.</param>
        /// <param name="timestamp">The timestamp.</param>
        /// <param name="nonce">The nonce.</param>
        /// Author  : 俞立钢
        /// Company : 绍兴标点电子技术有限公司
        /// Created : 2014-10-10 15:53:55
        public bool CheckSignature(string token, string signature, string timestamp, string nonce)
        {
            string[] arrTmp = { token, timestamp, nonce };
            Array.Sort(arrTmp);
            string tmpStr = string.Join("", arrTmp);

            tmpStr = FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");
            if (tmpStr != null)
            {
                OperateXml.ResponseEnd(signature);
                tmpStr = tmpStr.ToLower();
                if (tmpStr == signature)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 6
0
        public void Index()
        {
            //ProduceImage();
            _httpMethod = Request.HttpMethod.ToLower();
            Dictionary <string, string> model = new Dictionary <string, string>();

            //POST方式发送过来的xml数据
            if (_httpMethod == "post")
            {
                //将xml数据转换
                using (Stream stream = HttpContext.Request.InputStream)
                {
                    byte[] byteData = new byte[stream.Length];
                    stream.Read(byteData, 0, (Int32)stream.Length);
                    _xmlData = Encoding.UTF8.GetString(byteData);
                }
                //判断传输过来的xml是否有数据
                if (!string.IsNullOrEmpty(_xmlData))
                {
                    try
                    {
                        model = _xmlData.ReadXml();
                    }
                    catch (Exception)
                    {
                        OperateXml.ResponseEnd("出错了!!!");
                    }
                }
                if (model.Count > 0)//回复消息
                {
                    DoMsg(model);
                }
            }
            else//get方式
            {
                GetCheck();
            }
        }