Exemplo n.º 1
0
        public static String getExpireAuth(Dictionary <object, object> context, int expiresSecond, RequestInputModel Params)
        {
            EvnContext evnContext = (EvnContext)context[QSConstant.EVN_CONTEXT_KEY];

            Dictionary <object, object> paramsQuery   = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_QUERY);
            Dictionary <object, object> paramsHeaders = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_HEADER);

            paramsHeaders.Remove(QSConstant.HEADER_PARAM_KEY_DATE);
            paramsHeaders.Clear();
            paramsHeaders.Add(QSConstant.HEADER_PARAM_KEY_EXPIRES, expiresSecond + "");

            string method      = (string)context[QSConstant.PARAM_KEY_REQUEST_METHOD];
            string bucketName  = (string)context[QSConstant.PARAM_KEY_BUCKET_NAME];
            string requestPath = (string)context[QSConstant.PARAM_KEY_REQUEST_PATH];

            requestPath = requestPath.Replace(QSConstant.BUCKET_NAME_REPLACE, bucketName);
            if (context.ContainsKey(QSConstant.PARAM_KEY_OBJECT_NAME))
            {
                requestPath = requestPath.Replace(QSConstant.OBJECT_NAME_REPLACE, (string)context[QSConstant.PARAM_KEY_OBJECT_NAME]);
            }
            string authSign = getSignature(
                evnContext.getAccessKey(),
                evnContext.getAccessSecret(),
                method,
                requestPath,
                paramsQuery,
                paramsHeaders);

            return(HttpUtility.UrlEncode(authSign, Encoding.GetEncoding(QSConstant.ENCODING_UTF8)));
        }
Exemplo n.º 2
0
        public static string generateQSURL(Dictionary <object, object> parameters, string requestUrl)
        {
            parameters = QSParamInvokeUtil.serializeParams(parameters);
            StringBuilder sbStringToSign = new StringBuilder();

            string[] sortedKeys = new string[200];
            int      i          = 0;

            foreach (var key in parameters.Keys)
            {
                sortedKeys[i] = key.ToString();
                i++;
            }
            //Array.Sort(sortedKeys);
            int j;
            int count = 0;

            try
            {
                for (j = 0; j < i; j++)
                {
                    string key = sortedKeys[j];
                    if (count != 0)
                    {
                        sbStringToSign.Append("&");
                    }
                    sbStringToSign
                    .Append(QSStringUtil.percentEncode(key, QSConstant.ENCODING_UTF8))
                    .Append("=")
                    .Append(QSStringUtil.percentEncode(parameters[key].ToString(), QSConstant.ENCODING_UTF8));
                    count++;
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
                System.Console.WriteLine(e.Message);
            }

            if (sbStringToSign.Length > 0)
            {
                if (requestUrl.IndexOf("?") > 0)
                {
                    return(requestUrl + "&" + sbStringToSign.ToString());
                }
                else
                {
                    return(requestUrl + "?" + sbStringToSign.ToString());
                }
            }
            return(requestUrl);
        }
        private static string objectJSONValue(object o)
        {
            StringBuilder buffer = new StringBuilder();

            if (o is List <object> )
            {
                List <object> lst = (List <object>)o;
                buffer.Append("[");
                for (int i = 0; i < lst.Count; i++)
                {
                    buffer.Append(objectJSONValue(lst[i]));
                    if (i + 1 < lst.Count)
                    {
                        buffer.Append(",");
                    }
                }
                buffer.Append("]");
            }
            else if (o is Dictionary <object, object> )
            {
                Dictionary <object, object> m = (Dictionary <object, object>)o;
                buffer.Append(getDictionaryToJson(m));
            }
            else if (o is int ||
                     o is Double ||
                     o is double ||
                     o is Boolean ||
                     o is bool ||
                     o is long ||
                     o is float)
            {
                buffer.Append(o);
            }
            else if (o is string)
            {
                buffer.Append("\"").Append(o).Append("\"");
            }
            else
            {
                Dictionary <object, object> objMap = QSParamInvokeUtil.getRequestParams(o, "");
                buffer.Append(getDictionaryToJson(objMap));
            }
            return(buffer.ToString());
        }