Exemplo n.º 1
0
        /// <summary>
        /// 获取api需要的后面的请求字符串
        /// </summary>
        /// <param name="AccessKeySecret"></param>
        /// <param name="parameter"></param>
        /// <param name="dictAPI"></param>
        /// <returns></returns>
        public string GetRFC3986Uri(string AccessKeyId, string AccessKeySecret, Dictionary <string, string> dictAPI)
        {
            CommonParameter parameter = GetCommonParameter();

            parameter.AccessKeyId = AccessKeyId;

            var StringToSign = GetStringToSign(parameter, dictAPI, "GET");
            var Signature    = GetSignature(StringToSign, AccessKeySecret + "&");

            parameter.Signature = Signature;

            var dicParameter = parameter.ToDictionary();
            var dict         = dicParameter.Concat(dictAPI).OrderBy(i => i.Key).ToDictionary(i => i.Key, item => item.Value);

            return(dict.ToNotNullKeyValueEncoderString("=", "&"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据公共参数、请求API参数和请求方法,获取GetSignature,用于获取Signature
        /// </summary>
        /// <param name="parameter">公共参数类</param>
        /// <param name="dictAPI">API请求参数类</param>
        /// <param name="HTTPMethod">请求方法</param>
        /// <returns></returns>
        public string GetStringToSign(CommonParameter parameter, Dictionary <string, string> dictAPI, string HTTPMethod)
        {
            var dicParameter = parameter.ToDictionary();
            var aaa          = dicParameter.Concat(dictAPI);
            //拼接并排序的胡字符串
            //var dict = dicParameter.Concat(dictAPI).OrderBy(i => i.Key ).ToDictionary(i => i.Key,item=>item.Value);
            var           dict = Common.AsciiDictionarySort(dicParameter.Concat(dictAPI).ToDictionary(i => i.Key, item => item.Value));
            var           CanonicalizedQueryString = dict.ToNotNullKeyValueEncoderString("=", "&");
            StringBuilder sb = new StringBuilder();

            sb.Append(HTTPMethod);
            sb.Append("&");
            sb.Append(Methods.Common.GetURLEncoder("/"));
            sb.Append("&");
            sb.Append(Methods.Common.GetURLEncoder(CanonicalizedQueryString));
            return(sb.ToString());
        }