예제 #1
0
        /// <summary>
        /// 拼装api参数
        /// </summary>
        /// <param name="urlParanms">url参数</param>
        /// <param name="sign">签名</param>
        /// <returns></returns>
        private ParameterCollection GetUrlParmCollection(string sign)
        {
            ParameterCollection ps = new ParameterCollection();

            Dictionary <string, string> .Enumerator i = UrlParams.GetEnumerator();
            while (i.MoveNext())
            {
                ps.Add(i.Current.Key, i.Current.Value);
            }
            if (!string.IsNullOrEmpty(sign))
            {
                ps.Add("_aop_signature", sign);
            }
            return(ps);
        }
예제 #2
0
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="infor"></param>
        /// <param name="funname"></param>
        /// <param name="parms"></param>
        /// <returns></returns>
        private string GetSignature()
        {
            string        p1 = Secret.ApiParmUrl + FunName + "/" + Secret.AppKey;
            List <string> p2 = new List <string>();

            Dictionary <string, string> .Enumerator itemator = UrlParams.GetEnumerator();
            while (itemator.MoveNext())
            {
                p2.Add(itemator.Current.Key + itemator.Current.Value);
            }
            //排序
            p2.Sort(delegate(string a, string b)
            {
                int i;
                for (i = 0; i < a.Length; i++)
                {
                    if (i >= b.Length)
                    {
                        return(1);              //a比b长
                    }
                    if (a[i] < b[i])
                    {
                        return(-1);
                    }
                    if (a[i] > b[i])
                    {
                        return(1);
                    }
                }
                if (i < b.Length)
                { //a比b短
                    return(-1);
                }
                return(0);
            });

            p2.ForEach(delegate(string item) { p1 += item; });

            byte[]   signatureKey = Encoding.UTF8.GetBytes(Secret.AppSecret);
            HMACSHA1 hmacsha1     = new HMACSHA1(signatureKey);

            hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(p1));
            byte[] hash = hmacsha1.Hash;
            return(BitConverter.ToString(hash).Replace("-", string.Empty).ToUpper());
        }