示例#1
0
 public void add(JabinfoContext context)
 {
     Weixin weixin = new Weixin ();
     Utils util = new Utils ();
     if (!context.IsPost) {
         return;
     }
     context.Post ["uploadId"] = Jabinfo.Help.Basic.JabId;
     string type = context.Post ["type"];
     string fileName = context.Files ["afile"].FileName;
     string model=fileName.Substring(fileName.LastIndexOf('.') + 1);
     Jabinfo.Help.Upload.Save (context.Post ["uploadId"], context.Files["afile"],model);
     string file = Jabinfo.Help.Upload.PysPath (context.Post ["uploadId"],model);
     string url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token="+weixin.GetAccessToken();
     url = url + "&type=" + type;
     string json = util.HttpUpload (url, file);
     context.Post ["mediaId"] = weixin.GetJsonValue (json,"media_id");
     context.Post ["createdAt"] = weixin.GetJsonValue(json,"created_at");
     if (!string.IsNullOrEmpty (weixin.GetJsonValue (json, "errcode"))) {
         context.Jump ("/article/upload/home","无效媒体类型,请重新上传");
         return;
     }
     UploadMapper.I.Insert(context.Post);
     context.Refresh ();
 }
示例#2
0
 /// <summary>
 /// 微信添加用户分组
 /// </summary>
 /// <param name="">.</param>
 public void addGroup(JabinfoContext context)
 {
     if (!context.IsPost)
         return;
     Weixin wx = new Weixin ();
     string url = "https://api.weixin.qq.com/cgi-bin/groups/create?access_token=" + wx.GetAccessToken ();
     string groupname = "{\"group\":{\"name\":\"" + context.Post["title"] + "\"}}";
     string json = Jabinfo.Help.Http.PostHttps (url, groupname);
     context.Post ["categoryId"] = wx.GetJsonValue (json, "id");
     context.Post ["name"] = wx.GetJsonValue (json, "name");
     context.Post ["parentId"]="8";
     CategoryMapper.I.Insert (context.Post);
     context.Refresh ();
 }
示例#3
0
 public void add(JabinfoContext context)
 {
     bool istemp = true;
     Weixin wx = new Weixin ();
     JavaScriptSerializer serializer = new JavaScriptSerializer ();
     if (!context.IsPost) {
         return;
     }
     int sceneId = Convert.ToInt32(context.Post ["sceneId"]);
     string action = context.Post ["action"];
     if (action == "false")
         istemp = false;
     string resutl= wx.QRCodeTicket (istemp, sceneId);
     if (resutl == "0") {
         context.Alert ("添加失败");
         return;
     }
     string seconds = istemp ? wx.GetJsonValue (resutl, "expire_seconds") : "0";   //如果用为用二维码;则二维码时间为 100000000;
     TicketVO tk= serializer.Deserialize<TicketVO> (resutl);
     context.Post ["createtime"] = Jabinfo.Help.Date.Now.ToString();
     context.Post ["ticket"] = tk.ticket;
     context.Post ["url"] = tk.url;
     context.Post ["expireSeconds"] = seconds;
     TicketMapper.I.Insert(context.Post);
     context.Refresh ();
 }
示例#4
0
 public string info(object[] args)
 {
     Weixin weixin = new Weixin ();
     string openId = Convert.ToString (args [0]);
     string json= weixin.GetInfo (weixin.GetAccessToken(), openId);
     return weixin.GetJsonValue (json, "nickname");
 }
示例#5
0
 public void remove(JabinfoContext context, String msgId)
 {
     Weixin wx = new Weixin ();
     string url = "https://api.weixin.qq.com/cgi-bin/message/mass/delete?access_token=" + wx.GetAccessToken ();
     string con = "{\n   \"msg_id\":" + msgId + "\n}";
     string json = Jabinfo.Help.Http.PostHttps (url, con);
     if (wx.GetJsonValue (json, "errcode") == "0") {
         MsglogMapper.I.DeleteByPrimary (msgId);
         context.Alert ("删除成功");
     }
 }
示例#6
0
 /// <summary>
 /// 上传媒体文件
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="articles">Articles.</param>
 public void upload(JabinfoContext context,string articles)
 {
     if (!context.IsPost) {
         context.Variable ["articles"] = articles;
         return;
     }
     Weixin wx = new Weixin ();
     Utils util = new Utils ();
     string[] article =context.Post["articles"].Split (',');
     StringBuilder str = new StringBuilder ("{ \r\n");
     StringBuilder con = new StringBuilder ();
     str.Append (" \"articles\": [ \r\n");
     for (int i = 0; i < article.Length - 1; i++) {
         ArticleVO ar = ArticleMapper.I.Create (article [i]);
         ArticleDetailVO d = ArticleDetailMapper.I.Create (article [i]);
         con.Append("{ \r\n");
         Regex reg = new Regex(@"(?i)</?a\b[^>]*>");    //去掉字符串的<a>标签
         Regex reg1=new Regex(@"<img[^>]*?/>");         //去掉img标签
         Regex reg2=new Regex(@"style=""[^""]*""");     //去掉style标签
         string result = reg.Replace(d.content, "");
         result = reg1.Replace (result, "");
         result = reg2.Replace (result, "");
         string file = Jabinfo.Help.Upload.PysPath (ar.articleId,"jpg");
         string url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token="+wx.GetAccessToken();
         url = url + "&type=image";
         string json = util.HttpUpload (url, file);
         con.Append (string.Format(" \"thumb_media_id\":\"{0}\", \r\n",wx.GetJsonValue (json,"media_id")));
         con.Append("\"author\":\"" + ar.author.ToString() + "\",");
         con.Append("\"title\":\"" + ar.title.ToString() + "\",");
         con.Append(string.Format(" \"content_source_url\":\"{0}\", \r\n","http://wx.zento.me/article/home/detail/"+ ar.articleId));
         con.Append("\"content\":\"" + Jabinfo.Help.Formate.ClearSpace(result) + "\",");
         con.Append("\"digest\":\"" +  Jabinfo.Help.Formate.ClearSpace(ar.summary) + "\",");
         con.Append (" \"show_cover_pic\":\"0\" \r\n");
         con.Append (" },");
     }
     string mian = con.ToString ();
     string text = mian.Substring (0, mian.Length - 1);
     str.Append (text);
     str.Append ("  ] \r\n");
     str.Append ("} \r\n");
     wx.UpNews (str.ToString (),context.Post["title"]);
     context.Refresh ();
 }