当你的才华不能撑起你的野心时,就是你该选择学习的时候了!

.Net C# 签名字符串排序

#region Get Sign Content
        /// <summary>
        /// Get Sign Content
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private string GetSignContent(IDictionary<string, string> parameters)
        {
            // 第一步:把字典按Key的字母顺序排序
            IDictionary<string, string> sortedParams = new SortedDictionary<string, string>(parameters);
            IEnumerator<KeyValuePair<string, string>> dem = sortedParams.GetEnumerator();

            // 第二步:把所有参数名和参数值串在一起
            StringBuilder query = new StringBuilder("");
            while (dem.MoveNext())
            {
                string key = dem.Current.Key;
                string value = dem.Current.Value;
                if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
                {
                    query.Append(key).Append("=").Append(value).Append("&");
                }
            }
            string content = query.ToString().Substring(0, query.Length - 1);

            return content;
        }
        #endregion
                IDictionary<string, string> dics = new Dictionary<string, string>();
                dics.Add("dynamicCode", request.DynamicCode);
                dics.Add("accessToken", request.AccessToken);
                dics.Add("cardNo", request.CardNo);
                dics.Add("cerNo", request.CerNo);
                dics.Add("cardPhone", request.CardPhone);

                //Sensitive Domain Encryption 
                string snsDataString = GetSignContent(dics);

 

posted @ 2019-08-02 11:14  hofmann  阅读(1456)  评论(0编辑  收藏  举报