Exemplo n.º 1
0
        private static int timeOut    = 10000;//设置连接超时时间,默认10秒,用户可以根据具体需求适当更改timeOut的值

        public static void GetParams(SortedDictionary <string, object> requestParams, string secretId, string secretKey,
                                     string requestMethod, string requestHost, string requestPath)
        {
            requestParams.Add("SecretId", secretId);
            Random rand = new Random();

            requestParams.Add("Nonce", rand.Next(Int32.MaxValue).ToString());
            DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
            DateTime nowTime   = DateTime.Now;
            long     unixTime  = (long)Math.Round((nowTime - startTime).TotalMilliseconds, MidpointRounding.AwayFromZero);

            requestParams.Add("Timestamp", (unixTime / 1000).ToString());
            requestParams.Add("RequestClient", VERSION);
            string plainText       = Sign.MakeSignPlainText(requestParams, requestMethod, requestHost, requestPath);
            string SignatureMethod = "HmacSHA1";

            if (requestParams.ContainsKey("SignatureMethod") && requestParams["SignatureMethod"] == "HmacSHA256")
            {
                SignatureMethod = "HmacSHA256";
            }
            string sign = Sign.Signature(plainText, secretKey, SignatureMethod);

            requestParams.Add("Signature", sign);
        }