예제 #1
0
        /// <summary>
        /// 生成阿里云URL
        /// </summary>
        /// <param name="request">请求参数</param>
        /// <returns>生成的URL</returns>
        public static string GeneralURL(AliyunRequest request)
        {
            //第一步、创建请求参数
            SortedDictionary <string, string> _parameters = new SortedDictionary <string, string>(StringComparer.Ordinal); //区分大小写排序,这个问题开始卡我半天

            _parameters.Add("Timestamp", DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"));
            _parameters.Add("SignatureNonce", _makeNonceAliyun());

            Dictionary <string, string> _params = request.GeneralParameters();

            if (_params != null)
            {
                foreach (KeyValuePair <string, string> param in _params)
                {
                    _parameters.Add(param.Key, param.Value);
                }
            }

            string q         = _httpBuildQuery(_parameters);
            string Signature = _makeSignAliyun(request, _parameters);
            string url       = q + "&Signature=" + Signature;

            //第二步、生成请求URL
            url = AliyunRequest.Base_Url + "?" + url;
            return(url);
        }
예제 #2
0
        private static string _makeSignAliyun(AliyunRequest request, SortedDictionary <String, String> parameters)
        {
            //第一步、使用请求参数构造规范化的请求字符串
            string q = _httpBuildQuery(parameters);

            //第二步:使用上一步构造的规范化字符串按照下面的规则构造用于计算签名的字符串。
            string StringToSign = request.Http_Method.ToString() + "&%2F&" + _urlEncodeX(q);

            //第三步、按照RFC2104的定义,使用上面的用于签名的字符串计算签名HMAC值。
            string Signature = _hmacSha1Sign(StringToSign, request.Access_Key_Secret + "&");

            Signature = _urlEncodeX(Signature);
            return(Signature);
        }
예제 #3
0
        /// <summary>
        /// 获取阿里云响应
        /// </summary>
        /// <param name="request">请求参数</param>
        /// <returns>阿里云响应</returns>
        public static AliyunResponse GetResponse(AliyunRequest request)
        {
            string             url  = GeneralURL(request);
            string             html = Utils.GetUrlHtmlContentBySocket(url, request.Http_Method);
            AliyunHtmlResponse resp = GetHtmlResponse(html, request.Format);

            if (resp.StatusCode == System.Net.HttpStatusCode.OK)
            {
                AliyunResponse iresp = _analyzeResponse(request.Action, request.Format, resp.Content);
                return(iresp);
            }
            else
            {
                return(resp.ErrorMessage);
            }
        }
예제 #4
0
 /// <summary>
 /// 初始化请求
 /// </summary>
 /// <param name="AliyunRequest">请求</param>
 public static void Init(AliyunRequest AliyunRequest)
 {
     AliyunUtils.AliyunRequest = AliyunRequest;
 }