Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /*
         * Description:
         *      每个用户UID 15秒内只能调用一次该接口,否则无法更新成功
         */
        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.Users.GetShortUserInfo(commandParam.LocalUid).Adminid != 1)
                {
                    result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList);
                    return(false);
                }
            }

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

            string[] values = commandParam.GetDNTParam("additional_values").ToString().Split(',');
            string[] uids   = commandParam.GetDNTParam("uids").ToString().Split(',');

            if (!Utils.IsNumericArray(uids) || !Utils.IsNumericArray(values) || uids.Length > 100)
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList);
                return(false);
            }

            if (values.Length != 8)
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList);
                return(false);
            }

            List <float> list = new List <float>();

            for (int i = 0; i < values.Length; i++)
            {
                list.Add(Utils.StrToFloat(values[i], 0));
            }

            foreach (string uId in uids)
            {
                int id = TypeConverter.StrToInt(uId);
                if (id == 0)
                {
                    continue;
                }

                if (!CommandCacheQueue <SetExtCreditItem> .EnQueue(new SetExtCreditItem(id, DateTime.Now.Ticks)))
                {
                    continue;
                }

                CreditsFacade.UpdateUserExtCredits(id, list.ToArray(), true);
                CreditsFacade.UpdateUserCredits(id);

                //向第三方应用同步积分
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i] != 0.0)
                    {
                        Sync.UpdateCredits(TypeConverter.StrToInt(uId), i + 1, list[i].ToString(), commandParam.AppInfo.APIKey);
                    }
                }
            }

            if (commandParam.Format == FormatType.JSON)
            {
                result = "true";
            }
            else
            {
                SetExtCreditsResponse secr = new SetExtCreditsResponse();
                secr.Successfull = 1;
                result           = SerializationHelper.Serialize(secr);
            }
            return(true);
        }