public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; long spaceId; // 空间用户的标识 long referedId; // 回复留言的标识 long InstanceId; long msg_accountId;//短信接受者 string content; CY.UME.Core.Business.Account currentAccount; // 留言的用户 CY.UME.Core.Business.Account spaceAccount; // 所在个人主页的用户 CY.UME.Core.Business.MiniBlogComment comment = new CY.UME.Core.Business.MiniBlogComment(); CY.UME.Core.Business.MiniBlogComment referedComment = new CY.UME.Core.Business.MiniBlogComment(); // 所回复的留言 if (!CY.Utility.Common.ParseUtility.TryParseInt64(context.Request["spaceId"], out spaceId) || !CY.Utility.Common.ParseUtility.TryParseInt64(context.Request["referedId"], out referedId) || !CY.Utility.Common.ParseUtility.TryParseInt64(context.Request["InstanceId"], out InstanceId)) { context.Response.Write("{success:false,msg:'参数错误'}"); return; } currentAccount = CY.UME.Core.Business.Account.Load(spaceId); if (currentAccount == null) { context.Response.Write("{success:false,msg:'用户不存在'}"); return; } // 所在个人主页的用户 if (spaceId == 0) { spaceId = currentAccount.Id; spaceAccount = currentAccount; } else { spaceAccount = CY.UME.Core.Business.Account.Load(spaceId); if (spaceAccount == null) { context.Response.Write("{success:false,msg:'用户不存在'}"); return; } } // 所回复的留言 if (referedId > 0) { referedComment = CY.UME.Core.Business.MiniBlogComment.Load(referedId); if (referedComment == null) { context.Response.Write("{success:false,msg:'所回复的用户已被删除'}"); return; } } // 留言内容 content = context.Request["content"]; if (string.IsNullOrEmpty(content)) { context.Response.Write("{success:false,msg:'留言内容不能为空'}"); return; } #region Leave Msg,Notice // 将留言或者回复信息发送给空间主人 CY.UME.Core.Business.MiniBlog miniblog = CY.UME.Core.Business.MiniBlog.Load(InstanceId); if (miniblog == null) { context.Response.Write("{success:false,msg:'该状态不存在或已被删除'}"); return; } comment.AccountId = miniblog.AccountId; comment.Content = content; comment.ReferedId = referedId; comment.AuthorId = currentAccount.Id; comment.DateCreated = DateTime.Now; comment.InstanceId = InstanceId; comment.IP = CY.Utility.Common.RequestUtility.ClientIP; comment.Save(); msg_accountId = comment.AccountId; if (miniblog.AccountId != currentAccount.Id) // 回复其他人 { CY.UME.Core.Business.Notice notice = new CY.UME.Core.Business.Notice(); notice.AuthorId = comment.AuthorId; notice.IsReaded = false; notice.DateCreated = DateTime.Now; notice.InstanceId = InstanceId.ToString(); notice.Type = "miniblogreply"; if (referedComment.Id > 0) { notice.AccountId = referedComment.AuthorId; if (referedComment.AuthorId == miniblog.AccountId) // 回复空间主人 { notice.Content = "回复了您的评论"; } else // 在别人页面回复了另外一个人 { notice.Content = "回复了您在 " + spaceAccount.Name + " 处的评论"; // 在所引用的作者处添加一条回复副本 CY.UME.Core.Business.MiniBlogComment commentCopy = new CY.UME.Core.Business.MiniBlogComment(); commentCopy.AccountId = referedComment.AuthorId; commentCopy.AuthorId = currentAccount.Id; commentCopy.Content = comment.Content; commentCopy.DateCreated = comment.DateCreated; commentCopy.InstanceId = comment.InstanceId; commentCopy.IP = comment.IP; commentCopy.ReferedId = comment.ReferedId; commentCopy.Save(); msg_accountId = commentCopy.AccountId; } } else { notice.AccountId = miniblog.AccountId; notice.Content = "评论了您的状态"; } notice.Save(); } else //对自己的状态回复 { if (referedComment != null && referedComment.Id > 0 && referedComment.AuthorId != currentAccount.Id) // 为回复他人 { CY.UME.Core.Business.Notice notice = new CY.UME.Core.Business.Notice(); notice.AuthorId = comment.AuthorId; notice.IsReaded = false; notice.DateCreated = DateTime.Now; notice.Type = "miniblogreply"; notice.AccountId = referedComment.AuthorId; notice.Content = "回复了您的评论"; notice.InstanceId = InstanceId.ToString(); notice.Save(); } } #endregion StringBuilder sb = new StringBuilder(); sb.Append("{success:true, msg: '添加成功!', account: {"); sb.Append("Id: " + comment.AuthorId); sb.Append(", Name:'"); sb.Append(currentAccount.Name); sb.Append("'}, commentId: "); sb.Append(comment.Id); sb.Append("}"); context.Response.Write(sb.ToString()); //发送短信给被回复者 if (miniblog.MiniBlogExtend.IsMsgReceived) { CY.UME.Core.Business.AccountExtend ae = CY.UME.Core.Business.AccountExtend.Load(msg_accountId); if (ae != null) { string msgcontent = currentAccount.Name + "回复了您:" + comment.Content; string flag = String.Empty; try { CY.UME.Core.Global.TrySendMessage(ae.Telephone, msgcontent, out flag); } catch { } } } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; CY.UME.Core.Business.Account account; CY.UME.Core.Business.MiniBlog miniBlog; long miniBlogId = 0; string content = String.Empty; string strReplyedId = String.Empty; #region validate if (context.Request.Form["MiniBlogId"] == null || !long.TryParse(context.Request.Form["MiniBlogId"].ToString(), out miniBlogId)) { context.Response.Write("{success:false,msg:'操作失败'}"); return; } if (context.Request.Form["Content"] != null) { content = context.Request.Form["Content"].ToString().Trim(); content = Utility.Common.StringUtility.HTMLEncode(content); content = Regex.Replace(content, @"(http:\/\/[\w.]+\/?)([^\u4e00-\u9fa5|\u0020]*)", "<a href=\"$1$2\">$1$2</a>", RegexOptions.IgnoreCase | RegexOptions.Multiline); } if (context.Request.Form["strReplyedMinBlogId"] != null) { strReplyedId = context.Request.Form["strReplyedMinBlogId"].ToString().Trim(); } account = CY.UME.Core.Global.GetCurrentAccount(); if (account == null) { context.Response.Write("{success:false,msg:'登录超时失败'}"); return; } miniBlog = CY.UME.Core.Business.MiniBlog.Load(miniBlogId); if (miniBlog == null) { context.Response.Write("{success:false,msg:'参数错误'}"); return; } if (account.Id == miniBlog.AccountId) { context.Response.Write("{success:false,msg:'不能转发自己的博文'}"); return; } CY.UME.Core.Business.Account accountRefered = CY.UME.Core.Business.Account.Load(miniBlog.AccountId); if (accountRefered == null) { context.Response.Write("{success:false,msg:'您无法转发该篇博文'}"); return; } if (miniBlog.HasTransedByThisAccount(account)) { context.Response.Write("{success:false,msg:'您已经转发过该篇博文'}"); return; } #endregion try { CY.UME.Core.Business.MiniBlog newMiniBlog = new CY.UME.Core.Business.MiniBlog(); newMiniBlog.AccountId = account.Id; newMiniBlog.Content = content; newMiniBlog.DatePublish = DateTime.Now; newMiniBlog.IP = CY.Utility.Common.RequestUtility.ClientIP; newMiniBlog.Save(); string imgPath = String.Empty; string flashPath = String.Empty; CY.UME.Core.Business.MiniBlogExtend miniBlogExtend = CY.UME.Core.Business.MiniBlogExtend.Load(miniBlog.Id); if (miniBlogExtend != null) { imgPath = miniBlogExtend.ImgPath; flashPath = miniBlogExtend.Video; } CY.UME.Core.Business.MiniBlogExtend newMiniBlogExtend = new CY.UME.Core.Business.MiniBlogExtend(); newMiniBlogExtend.AccountId = newMiniBlog.AccountId; newMiniBlogExtend.Id = newMiniBlog.Id; newMiniBlogExtend.ImgPath = imgPath; newMiniBlogExtend.Video = flashPath; newMiniBlogExtend.IsMsgReceived = false; newMiniBlogExtend.IsPhoneSended = false; newMiniBlogExtend.ReferedId = miniBlog.Id; newMiniBlogExtend.ReferedName = accountRefered.Name; newMiniBlogExtend.ReferedAuthorId = accountRefered.Id; newMiniBlogExtend.TransferedNum = 0; newMiniBlogExtend.Save(); account.SendNoticeToAllFriendAndFollower("miniblog", "转发了一篇微博", newMiniBlog.Id.ToString()); CY.UME.Core.Business.Notice notice = new CY.UME.Core.Business.Notice(); notice.AccountId = newMiniBlogExtend.AccountId; notice.AuthorId = newMiniBlogExtend.AccountId; notice.Content = "转发了一篇微博"; notice.DateCreated = DateTime.Now; notice.InstanceId = newMiniBlogExtend.Id.ToString(); notice.IsReaded = false; notice.Type = "miniblog"; notice.Save(); #region Reply string strReplyedIdTemp = String.Empty; string[] arrReplyedId = strReplyedId.Split(','); for (int i = 0; i < arrReplyedId.Length; i++) { strReplyedIdTemp = arrReplyedId[i]; long replyedId = 0; if (long.TryParse(strReplyedIdTemp, out replyedId)) { CY.UME.Core.Business.MiniBlog replyedMiniBlog = CY.UME.Core.Business.MiniBlog.Load(replyedId); if (replyedMiniBlog != null) { CY.UME.Core.Business.MiniBlogComment mbc = new CY.UME.Core.Business.MiniBlogComment(); mbc.AccountId = replyedMiniBlog.AccountId; mbc.AuthorId = account.Id; mbc.Content = content; mbc.DateCreated = DateTime.Now; mbc.IP = Utility.Common.RequestUtility.ClientIP; mbc.InstanceId = replyedMiniBlog.Id; mbc.Save(); CY.UME.Core.Business.Notice noticeTemp = new CY.UME.Core.Business.Notice(); noticeTemp.AccountId = replyedMiniBlog.AccountId; noticeTemp.AuthorId = mbc.AuthorId; noticeTemp.Content = "评论了您的微博"; noticeTemp.DateCreated = DateTime.Now; noticeTemp.InstanceId = replyedId.ToString(); noticeTemp.IsReaded = false; noticeTemp.Type = "miniblogreply"; noticeTemp.Save(); } } } #endregion context.Response.Write("{success:true}"); } catch { context.Response.Write("{success:false,msg:'服务器忙,请稍后再试'}"); } }
/// <summary> /// 添加回复 /// </summary> /// <returns>0登录失败 -1 请求失败 -2异常错误 -3该微博不存在或已被删除</returns> public string AddMiniBlogComment(HttpContext context) { string email = String.Empty; string content = String.Empty; long referedId = 0; long instanceId = 0; CY.UME.Core.Business.AccountExtend ae; CY.UME.Core.Business.MiniBlog miniBlog; #region validate if (context.Request.QueryString["email"] == null || context.Request.QueryString["Content"] == null || context.Request.QueryString["MiniBlogId"] == null || !long.TryParse(context.Request.QueryString["MiniBlogId"].ToString(), out instanceId)) { return "-1"; } email = context.Request.QueryString["email"].ToString(); ae = CY.UME.Core.Business.AccountExtend.Load(email); if (ae == null) { return "-1"; } content = context.Request.QueryString["Content"].ToString(); miniBlog = CY.UME.Core.Business.MiniBlog.Load(instanceId); if (miniBlog == null) { return "-3"; } if (context.Request.QueryString["referedId"] != null) { long.TryParse(context.Request.QueryString["referedId"].ToString(), out referedId); } #endregion try { CY.UME.Core.Business.MiniBlogComment mbc = new CY.UME.Core.Business.MiniBlogComment(); mbc.AccountId = miniBlog.AccountId; mbc.AuthorId = ae.Id; mbc.DateCreated = DateTime.Now; mbc.Content = content; mbc.InstanceId = instanceId; mbc.ReferedId = referedId; mbc.Save(); //添加通知 if (ae.Id != miniBlog.AccountId || referedId > 0) { CY.UME.Core.Business.Notice notice = new CY.UME.Core.Business.Notice(); if (referedId > 0) { CY.UME.Core.Business.MiniBlogComment mbcTemp = CY.UME.Core.Business.MiniBlogComment.Load(referedId); if (mbcTemp != null) { notice.AccountId = mbcTemp.AuthorId; notice.Content = "回复了您的评论"; } else { notice.AccountId = miniBlog.AccountId; notice.Content = "回复了您"; } } else { notice.AccountId = miniBlog.AccountId; notice.Content = "回复了您"; } notice.AuthorId = ae.Id; notice.DateCreated = DateTime.Now; notice.InstanceId = miniBlog.Id.ToString(); notice.IsReaded = false; notice.Type = "miniblogreply"; notice.Save(); } return mbc.Id.ToString(); } catch { return "-2"; } }