Exemple #1
0
        public override bool Run(CommandParameter commandParam, ref string result)
        {
            //如果是桌面程序则需要验证用户身份
            if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP)
            {
                if (commandParam.LocalUid < 1)
                {
                    result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList);
                    return(false);
                }
                //如果当前用户不是管理员
                if (Discuz.Forum.UserGroups.GetUserGroupInfo(Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid).Groupid).Radminid != 1)
                {
                    result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList);
                    return(false);
                }
            }

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

            //给当前登录用户发送通知可以将to_ids设置为空
            if (commandParam.LocalUid < 1 && (!commandParam.CheckRequiredParams("to_ids") || !Utils.IsNumericList(commandParam.GetDNTParam("to_ids").ToString())))
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList);
                return(false);
            }

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

            string notification = commandParam.GetDNTParam("notification").ToString();

            string[] to_ids;
            if (ids == string.Empty)
            {
                to_ids    = new string[1];
                to_ids[0] = commandParam.LocalUid.ToString();
            }
            else
            {
                to_ids = commandParam.GetDNTParam("to_ids").ToString().Split(',');
            }

            string        successfulIds = string.Empty;
            ShortUserInfo shortUserInfo = null;

            if (commandParam.LocalUid > 0)
            {
                shortUserInfo = Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid);
            }

            foreach (string id in to_ids)
            {
                if (Utils.StrToInt(id, 0) < 1)
                {
                    continue;
                }

                NoticeInfo noticeinfo = new NoticeInfo();
                noticeinfo.Uid          = Utils.StrToInt(id, 0);
                noticeinfo.New          = 1;
                noticeinfo.Postdatetime = Utils.GetDateTime();

                //如果应用程序没有指定来源id,则会将当前应用程序id的hash值作为来源ID,若不指定来源id,用户的通知列表中只存在一条最新的应用程序通知
                noticeinfo.Fromid = commandParam.GetIntParam("from_id", Utils.BKDEHash(commandParam.AppInfo.APIKey, 113));
                //如果应用程序指定了来源id,则通知类型为“应用程序自定义通知”,否则是“应用程序通知”
                noticeinfo.Type = commandParam.CheckRequiredParams("from_id") ? NoticeType.ApplicationCustomNotice : NoticeType.ApplicationNotice;

                if (commandParam.LocalUid > 0)
                {
                    noticeinfo.Poster   = shortUserInfo == null ? "" : shortUserInfo.Username;
                    noticeinfo.Posterid = commandParam.LocalUid;
                }
                else
                {
                    noticeinfo.Poster   = "";
                    noticeinfo.Posterid = 0;
                }
                noticeinfo.Note = Utils.EncodeHtml(notification);//需要做ubb标签转换

                if (Notices.CreateNoticeInfo(noticeinfo) > 0)
                {
                    successfulIds += (id + ",");
                }
            }

            if (successfulIds.Length > 0)
            {
                successfulIds = successfulIds.Remove(successfulIds.Length - 1);
            }
            if (commandParam.Format == FormatType.JSON)
            {
                result = string.Format("\"{0}\"", successfulIds);
            }
            else
            {
                NotificationSendResponse nsr = new NotificationSendResponse();
                nsr.Result = successfulIds;
                result     = SerializationHelper.Serialize(nsr);
            }
            return(true);
        }
