Ejemplo n.º 1
0
        /// <summary>
        /// 转换参数
        /// </summary>
        /// <param name="method_name"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        internal DNTParam[] Sign(string method_name, DNTParam[] parameters)
        {
            ArrayList list = new ArrayList();

            list.Add(DNTParam.Create("method", method_name));
            list.Add(DNTParam.Create("api_key", api_key));
            list.Add(VersionParam);
            list.Sort();

            StringBuilder values = new StringBuilder();

            foreach (DNTParam param in list)
            {
                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(DNTParam.Create("sig", sig_builder.ToString()));

            return((DNTParam[])list.ToArray());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据参数和密码生成签名字符串
        /// </summary>
        /// <param name="parameters">API参数</param>
        /// <param name="secret">密码</param>
        /// <returns>签名字符串</returns>
        private string GetSignature(DNTParam[] parameters, string secret)
        {
            StringBuilder values = new StringBuilder();

            foreach (DNTParam param in parameters)
            {
                if (param.Name == "sig" || string.IsNullOrEmpty(param.Value))
                    continue;
                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"));

            return sig_builder.ToString();
        }