コード例 #1
0
        /// <summary>
        /// 将参数绑定到url
        /// </summary>
        /// <param name="apiUrl"></param>
        /// <param name="secret"></param>
        /// <param name="action"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private static string GetUrl(string apiUrl, string secret, string action, UrlParam[] parameters)
        {
            List <UrlParam> list = new List <UrlParam>(parameters);

            list.Add(UrlParam.Create("time", Time()));
            list.Add(UrlParam.Create("action", action));
            list.Sort();
            StringBuilder values = new StringBuilder();

            foreach (UrlParam param in list)
            {
                if (!string.IsNullOrEmpty(param.Value))
                {
                    values.Append(param.ToString());
                }
            }
            values.Append(secret);
            byte[]        md5_result  = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(values.ToString()));
            StringBuilder sig_builder = new StringBuilder();

            foreach (byte b in md5_result)
            {
                sig_builder.Append(b.ToString("x2"));
            }
            list.Add(UrlParam.Create("sig", sig_builder.ToString()));
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < list.Count; i++)
            {
                if (i > 0)
                {
                    builder.Append("&");
                }
                builder.Append(list[i].ToEncodedString());
            }
            return(string.Format("{0}?{1}", apiUrl, builder.ToString()));
        }
コード例 #2
0
ファイル: UrlParam.cs プロジェクト: pczy/Pub.Class
 /// <summary>
 /// 将参数绑定到url
 /// </summary>
 /// <param name="apiUrl"></param>
 /// <param name="secret"></param>
 /// <param name="action"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 private static string GetUrl(string apiUrl, string secret, string action, UrlParam[] parameters) {
     List<UrlParam> list = new List<UrlParam>(parameters);
     list.Add(UrlParam.Create("time", Time()));
     list.Add(UrlParam.Create("action", action));
     list.Sort();
     StringBuilder values = new StringBuilder();
     foreach (UrlParam param in list) {
         if (!string.IsNullOrEmpty(param.Value)) values.Append(param.ToString());
     }
     values.Append(secret);
     byte[] md5_result = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(values.ToString()));
     StringBuilder sig_builder = new StringBuilder();
     foreach (byte b in md5_result) sig_builder.Append(b.ToString("x2"));
     list.Add(UrlParam.Create("sig", sig_builder.ToString()));
     StringBuilder builder = new StringBuilder();
     for (int i = 0; i < list.Count; i++) {
         if (i > 0) builder.Append("&");
         builder.Append(list[i].ToEncodedString());
     }
     return string.Format("{0}?{1}", apiUrl, builder.ToString());
 }