Exemple #2
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 (Discuz.Forum.UserGroups.GetUserGroupInfo(Discuz.Forum.Users.GetShortUserInfo(Uid).Groupid).Radminid != 1)
                {
                    ErrorCode = (int)ErrorType.API_EC_PERMISSION_DENIED;
                    return "";
                }
            }

            if (CallId <= LastCallId)
            {
                ErrorCode = (int)ErrorType.API_EC_CALLID;
                return "";
            }

            if (!CheckRequiredParams("notification"))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }

            if (GetParam("to_ids") == null)
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }

            if (Uid < 1 && (!CheckRequiredParams("to_ids") || !Utils.IsNumericArray(GetParam("to_ids").ToString().Split(','))))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }

            string ids = GetParam("to_ids").ToString();

            string notification = GetParam("notification").ToString();

            string[] to_ids;
            if (ids == string.Empty)
            {
                to_ids = new string[1];
                to_ids[0] = Uid.ToString();
            }
            else
            {
                to_ids = GetParam("to_ids").ToString().Split(',');
            }

            string successfulIds = string.Empty;
            ShortUserInfo shortUserInfo = null;
            if (Uid > 0)
            {
                shortUserInfo = Discuz.Forum.Users.GetShortUserInfo(Uid);
            }
            foreach (string id in to_ids)
            {
                if (Utils.StrToInt(id, 0) < 1)
                {
                    continue;
                }
                NoticeInfo noticeinfo = new NoticeInfo();
                noticeinfo.Uid = Utils.StrToInt(id, 0);
                noticeinfo.New = 1;
                noticeinfo.Postdatetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (Uid > 0)
                {
                    //ShortUserInfo shortUserInfo = Discuz.Forum.Users.GetShortUserInfo(Uid);
                    noticeinfo.Poster = shortUserInfo == null ? "" : shortUserInfo.Username;
                    noticeinfo.Posterid = Uid;
                }
                else
                {
                    noticeinfo.Poster = "";
                    noticeinfo.Posterid = 0;
                }
                noticeinfo.Note = Utils.EncodeHtml(notification);//需要做ubb标签转换

                if (Notices.CreateNoticeInfo(noticeinfo) > 0)
                {
                    successfulIds += (id + ",");
                }

            }

            if (successfulIds.Length > 0)
                successfulIds = successfulIds.Remove(successfulIds.Length - 1);
            if (Format == FormatType.JSON)
                return string.Format("\"{0}\"", successfulIds);


            NotificationSendResponse nsr = new NotificationSendResponse();
            nsr.Result = successfulIds;
            return SerializationHelper.Serialize(nsr);
        }
