/// <summary> /// 回复 /// </summary> /// <returns></returns> public string Reply() { if (Signature != GetParam("sig").ToString()) { ErrorCode = (int)ErrorType.API_EC_SIGNATURE; return ""; } //如果是桌面程序则需要验证用户身份 if (this.App.ApplicationType == (int)ApplicationType.DESKTOP) { if (Uid < 1) { ErrorCode = (int)ErrorType.API_EC_SESSIONKEY; return ""; } } if (CallId <= LastCallId) { ErrorCode = (int)ErrorType.API_EC_CALLID; return ""; } if (!CheckRequiredParams("reply_info")) { ErrorCode = (int)ErrorType.API_EC_PARAM; return ""; } Reply reply; try { reply = JavaScriptConvert.DeserializeObject<Reply>(GetParam("reply_info").ToString()); } catch { ErrorCode = (int)ErrorType.API_EC_PARAM; return ""; } if (reply == null || AreParamsNullOrZeroOrEmptyString(reply.Tid, reply.Fid, reply.Message)) { ErrorCode = (int)ErrorType.API_EC_PARAM; return ""; } if (reply.Title == null) { reply.Title = string.Empty; } TopicInfo topicinfo = Discuz.Forum.Topics.GetTopicInfo(reply.Tid); if (topicinfo == null) { ErrorCode = (int)ErrorType.API_EC_PARAM; return ""; } if (topicinfo.Closed == 1) { ErrorCode = (int)ErrorType.API_EC_TOPIC_CLOSED; return ""; } ForumInfo foruminfo = Discuz.Forum.Forums.GetForumInfo(reply.Fid); if (foruminfo == null) { ErrorCode = (int)ErrorType.API_EC_PARAM; return ""; } int groupid = 0; ShortUserInfo userinfo = Discuz.Forum.Users.GetShortUserInfo(Uid); if (userinfo == null) groupid = 7; else groupid = userinfo.Groupid; UserGroupInfo usergroupinfo = Discuz.Forum.UserGroups.GetUserGroupInfo(groupid); if (topicinfo.Readperm > usergroupinfo.Readaccess && topicinfo.Posterid != Uid && usergroupinfo.Radminid != 1 && (userinfo != null && !Utils.InArray(userinfo.Username, foruminfo.Moderators.Split(',')))) { ErrorCode = (int)ErrorType.API_EC_TOPIC_READ_PERM; return ""; } if (foruminfo.Password != "") { ErrorCode = (int)ErrorType.API_EC_FORUM_PASSWORD; return ""; } if (!Discuz.Forum.Forums.AllowViewByUserId(foruminfo.Permuserlist, Uid)) //判断当前用户在当前版块浏览权限 { if (foruminfo.Viewperm == null || foruminfo.Viewperm == string.Empty)//当板块权限为空时,按照用户组权限 { if (usergroupinfo.Allowvisit != 1) { ErrorCode = (int)ErrorType.API_EC_FORUM_PERM; return ""; } } else//当板块权限不为空,按照板块权限 { if (!Discuz.Forum.Forums.AllowView(foruminfo.Viewperm, groupid)) { ErrorCode = (int)ErrorType.API_EC_FORUM_PERM; return ""; } } } //是否有回复的权限 if (!Discuz.Forum.Forums.AllowReplyByUserID(foruminfo.Permuserlist, Uid)) { if (foruminfo.Replyperm == null || foruminfo.Replyperm == string.Empty)//当板块权限为空时根据用户组权限判断 { // 验证用户是否有发表主题的权限 if (usergroupinfo.Allowreply != 1) { ErrorCode = (int)ErrorType.API_EC_REPLY_PERM; return ""; } } else//板块权限不为空时根据板块权限判断 { if (!Discuz.Forum.Forums.AllowReply(foruminfo.Replyperm, groupid)) { ErrorCode = (int)ErrorType.API_EC_REPLY_PERM; return ""; } } } // 如果是受灌水限制用户, 则判断是否是灌水 if (userinfo != null) { string joindate = userinfo.Joindate; if (Utils.StrDateDiffMinutes(joindate, Config.Newbiespan) < 0) { ErrorCode = (int)ErrorType.API_EC_FRESH_USER; return ""; } } if (reply.Title.IndexOf(" ") != -1) { ErrorCode = (int)ErrorType.API_EC_FRESH_USER; return ""; } else if (reply.Title.Length > 60) { ErrorCode = (int)ErrorType.API_EC_FRESH_USER; return ""; } if (reply.Message.Length < Config.Minpostsize) { ErrorCode = (int)ErrorType.API_EC_MESSAGE_LENGTH; return ""; } if (reply.Message.Length > Config.Maxpostsize) { ErrorCode = (int)ErrorType.API_EC_MESSAGE_LENGTH; return ""; } //新用户广告强力屏蔽检查 if ((Config.Disablepostad == 1) && usergroupinfo.Radminid < 1 || userinfo == null) //如果开启新用户广告强力屏蔽检查或是游客 { if (userinfo == null || (Config.Disablepostadpostcount != 0 && userinfo.Posts <= Config.Disablepostadpostcount) || (Config.Disablepostadregminute != 0 && DateTime.Now.AddMinutes(-Config.Disablepostadregminute) <= Convert.ToDateTime(userinfo.Joindate))) { foreach (string regular in Config.Disablepostadregular.Replace("\r", "").Split('\n')) { if (Posts.IsAD(regular, reply.Title, reply.Message)) { ErrorCode = (int)ErrorType.API_EC_SPAM; return ""; } } } } if (ForumUtils.HasBannedWord(reply.Title) || ForumUtils.HasBannedWord(reply.Message)) { ErrorCode = (int)ErrorType.API_EC_SPAM; return ""; } PostInfo postInfo = PostReply(Uid, reply, usergroupinfo, userinfo, foruminfo, topicinfo.Title); if (topicinfo.Replies < (Config.Ppp + 9)) { ForumUtils.DeleteTopicCacheFile(topicinfo.Tid); } TopicReplyResponse trr = new TopicReplyResponse(); trr.PostId = postInfo.Pid; trr.Url = ForumUrl + string.Format("showtopic.aspx?topicid={0}&page=end#{1}", reply.Tid, trr.PostId); trr.NeedAudit = postInfo.Invisible == 1; //同步到其他应用程序 Sync.Reply(postInfo.Pid.ToString(), postInfo.Tid.ToString(), postInfo.Topictitle, postInfo.Poster, postInfo.Posterid.ToString(), postInfo.Fid.ToString()); if (Format == FormatType.JSON) { return JavaScriptConvert.SerializeObject(trr); } return SerializationHelper.Serialize(trr); }
public override bool Run(CommandParameter commandParam, ref string result) { //如果validate为true,则校验数据的合法性,包括广告强力屏蔽,是否含有需审核的,以及非法内容.和当前用户的发帖权限 bool validate = commandParam.GetIntParam("validate") == 1 || commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP; //桌面程序因为安全需要,游客不允许操作 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } if (!commandParam.CheckRequiredParams("reply_info")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } Reply reply; try { reply = JavaScriptConvert.DeserializeObject<Reply>(commandParam.GetDNTParam("reply_info").ToString()); } catch { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (reply == null || Util.AreParamsNullOrZeroOrEmptyString(reply.Tid, reply.Fid, reply.Message)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } if (reply.Title == null) reply.Title = string.Empty; if (reply.Title.IndexOf(" ") != -1 || reply.Title.Length > 60) { result = Util.CreateErrorMessage(ErrorType.API_EC_TITLE_INVALID, commandParam.ParamList); return false; } if (reply.Message.Length < commandParam.GeneralConfig.Minpostsize || reply.Message.Length > commandParam.GeneralConfig.Maxpostsize) { result = Util.CreateErrorMessage(ErrorType.API_EC_MESSAGE_LENGTH, commandParam.ParamList); return false; } ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(reply.Fid); if (forumInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_FORUM_NOT_EXIST, commandParam.ParamList); return false; } TopicInfo topicInfo = Discuz.Forum.Topics.GetTopicInfo(reply.Tid); if (topicInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_TOPIC_NOT_EXIST, commandParam.ParamList); return false; } //validate=true或未指定回帖uid时则默认读取当前用户uid,游客为-1 ShortUserInfo userInfo = Discuz.Forum.Users.GetShortUserInfo(validate || reply.Uid == null ? commandParam.LocalUid : (int)reply.Uid); userInfo = userInfo == null ? TopicsCommandUtils.GetGuestUserInfo() : userInfo; UserGroupInfo userGroupInfo = Discuz.Forum.UserGroups.GetUserGroupInfo(userInfo.Groupid); AdminGroupInfo adminInfo = AdminGroups.GetAdminGroupInfo(userGroupInfo.Groupid); //是否受审核、过滤、灌水等限制权限 int disablePost = adminInfo != null ? adminInfo.Disablepostctrl : userGroupInfo.Disableperiodctrl; bool hasAudit = false; if (validate) { ErrorType et = TopicsCommandUtils.GeneralValidate(reply.Title, reply.Message, userInfo, userGroupInfo, forumInfo, commandParam, disablePost); if (et != ErrorType.API_EC_NONE) { result = Util.CreateErrorMessage(et, commandParam.ParamList); return false; } //是否有回复的权限 if (!UserAuthority.PostReply(forumInfo, commandParam.LocalUid, userGroupInfo, topicInfo)) { result = Util.CreateErrorMessage(topicInfo.Closed >= 1 ? ErrorType.API_EC_TOPIC_CLOSED : ErrorType.API_EC_REPLY_PERM, commandParam.ParamList); return false; } if (disablePost != 1) { et = TopicsCommandUtils.PostTimeAndRepostMessageValidate(userInfo, reply.Title + reply.Message); if (et != ErrorType.API_EC_NONE) { result = Util.CreateErrorMessage(et, commandParam.ParamList); return false; } //内容中是否含有需审核的词汇 if (ForumUtils.HasAuditWord(reply.Title + reply.Message)) hasAudit = true; reply.Title = ForumUtils.BanWordFilter(reply.Title); reply.Message = ForumUtils.BanWordFilter(reply.Message); } } PostInfo postInfo = TopicsCommandUtils.PostReply(reply, userGroupInfo, userInfo, forumInfo, topicInfo.Title, disablePost, hasAudit); if (topicInfo.Replies < (commandParam.GeneralConfig.Ppp + 9)) { ForumUtils.DeleteTopicCacheFile(topicInfo.Tid); } TopicReplyResponse trr = new TopicReplyResponse(); trr.PostId = postInfo.Pid; trr.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + string.Format("showtopic.aspx?topicid={0}&postid={1}#{1}", reply.Tid, trr.PostId); trr.NeedAudit = postInfo.Invisible == 1; //同步到其他应用程序 Sync.Reply(postInfo.Pid.ToString(), postInfo.Tid.ToString(), postInfo.Topictitle, postInfo.Poster, postInfo.Posterid.ToString(), postInfo.Fid.ToString(), commandParam.AppInfo.APIKey); result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(trr) : SerializationHelper.Serialize(trr); return true; }