Beispiel #1
0
        /// <summary>
        /// 是否支付平台签名,规则是:按参数名称a-z排序,遇到空值的参数不参加签名。
        /// </summary>
        /// <returns></returns>
        public virtual Boolean IsTenpaySign()
        {
            StringBuilder sb = new StringBuilder();

            List <string> akeys = Parameters.Keys.ToList();

            akeys.Sort();

            foreach (string k in akeys)
            {
                string v = (string)Parameters[k];
                if (null != v && String.Compare("", v, StringComparison.Ordinal) != 0 &&
                    String.Compare("sign", k, StringComparison.Ordinal) != 0 &&
                    String.Compare("key", k, StringComparison.Ordinal) != 0)
                {
                    sb.Append(k + "=" + v + "&");
                }
            }

            sb.Append("key=" + this.GetKey());
            var sign = Md5Util.GetMd5(sb.ToString(), GetCharset()).ToLower();

            //debug信息
            this.SetDebugInfo(sb.ToString() + " => sign:" + sign);
            return(GetParameter("sign").ToLower().Equals(sign));
        }
Beispiel #2
0
        private string CreateSign(IDictionary <string, string> dictionary, string key)
        {
            var sb    = new StringBuilder();
            var akeys = dictionary.Keys.ToList();

            akeys.Sort();
            foreach (string k in akeys)
            {
                var v = (string)dictionary[k];
                if (null != v && Compare("", v, StringComparison.Ordinal) != 0 &&
                    Compare("sign", k, StringComparison.Ordinal) != 0 &&
                    Compare("key", k, StringComparison.Ordinal) != 0)
                {
                    sb.Append(k + "=" + v + "&");
                }
            }
            sb.Append("key=" + key);
            var sign = Md5Util.GetMd5(sb.ToString(), dictionary["charset"].ToUpper());

            return(sign);
        }