/// <summary>
        /// 获取签名
        /// </summary>
        /// <param name="url">网址</param>
        /// <param name="apiKeyInfo">取用的Api密钥</param>
        /// <returns></returns>
        public static string GetSign(string url, ApiKeyInfo apiKeyInfo = null)
        {
            if (apiKeyInfo == null)
            {
                apiKeyInfo = AndroidKey;
            }
            string result;

            if (url.StartsWith("http"))
            {
                url.Substring(url.IndexOf("?", 4) + 1);
            }
            List <string> list = url.Split('&').ToList();

            list.Sort();
            StringBuilder stringBuilder = new StringBuilder();

            foreach (string str1 in list)
            {
                stringBuilder.Append((stringBuilder.Length > 0 ? "&" : string.Empty));
                stringBuilder.Append(str1);
            }
            stringBuilder.Append(apiKeyInfo.Secret);
            result = MD5Tool.GetMd5String(stringBuilder.ToString()).ToLower();
            return(result);
        }
Exemplo n.º 2
0
        public static string GetMd5String(string source)
        {
            MD5Tool md = Create();

            byte[]        bytes   = new UTF8Encoding().GetBytes(source);
            byte[]        buffer2 = md.ComputeHash(bytes);
            StringBuilder builder = new StringBuilder();

            foreach (byte num in buffer2)
            {
                builder.Append(((byte)num).ToString("x2"));
            }
            return(builder.ToString());
        }