Esempio n. 1
0
        /// <summary>
        /// 发送通知
        /// </summary>
        /// <returns></returns>
        public string Send()
        {
            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("subject,message,to_ids"))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return("");
            }
            string ids = GetParam("to_ids").ToString();

            if (!CheckRequiredParams("to_ids") || !Utils.IsNumericArray(ids.Split(',')))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return("");
            }

            if ((!CheckRequiredParams("from_id") || !Utils.IsNumeric(GetParam("from_id"))) && Uid < 1)
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return("");
            }
            int fromId = TypeConverter.ObjectToInt(GetParam("from_id"), Uid);

            string message = UBB.ParseUrl(Utils.EncodeHtml(GetParam("message").ToString()));

            string[] to_ids = ids.Split(',');

            string successfulIds = string.Empty;

            foreach (string id in to_ids)
            {
                if (TypeConverter.StrToInt(id) < 1)
                {
                    continue;
                }
                PrivateMessageInfo pm = new PrivateMessageInfo();
                pm.Folder       = 0;
                pm.Message      = message;
                pm.Msgfrom      = Discuz.Forum.Users.GetShortUserInfo(fromId).Username;
                pm.Msgfromid    = fromId;
                pm.Msgto        = "";//可能需要查询具体的收件人姓名
                pm.Msgtoid      = TypeConverter.StrToInt(id);
                pm.New          = 1;
                pm.Postdatetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                pm.Subject      = GetParam("subject").ToString();

                successfulIds += (PrivateMessages.CreatePrivateMessage(pm, 0) > 0) ? (id + ",") : "";
            }
            successfulIds = successfulIds.Length > 0 ? successfulIds.Remove(successfulIds.Length - 1) : successfulIds;

            if (Format == FormatType.JSON)
            {
                return(string.Format("\"{0}\"", successfulIds));
            }

            MessageSendResponse nsr = new MessageSendResponse();

            nsr.Result = successfulIds;
            return(SerializationHelper.Serialize(nsr));
        }
Esempio n. 2
0
        /*
         * 每个用户UID 30秒内只能调用一次该接口
         */
        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("subject,message,to_ids"))
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList);
                return(false);
            }

            string ids = commandParam.GetDNTParam("to_ids").ToString();

            if (!Utils.IsNumericList(ids))
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList);
                return(false);
            }

            string[] idArray = ids.Split(',');
            if (idArray.Length > 10)
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PM_TOID_OVERFLOW, commandParam.ParamList);
                return(false);
            }
            //桌面应用程序用户强制使用session_info.uid
            int fromId = commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP ?
                         commandParam.LocalUid : commandParam.GetIntParam("from_id", commandParam.LocalUid);
            ShortUserInfo fromUserInfo = Discuz.Forum.Users.GetShortUserInfo(fromId);

            if (fromUserInfo == null)
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PM_FROMID_NOT_EXIST, commandParam.ParamList);
                return(false);
            }

            //如果发送用户不是管理员,且在30秒内调用了该接口
            if (fromUserInfo.Adminid != 1 && !CommandCacheQueue <SendMessageItem> .EnQueue(new SendMessageItem(fromUserInfo.Uid, DateTime.Now.Ticks)))
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PM_VISIT_TOOFAST, commandParam.ParamList);
                return(false);
            }

            string message       = UBB.ParseUrl(Utils.EncodeHtml(commandParam.GetDNTParam("message").ToString()));
            string successfulIds = string.Empty;

            foreach (string id in ids.Split(','))
            {
                int toUid = TypeConverter.StrToInt(id);
                if (toUid < 1 || toUid == fromId)
                {
                    continue;
                }
                ShortUserInfo toUserInfo = Discuz.Forum.Users.GetShortUserInfo(toUid);
                if (toUserInfo == null)
                {
                    continue;
                }

                PrivateMessageInfo pm = new PrivateMessageInfo();
                pm.Folder       = 0;
                pm.Message      = message;
                pm.Msgfrom      = fromUserInfo.Username;
                pm.Msgfromid    = fromId;
                pm.Msgto        = toUserInfo.Username;
                pm.Msgtoid      = TypeConverter.StrToInt(id);
                pm.New          = 1;
                pm.Postdatetime = Utils.GetDateTime();
                pm.Subject      = commandParam.GetDNTParam("subject").ToString();

                successfulIds += (PrivateMessages.CreatePrivateMessage(pm, 0) > 0) ? (id + ",") : "";
            }
            successfulIds = successfulIds.Length > 0 ? successfulIds.Remove(successfulIds.Length - 1) : successfulIds;

            if (commandParam.Format == FormatType.JSON)
            {
                result = string.Format("\"{0}\"", successfulIds);
            }
            else
            {
                MessageSendResponse nsr = new MessageSendResponse();
                nsr.Result = successfulIds;
                result     = SerializationHelper.Serialize(nsr);
            }
            return(true);
        }