Exemple #3
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 (Discuz.Forum.UserGroups.GetUserGroupInfo(Discuz.Forum.Users.GetShortUserInfo(Uid).Groupid).Radminid != 1)
                {
                    ErrorCode = (int)ErrorType.API_EC_PERMISSION_DENIED;
                    return("");
                }
            }

            if (CallId <= LastCallId)
            {
                ErrorCode = (int)ErrorType.API_EC_CALLID;
                return("");
            }

            if (!CheckRequiredParams("notification"))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return("");
            }

            if (GetParam("to_ids") == null)
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return("");
            }

            if (Uid < 1 && (!CheckRequiredParams("to_ids") || !Utils.IsNumericArray(GetParam("to_ids").ToString().Split(','))))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return("");
            }

            string ids = GetParam("to_ids").ToString();

            string notification = GetParam("notification").ToString();

            string[] to_ids;
            if (ids == string.Empty)
            {
                to_ids    = new string[1];
                to_ids[0] = Uid.ToString();
            }
            else
            {
                to_ids = GetParam("to_ids").ToString().Split(',');
            }

            string        successfulIds = string.Empty;
            ShortUserInfo shortUserInfo = null;

            if (Uid > 0)
            {
                shortUserInfo = Discuz.Forum.Users.GetShortUserInfo(Uid);
            }
            foreach (string id in to_ids)
            {
                if (Utils.StrToInt(id, 0) < 1)
                {
                    continue;
                }
                NoticeInfo noticeinfo = new NoticeInfo();
                noticeinfo.Uid          = Utils.StrToInt(id, 0);
                noticeinfo.New          = 1;
                noticeinfo.Postdatetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (Uid > 0)
                {
                    //ShortUserInfo shortUserInfo = Discuz.Forum.Users.GetShortUserInfo(Uid);
                    noticeinfo.Poster   = shortUserInfo == null ? "" : shortUserInfo.Username;
                    noticeinfo.Posterid = Uid;
                }
                else
                {
                    noticeinfo.Poster   = "";
                    noticeinfo.Posterid = 0;
                }
                noticeinfo.Note = Utils.EncodeHtml(notification);//需要做ubb标签转换

                if (Notices.CreateNoticeInfo(noticeinfo) > 0)
                {
                    successfulIds += (id + ",");
                }
            }

            if (successfulIds.Length > 0)
            {
                successfulIds = successfulIds.Remove(successfulIds.Length - 1);
            }
            if (Format == FormatType.JSON)
            {
                return(string.Format("\"{0}\"", successfulIds));
            }


            NotificationSendResponse nsr = new NotificationSendResponse();

            nsr.Result = successfulIds;
            return(SerializationHelper.Serialize(nsr));
        }
        public override bool Run(CommandParameter commandParam, ref string result)
        {
            //如果是桌面程序则需要验证用户身份
            if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP)
            {
                if (commandParam.LocalUid < 1)
                {
                    result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList);
                    return false;
                }
                //如果当前用户不是管理员
                if (Discuz.Forum.UserGroups.GetUserGroupInfo(Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid).Groupid).Radminid != 1)
                {
                    result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList);
                    return false;
                }
            }

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

            //给当前登录用户发送通知可以将to_ids设置为空
            if (commandParam.LocalUid < 1 && (!commandParam.CheckRequiredParams("to_ids") || !Utils.IsNumericList(commandParam.GetDNTParam("to_ids").ToString())))
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList);
                return false;
            }

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

            string notification = commandParam.GetDNTParam("notification").ToString();

            string[] to_ids;
            if (ids == string.Empty)
            {
                to_ids = new string[1];
                to_ids[0] = commandParam.LocalUid.ToString();
            }
            else
            {
                to_ids = commandParam.GetDNTParam("to_ids").ToString().Split(',');
            }

            string successfulIds = string.Empty;
            ShortUserInfo shortUserInfo = null;
            if (commandParam.LocalUid > 0)
                shortUserInfo = Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid);

            foreach (string id in to_ids)
            {
                if (Utils.StrToInt(id, 0) < 1)
                    continue;

                NoticeInfo noticeinfo = new NoticeInfo();
                noticeinfo.Uid = Utils.StrToInt(id, 0);
                noticeinfo.New = 1;
                noticeinfo.Postdatetime = Utils.GetDateTime();

                //如果应用程序没有指定来源id,则会将当前应用程序id的hash值作为来源ID,若不指定来源id,用户的通知列表中只存在一条最新的应用程序通知
                noticeinfo.Fromid = commandParam.GetIntParam("from_id", Utils.BKDEHash(commandParam.AppInfo.APIKey, 113));
                //如果应用程序指定了来源id,则通知类型为“应用程序自定义通知”,否则是“应用程序通知”
                noticeinfo.Type = commandParam.CheckRequiredParams("from_id") ? NoticeType.ApplicationCustomNotice : NoticeType.ApplicationNotice;

                if (commandParam.LocalUid > 0)
                {
                    noticeinfo.Poster = shortUserInfo == null ? "" : shortUserInfo.Username;
                    noticeinfo.Posterid = commandParam.LocalUid;
                }
                else
                {
                    noticeinfo.Poster = "";
                    noticeinfo.Posterid = 0;
                }
                noticeinfo.Note = Utils.EncodeHtml(notification);//需要做ubb标签转换

                if (Notices.CreateNoticeInfo(noticeinfo) > 0)
                    successfulIds += (id + ",");
            }

            if (successfulIds.Length > 0)
                successfulIds = successfulIds.Remove(successfulIds.Length - 1);
            if (commandParam.Format == FormatType.JSON)
            {
                result = string.Format("\"{0}\"", successfulIds);
            }
            else
            {
                NotificationSendResponse nsr = new NotificationSendResponse();
                nsr.Result = successfulIds;
                result = SerializationHelper.Serialize(nsr);
            }
            return true;
        }