protected void Page_Load(object sender, EventArgs e) { #region AJAX请求 //正数为消息,负数为贴吧 if (function.isAjax()) { string action = Request["action"]; string result = ""; int id = DataConvert.CLng(Regex.Split(Request["value"] ?? "", ":::")[0]); //思路,信息都存在贴吧中,ID为负数 switch (action) { case "add": { string puremsg = ""; msgMod = FillMsg(Request.Form["MsgContent_T"], out puremsg); result = msgBll.Insert(msgMod).ToString(); #region 步至微博 if (!string.IsNullOrWhiteSpace(Request.Form["sync_chk"])) { puremsg = StringHelper.SubStr(puremsg, 140, ""); string sync = Request.Form["sync_chk"]; M_UserInfo mu = buser.GetLogin(); M_User_Token tokenMod = tokenBll.SelModelByUid(mu.UserID); if (tokenMod != null) { try { if (sync.Contains("qqblog") && !string.IsNullOrWhiteSpace(tokenMod.QQToken)) { qqBll = new QQHelper(tokenMod.QQToken, tokenMod.QQOpenID); if (!string.IsNullOrEmpty(msgMod.Attach)) { qqBll.AddBlog(puremsg, msgMod.Attach.Split('|')[0]); } else { qqBll.AddBlog(puremsg); } } if (sync.Contains("sina") && !string.IsNullOrWhiteSpace(tokenMod.SinaToken)) { sinaBll = new SinaHelper(tokenMod.SinaToken); string err = sinaBll.PostStatus(puremsg, (msgMod.Attach ?? "").Split('|')[0]); ZLLog.L(err); } } catch (Exception ex) { ZLLog.L("[" + sync + "]同步失败,用户[" + mu.UserName + "]原因:" + ex.Message); } } } #endregion } break; case "addvote": { msgMod = FillMsg(Request.Form["MsgContent_T"]); msgMod.MsgType = 2; msgMod.Title = HttpUtility.HtmlEncode(VoteTitle_T.Text); msgMod.VoteOP = Request.Form["VoteOption_T1"] + "," + Request.Form["VoteOption_T"]; //为Jquery验证 msgMod.VoteOP = HttpUtility.HtmlEncode(msgMod.VoteOP); msgMod.VoteResult = ""; msgMod.EndTime = DateTime.Parse(EndDate_T.Text); result = msgBll.Insert(msgMod).ToString(); } break; case "addarticle": //里面包含html|图片|附件,暂不同步微博 { string msg = Request.Form["msg"]; UEHelper ueHelper = new UEHelper(); msgMod = FillMsg(""); msgMod.MsgContent = msg; msgMod.MsgType = 3; msgMod.Title = ueHelper.GetSubTitle(msgMod.MsgContent); result = msgBll.Insert(msgMod).ToString(); } break; case "AddReply": case "AddReply2": if (id == 0) { throw new Exception("传入的ID不正确"); } result = PlatAJAX(); break; case "UserVote": result = PlatAJAX(); break; default: if (id == 0) { throw new Exception("信息ID不正确"); } if (id > 0) { result = PlatAJAX(); } else { result = BarAJAX(); } break; } Response.Write(result); Response.Flush(); Response.End(); } #endregion if (!IsPostBack) { MyBind(); } }
public ContentResult Blog_API() { //正数为plat,负数为bar string action = GetParam("action"); string result = ""; int id = DataConvert.CLng(Regex.Split(GetParam("value"), ":::")[0]); //思路,信息都存在贴吧中,ID为负数 switch (action) { case "add": { string puremsg = ""; msgMod = FillMsg(Request.Form["MsgContent_T"], out puremsg); result = msgBll.Insert(msgMod).ToString(); #region 步至微博 if (!string.IsNullOrWhiteSpace(Request.Form["sync_chk"])) { puremsg = StringHelper.SubStr(puremsg, 140, ""); string sync = Request.Form["sync_chk"]; M_User_Token tokenMod = tokenBll.SelModelByUid(mu.UserID); if (tokenMod != null) { try { if (sync.Contains("sina") && !string.IsNullOrWhiteSpace(tokenMod.SinaToken)) { //sinaBll = new SinaHelper(tokenMod.SinaToken); //string err = sinaBll.PostStatus(puremsg, (msgMod.Attach ?? "").Split('|')[0]); //ZLLog.L(err); } } catch (Exception ex) { ZLLog.L("[" + sync + "]同步失败,用户[" + mu.UserName + "]原因:" + ex.Message); } } } #endregion } break; case "addvote": { msgMod = FillMsg(Request.Form["MsgContent_T"]); msgMod.MsgType = 2; msgMod.Title = HttpUtility.HtmlEncode(GetParam("VoteTitle_T")); msgMod.VoteOP = Request.Form["VoteOption_T1"] + "," + Request.Form["VoteOption_T"]; //为Jquery验证 msgMod.VoteOP = HttpUtility.HtmlEncode(msgMod.VoteOP); msgMod.VoteResult = ""; msgMod.EndTime = DateTime.Parse(GetParam("EndDate_T")); result = msgBll.Insert(msgMod).ToString(); } break; case "addarticle": //里面包含html|图片|附件,暂不同步微博 { string msg = GetParam("msg"); UEHelper ueHelper = new UEHelper(); msgMod = FillMsg(""); msgMod.MsgContent = msg; msgMod.MsgType = 3; msgMod.Title = ueHelper.GetSubTitle(msgMod.MsgContent); result = msgBll.Insert(msgMod).ToString(); } break; case "AddReply": case "AddReply2": if (id == 0) { throw new Exception("传入的ID不正确"); } result = PlatAJAX(); break; case "UserVote": result = PlatAJAX(); break; default: if (id == 0) { throw new Exception("信息ID不正确"); } if (id > 0) { result = PlatAJAX(); } else { result = BarAJAX(); } break; } return(Content(result)); }