Esempio n. 3
0
        protected override void ShowPage()
        {
            if (!IsLogin())
            {
                return;
            }

            pagetitle = "查看短消息";

            if (pmid <= 0)
            {
                AddErrLine("参数无效");
                return;
            }

            if (!CreditsFacade.IsEnoughCreditsPM(userid))
            {
                canreplypm = false;
            }

            PrivateMessageInfo messageinfo = PrivateMessages.GetPrivateMessageInfo(pmid);

            if (messageinfo == null)
            {
                AddErrLine("无效的短消息ID");
                return;
            }

            if (messageinfo.Msgfrom == "系统" && messageinfo.Msgfromid == 0)
            {
                messageinfo.Message = Utils.HtmlDecode(messageinfo.Message);
            }

            if (messageinfo != null && (messageinfo.Msgtoid == userid || messageinfo.Msgfromid == userid))
            {
                //判断当前用户是否有权阅读此消息
                if (DNTRequest.GetQueryString("action").CompareTo("delete") == 0)
                {
                    ispost = true;
                    if (PrivateMessages.DeletePrivateMessage(userid, pmid) < 1)
                    {
                        AddErrLine("消息未找到,可能已被删除");
                        return;
                    }
                    else
                    {
                        AddMsgLine("指定消息成功删除,现在将转入消息列表");
                        SetUrl("usercpinbox.aspx");
                        SetMetaRefresh();
                        return;
                    }
                }

                if (DNTRequest.GetQueryString("action").CompareTo("noread") == 0)
                {
                    PrivateMessages.SetPrivateMessageState(pmid, 1); //将短消息的状态置 1 表示未读
                    ispost = true;
                    if (messageinfo.New != 1 && messageinfo.Folder == 0)
                    {
                        Users.UpdateUserNewPMCount(userid, olid); //将用户的未读短信息数据加 1
                        AddMsgLine("指定消息已被置成未读状态,现在将转入消息列表");
                        SetUrl("usercpinbox.aspx");
                        SetMetaRefresh();
                    }
                }
                else
                {
                    PrivateMessages.SetPrivateMessageState(pmid, 0); //将短消息的状态置 0 表示已读
                    if (messageinfo.New == 1 && messageinfo.Folder == 0)
                    {
                        Users.UpdateUserNewPMCount(userid, olid); //将用户的未读短信息数据减 1
                    }
                }

                msgto        = (messageinfo.Folder == 0) ? messageinfo.Msgfrom : messageinfo.Msgto;
                msgfrom      = messageinfo.Msgfrom;
                subject      = messageinfo.Subject;
                message      = UBB.ParseUrl(Utils.StrFormat(messageinfo.Message));
                postdatetime = messageinfo.Postdatetime;
                resubject    = "re:" + messageinfo.Subject;
                remessage    = Utils.HtmlEncode("> ") + messageinfo.Message.Replace("\n", "\n> ") + "\r\n\r\n";
                return;
            }
            AddErrLine("对不起, 短消息不存在或已被删除.");

            newnoticecount = Notices.GetNewNoticeCountByUid(userid);
        }
Esempio n. 4
0
        protected override void ShowPage()
        {
            if (!base.IsLogin())
            {
                return;
            }
            this.pagetitle = "查看短消息";
            if (this.pmid <= 0)
            {
                base.AddErrLine("参数无效");
                return;
            }
            if (!CreditsFacade.IsEnoughCreditsPM(this.userid))
            {
                this.canreplypm = false;
            }
            var msg = ShortMessage.FindByID(this.pmid);

            if (msg == null)
            {
                base.AddErrLine("无效的短消息ID");
                return;
            }
            if (msg.Msgfrom == "系统" && msg.MsgfromID == 0)
            {
                msg.Message = Utils.HtmlDecode(msg.Message);
            }
            if (msg == null || (msg.MsgtoID != this.userid && msg.MsgfromID != this.userid))
            {
                base.AddErrLine("对不起, 短消息不存在或已被删除.");
                this.newnoticecount = Notice.GetNewNoticeCountByUid(this.userid);
                return;
            }
            if (DNTRequest.GetQueryString("action").CompareTo("delete") != 0)
            {
                if (DNTRequest.GetQueryString("action").CompareTo("noread") == 0)
                {
                    //PrivateMessages.SetPrivateMessageState(this.pmid, 1);
                    msg.New = true;
                    msg.Update();
                    this.ispost = true;
                    if (!msg.New && msg.Folder == 0)
                    {
                        Users.UpdateUserNewPMCount(this.userid, this.olid);
                        base.AddMsgLine("指定消息已被置成未读状态,现在将转入消息列表");
                        base.SetUrl("usercpinbox.aspx");
                        base.SetMetaRefresh();
                    }
                }
                else
                {
                    //PrivateMessages.SetPrivateMessageState(this.pmid, 0);
                    msg.New = false;
                    msg.Update();

                    if (msg.New && msg.Folder == 0)
                    {
                        Users.UpdateUserNewPMCount(this.userid, this.olid);
                    }
                }
                this.msgto        = ((msg.Folder == 0) ? msg.Msgfrom : msg.Msgto);
                this.msgfrom      = msg.Msgfrom;
                this.subject      = msg.Subject;
                this.message      = UBB.ParseUrl(Utils.StrFormat(msg.Message));
                this.postdatetime = msg.PostDateTime.ToFullString();
                this.resubject    = "re:" + msg.Subject;
                this.remessage    = Utils.HtmlEncode("> ") + msg.Message.Replace("\n", "\n> ") + "\r\n\r\n";
                return;
            }
            this.ispost = true;
            msg.Delete();
            //if (ShortMessage.DeletePrivateMessage(this.userid, pmid + "") < 1)
            //{
            //    base.AddErrLine("消息未找到,可能已被删除");
            //    return;
            //}
            base.AddMsgLine("指定消息成功删除,现在将转入消息列表");
            base.SetUrl("usercpinbox.aspx");
            base.SetMetaRefresh();
        }