Exemplo n.º 1
0
        public string SetExtCredits()
        {
            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.Users.GetShortUserInfo(Uid).Adminid != 1)
                {
                    ErrorCode = (int)ErrorType.API_EC_PERMISSION_DENIED;
                    return "";
                }
            }

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

            if (!this.CheckRequiredParams("uids,additional_values"))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }

            if (!Utils.IsNumericArray(GetParam("additional_values").ToString().Split(',')) || !Utils.IsNumericArray(GetParam("uids").ToString().Split(',')))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }

            string[] values = GetParam("additional_values").ToString().Split(',');
            if (values.Length != 8)
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }

            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 GetParam("uids").ToString().Split(','))
            {
                int id = TypeConverter.StrToInt(uId);
                if (id == 0)
                    continue;
                UserCredits.UpdateUserExtCredits(id, list.ToArray(), true);

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

            int successful = 1;

            if (Format == FormatType.JSON)
            {
                return successful == 1 ? "true" : "false";
            }


            SetExtCreditsResponse secr = new SetExtCreditsResponse();

            secr.Successfull = successful;

            return SerializationHelper.Serialize(secr);
        }
Exemplo 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;
        }
Exemplo n.º 3
0
        public string SetExtCredits()
        {
            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.Users.GetShortUserInfo(Uid).Adminid != 1)
                {
                    ErrorCode = (int)ErrorType.API_EC_PERMISSION_DENIED;
                    return("");
                }
            }

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

            if (!this.CheckRequiredParams("uids,additional_values"))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return("");
            }

            if (!Utils.IsNumericArray(GetParam("additional_values").ToString().Split(',')) || !Utils.IsNumericArray(GetParam("uids").ToString().Split(',')))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return("");
            }

            string[] values = GetParam("additional_values").ToString().Split(',');
            if (values.Length != 8)
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return("");
            }

            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 GetParam("uids").ToString().Split(','))
            {
                int id = TypeConverter.StrToInt(uId);
                if (id == 0)
                {
                    continue;
                }
                UserCredits.UpdateUserExtCredits(id, list.ToArray(), true);
                UserCredits.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(), ApiKey);
                    }
                }
            }

            int successful = 1;

            if (Format == FormatType.JSON)
            {
                return(successful == 1 ? "true" : "false");
            }

            SetExtCreditsResponse secr = new SetExtCreditsResponse();

            secr.Successfull = successful;

            return(SerializationHelper.Serialize(secr));
        }
Exemplo n.º 4
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);
        }