Ejemplo n.º 1
0
        private string devlopID = "wx6522a9d862ae7a0f"; //微信里面开发者模式:开发者ID

        #endregion Fields

        #region Methods

        public string Event(RequestVO requesXML,string key)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string message = string.Empty;
            string strResult = string.Empty;
            Msg msg = new Msg ();
            switch (key)
            {
            case "subscribe":
                message = "感谢您关注【知识产权那点事】微信公众号,我们会定期为你推送我们最新的新闻资讯";
                strResult = msg.SendMsg (requesXML, message);
                // 将关注信息写入follow 表中
                string json = GetInfo (GetAccessToken (), requesXML.fromUserName);
                FollowVO follow = serializer.Deserialize<FollowVO> (json);
                JabinfoKeyValue data = new JabinfoKeyValue ();
                data ["openid"] = follow.openId;
                data ["nickname"] = follow.nickname;
                data ["sex"] = follow.sex;
                data ["province"] = follow.province;
                data ["city"] = follow.city;
                data ["country"] = follow.country;
                data ["headimgurl"] = follow.headimgurl;
                data ["createtime"] = requesXML.createTime.ToString();
                FollowMapper.I.Insert (data);
                break;
            case "unsubscribe":
                message = "取消关注";
                strResult = msg.SendMsg (requesXML, message);
                // 将关注者从数据库中取消
                FollowMapper.I.DeleteByPrimary (requesXML.fromUserName);
                break;
            case "CLICK":
                if (requesXML.EventKey == "inn") {
                    IList<WXArticle> articles = new List<WXArticle> ();
                    WXArticle article = new WXArticle ();
                    article.Description = "上海知识产权研究所,提供最具价值的知识产权资讯";
                    article.PicUrl = "http://www.iprlawyers.com/Files/2014.5.22fugang.jpg";
                    article.Title = "知识产权那点事";
                    article.Url = "http://www.iprlawyers.com/";
                    articles.Add (article);
                    strResult = msg.SendMsg (requesXML, articles);
                }
                break;
            //			case "SCAN":
            //				IList<WXArticle> articles1 = new List<WXArticle> ();
            //				WXArticle item = new WXArticle ();
            //				item.Title = "Kooteam";
            //				item.Description = "KooTeam是一款轻量级的团队时间管理与项目管理的系统,免费提供项目管理,团队协作SaaS解决方案。不需要安装或升级任何软件,您只要注册一个KooTeam账户就马上可以拥有一个多功能、一体化的在线项目管理,团队协作办公系统——无需购买服务器,使用次数不限、使用时长不限、用户数不限、项目数量不限";
            //				item.PicUrl = "http://p.kooteam.com/res/tma/banner/01.jpg";
            //				item.Url = "http://p.kooteam.com";
            //				articles1.Add (item);
            //				strResult = msg.SendMsg (requesXML, articles1);
            //				break;
            default:
                message = "receive a new event:" + requesXML.EventKey;
                strResult = msg.SendMsg (requesXML, message);
                break;
            }
            return strResult;
        }
Ejemplo n.º 2
0
 public string Excute(JabinfoContext context)
 {
     Weixin weixin = new Weixin ();
     string strResult = string.Empty;
     string message = string.Empty;
     Msg msg = new Msg ();
     Stream s = context.Request.InputStream;
     byte[] b = new byte[s.Length];
     s.Read(b, 0, (int)s.Length);
     string postString = Encoding.UTF8.GetString(b);
     RequestVO requestXML = weixin.GetRequest (postString);
     string type = requestXML.msgType;
     switch (type)
     {
     case "text":
         if (requestXML.content == "音乐") {
             WXMusic music = new WXMusic ();
             music.Title = "喜欢你";
             music.Description = "邓紫琪";
             music.MusicUrl = "http://qzone.djsoso.com/mp3/7D67455E23D943ED09AA4772B0CC2B5A-54738/www.haoduoge.com.mp3";
             music.HQMusicUrl = "http://qzone.djsoso.com/mp3/7D67455E23D943ED09AA4772B0CC2B5A-54738/www.haoduoge.com.mp3";
             strResult = msg.SendMusic (requestXML, music);
         } else if(requestXML.content=="koo"||requestXML.content=="kooteam") {
             IList<WXArticle> articles = new List<WXArticle> ();
             WXArticle item = new WXArticle ();
             item.Title = "Kooteam";
             item.Description = "办公也扮酷";
             item.PicUrl = "http://p.kooteam.com/res/tma/banner/01.jpg";
             item.Url = "http://p.kooteam.com";
             articles.Add (item);
             strResult = msg.SendMsg (requestXML, articles);
         }else{
             string keywold = requestXML.content;
             ArticleVO[] articleVO =ArticleModel.I.Keywold(keywold, 0, 4);
             if (articleVO.Length == 0) {
                 string joke = Jabinfo.Help.Http.Get ("http://apix.sinaapp.com/joke/?appkey=trialuser");
                 string jo = joke.Substring (0, joke.Length-15);
                 strResult = msg.SendMsg (requestXML, jo);
             } else {
                 IList<WXArticle> articles = new List<WXArticle> ();
                 foreach (ArticleVO a in articleVO) {
                     WXArticle item = new WXArticle ();
                     item.Title = a.title;
                     item.Description = a.summary;
                     item.PicUrl = "http://wx.zento.me/upload/" + Attch (a.articleId);
                     item.Url = "http://wx.zento.me/article/home/detail/" + a.articleId;
                     articles.Add (item);
                 }
                 strResult = msg.SendMsg (requestXML, articles);
             }
         }
         weixin.loger (requestXML);
         break;
     case "location":
         message = string.Format ("你发送的是位置,纬度为:{0};经度为:{1};缩放级别为:{2};位置为:{3};", requestXML.Location_X, requestXML.Location_Y, requestXML.Scale, requestXML.Label);
         strResult = msg.SendMsg (requestXML, message);
         break;
     case "image":
         strResult = msg.SendPic (requestXML);
         break;
     case "vedio":
         strResult = msg.SendVedio (requestXML);
         break;
     case "voice":
         strResult = msg.SendVoice (requestXML);
         break;
     case "link":
         message = string.Format ("你发送的是链接,标题为:{0};内容为:{1};链接地址为:{2}", requestXML.Title, requestXML.content, requestXML.Url);
         strResult = msg.SendMsg (requestXML, message);
         break;
     case "event":
         string key = requestXML.Event;
         strResult= weixin.Event (requestXML, key);
         break;
     }
     return strResult;
 }