Exemple #1
0
        private static Dictionary <String, String> InitialBasicHeader(Dictionary <String, String> headers, String appKey, String appSecret, String method, String requestAddress, Dictionary <String, String> formParam, List <String> signHeaderPrefixList)
        {
            if (headers == null)
            {
                headers = new Dictionary <String, String>();
            }

            Uri           uri           = new Uri(requestAddress);
            StringBuilder stringBuilder = new StringBuilder();

            if (!String.IsNullOrEmpty(uri.LocalPath) && !"/".Equals(uri.LocalPath))
            {
                stringBuilder.Append(uri.LocalPath);
            }

            if (!String.IsNullOrEmpty(uri.Query))
            {
                //stringBuilder.Append("?");
                stringBuilder.Append(uri.Query);
            }

            //headers.Add(HttpHeader.HTTP_HEADER_USER_AGENT, Constants.USER_AGENT);
            headers.Add(SystemHeader.X_CA_TIMESTAMP, DateUtil.ConvertDateTimeInt(DateTime.Now).ToString());
            headers.Add(SystemHeader.X_CA_NONCE, Guid.NewGuid().ToString());
            headers.Add(SystemHeader.X_CA_KEY, appKey);
            headers.Add(SystemHeader.X_CA_SIGNATURE, SignUtil.Sign(method, stringBuilder.ToString(), appSecret, headers, formParam, signHeaderPrefixList));

            return(headers);
        }
        private static Dictionary <String, String> InitialBasicHeader(String path, String appKey, String appSecret, String method, Dictionary <String, String> headers, Dictionary <String, String> querys, Dictionary <String, String> bodys, List <String> signHeaderPrefixList)
        {
            if (headers == null)
            {
                headers = new Dictionary <String, String>();
            }

            StringBuilder sb = new StringBuilder();

            //时间戳
            headers.Add(SystemHeader.X_CA_TIMESTAMP, DateUtil.ConvertDateTimeInt(DateTime.Now).ToString());
            //防重放,协议层不能进行重试,否则会报NONCE被使用;如果需要协议层重试,请注释此行
            headers.Add(SystemHeader.X_CA_NONCE, Guid.NewGuid().ToString());
            headers.Add(SystemHeader.X_CA_KEY, appKey);
            headers.Add(SystemHeader.X_CA_SIGNATURE, SignUtil.Sign(path, method, appSecret, headers, querys, bodys, signHeaderPrefixList));

            return(headers);
        }