コード例 #1
0
        public static string Send(SortedDictionary <string, object> requestParams, string secretId, string secretKey, string requestMethod, String requestHost, String requestPath, String fileName)
        {
            if (!requestParams.ContainsKey("SecretId"))
            {
                requestParams["SecretId"] = secretId;
            }
            if (!requestParams.ContainsKey("Nonce"))
            {
                requestParams["Nonce"] = new Random().Next(Int32.MaxValue);
            }
            if (!requestParams.ContainsKey("Timestamp"))
            {
                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["RequestClient"] = VERSION;
            String plainText       = Sign.MakeSignPlainText(requestParams, requestMethod, requestHost, requestPath);
            string SignatureMethod = "HmacSHA1";

            if (requestParams.ContainsKey("SignatureMethod") && requestParams["SignatureMethod"] == "HmacSHA256")
            {
                SignatureMethod = "HmacSHA256";
            }
            requestParams["Signature"] = Sign.Signature(plainText, secretKey, SignatureMethod);
            string url = "https://" + requestHost + requestPath;

            return(SendRequest(url, requestParams, requestMethod, fileName));
        }
コード例 #2
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 sign      = Sign.Signature(plainText, secretKey);

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