Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 public void index(JabinfoContext context)
 {
     Weixin weixin = new Weixin ();
     if (context.Request.HttpMethod.ToUpper()=="POST")
     {
         string strReset =Excute (context);
         context.Print (strReset);
     }
     else
     {
         Auth(context) ; //微信接入的测试
         weixin.SetMenu (context);
     }
 }