public static string generateQSURL(Dictionary <object, object> parameters, string requestUrl)
        {
            parameters = ParamInvokeUtil.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(StringUtil.percentEncode(key, Constant.ENCODING_UTF8))
                    .Append("=")
                    .Append(StringUtil.percentEncode(parameters[key].ToString(), Constant.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);
        }
Exemple #2
0
        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 = ParamInvokeUtil.getRequestParams(o, "");
                buffer.Append(getDictionaryToJson(objMap));
            }
            return(buffer.ToString());
        }
        public static String getExpireAuth(Dictionary <object, object> context, int expiresSecond, RequestInputModel Params)
        {
            Config Config = (Config)context[Constant.CONFIG_CONTEXT_KEY];

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

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

            string method = (string)context[Constant.PARAM_KEY_REQUEST_METHOD];

            string requestPath = Config.getHost() + Config.getUri();
            string authSign    = getSignature(
                Config.getAccessKey(),
                Config.getAccessSecret(),
                method,
                requestPath,
                paramsQuery,
                paramsHeaders);

            return(HttpUtility.UrlEncode(authSign, Encoding.GetEncoding(Constant.ENCODING_UTF8)));
        }