示例#1
0
        /// <summary>
        /// 获得最新回复
        /// </summary>
        /// <returns></returns>
        public string GetRecentReplies()
        {
            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("fid,tid,page_size,page_index"))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }

            int tid = Utils.StrToInt(GetParam("tid"), 0);
            int fid = Utils.StrToInt(GetParam("fid"), 0);
            TopicInfo topicInfo = Discuz.Forum.Topics.GetTopicInfo(tid);
            if (topicInfo == null)
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }

            ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(fid);
            if (forumInfo == null)
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }

            PostpramsInfo postPramsInfo = GetPostParamInfo(topicInfo, forumInfo);

            System.Data.DataTable lastpostlist = Posts.GetPagedLastDataTable(postPramsInfo);

            List<Post> list = new List<Post>();
            foreach (System.Data.DataRow dr in lastpostlist.Rows)
            {
                Post post = new Post();
                post.AdIndex = Utils.StrToInt(dr["adindex"], 0);
                post.Invisible = Utils.StrToInt(dr["invisible"], 0);
                post.Layer = Utils.StrToInt(dr["layer"], 0);
                post.Message = dr["message"].ToString();
                post.Pid = Utils.StrToInt(dr["pid"], 0);
                post.PostDateTime = DateTime.Parse(dr["postdatetime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                post.PosterAvator = dr["avatar"].ToString().Replace("\\", "/");
                post.PosterAvatorWidth = Utils.StrToInt(dr["avatarwidth"], 0);
                post.PosterAvatorHeight = Utils.StrToInt(dr["avatarheight"], 0);
                post.PosterEmail = dr["email"].ToString().Trim();
                post.PosterId = Utils.StrToInt(dr["posterid"], 0);
                post.PosterLocation = dr["location"].ToString();
                post.PosterName = dr["poster"].ToString();
                post.PosterShowEmail = Utils.StrToInt(dr["showemail"], 0);
                post.PosterSignature = dr["signature"].ToString();
                post.Rate = Utils.StrToInt(dr["rate"], 0);
                post.RateTimes = Utils.StrToInt(dr["ratetimes"], 0);
                post.UseSignature = Utils.StrToInt(dr["usesig"], 0);

                list.Add(post);
            }

            TopicGetRencentRepliesResponse tgrrr = new TopicGetRencentRepliesResponse();

            tgrrr.List = true;
            tgrrr.Count = topicInfo.Replies;
            tgrrr.Posts = list.ToArray();


            if (Format == FormatType.JSON)
            {
                return JavaScriptConvert.SerializeObject(tgrrr);
            }
            return Util.AddMessageCDATA(SerializationHelper.Serialize(tgrrr));
        }
示例#2
0
        public override bool Run(CommandParameter commandParam, ref string result)
        {
            //如果是桌面程序则需要验证用户身份
            if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1)
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList);
                return false;
            }

            if (!commandParam.CheckRequiredParams("fid,tid,page_size,page_index"))
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList);
                return false;
            }

            int fid = commandParam.GetIntParam("fid");
            ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(fid);
            if (forumInfo == null)
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_FORUM_NOT_EXIST, commandParam.ParamList);
                return false;
            }

            int tid = commandParam.GetIntParam("tid");
            TopicInfo topicInfo = Discuz.Forum.Topics.GetTopicInfo(tid);
            if (topicInfo == null)
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_TOPIC_NOT_EXIST, commandParam.ParamList);
                return false;
            }

            int pageSize = commandParam.GetIntParam("page_size", commandParam.GeneralConfig.Ppp);
            int pageIndex = commandParam.GetIntParam("page_index", 1);
            pageSize = pageSize < 1 ? commandParam.GeneralConfig.Ppp : pageSize;
            pageIndex = pageIndex < 1 ? 1 : pageIndex;

            PostpramsInfo postPramsInfo = TopicsCommandUtils.GetPostParamInfo(commandParam.LocalUid, topicInfo, forumInfo, pageSize, pageIndex);
            System.Data.DataTable lastpostlist = Posts.GetPagedLastDataTable(postPramsInfo);

            List<Post> list = new List<Post>();
            foreach (System.Data.DataRow dr in lastpostlist.Rows)
            {
                Post post = new Post();
                post.AdIndex = Utils.StrToInt(dr["adindex"], 0);
                post.Invisible = Utils.StrToInt(dr["invisible"], 0);
                post.Layer = Utils.StrToInt(dr["layer"], 0);
                post.Message = dr["message"].ToString();
                post.Pid = Utils.StrToInt(dr["pid"], 0);
                post.PostDateTime = DateTime.Parse(dr["postdatetime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                post.PosterAvator = dr["avatar"].ToString().Replace("\\", "/");
                post.PosterAvatorWidth = Utils.StrToInt(dr["avatarwidth"], 0);
                post.PosterAvatorHeight = Utils.StrToInt(dr["avatarheight"], 0);
                post.PosterEmail = dr["email"].ToString().Trim();
                post.PosterId = Utils.StrToInt(dr["posterid"], 0);
                post.PosterLocation = dr["location"].ToString();
                post.PosterName = dr["poster"].ToString();
                post.PosterShowEmail = Utils.StrToInt(dr["showemail"], 0);
                post.PosterSignature = dr["signature"].ToString();
                post.Rate = Utils.StrToInt(dr["rate"], 0);
                post.RateTimes = Utils.StrToInt(dr["ratetimes"], 0);
                post.UseSignature = Utils.StrToInt(dr["usesig"], 0);

                list.Add(post);
            }

            TopicGetRencentRepliesResponse tgrrr = new TopicGetRencentRepliesResponse();
            tgrrr.List = true;
            tgrrr.Count = topicInfo.Replies;
            tgrrr.Posts = list.ToArray();

            result = commandParam.Format == FormatType.JSON ?
                JavaScriptConvert.SerializeObject(tgrrr) : Util.AddMessageCDATA(SerializationHelper.Serialize(tgrrr));
            return true;
        }