Ejemplo n.º 1
0
        public static string ToSign(Dictionary <string, string> dic, string appsecret)
        {
            if (dic == null)
            {
                return("");
            }

            IOrderedEnumerable <KeyValuePair <string, string> > _newdic = dic.OrderBy(x => x.Key);

            StringBuilder sb = new StringBuilder();

            foreach (var f in _newdic)
            {
                if (f.Key == "sign")
                {
                    continue;
                }
                sb.Append(f.Key + "=" + f.Value + "&");
            }
            if (sb.Length > 0)
            {
                sb.Append("&appsecret=" + appsecret);
            }
            else
            {
                sb.Append("appsecret=" + appsecret);
            }
            string si = Authcomm.ToMD5String(sb.ToString());

            return(si);
        }
Ejemplo n.º 2
0
        public static void ToSign(List <ParmField> para, string appsecret)
        {
            if (para == null)
            {
                para = new List <ParmField>();
                //   para.Add(new StringField("timespan",GetTimeSpan().ToString()));
            }
            IOrderedEnumerable <ParmField> _newpara = para.OrderBy((a) => { return(a.Key); });
            StringBuilder sb = new StringBuilder();

            foreach (ParmField f in _newpara)
            {
                if (f.GetType() == typeof(StringField))
                {
                    sb.Append(f.Key + "=" + f.Value + "&");
                }
            }
            if (sb.Length > 0)
            {
                sb.Append("&appsecret=" + appsecret);
            }
            else
            {
                sb.Append("appsecret=" + appsecret);
            }
            string si = Authcomm.ToMD5String(sb.ToString());

            para.Add(new StringField("sign", si));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// all StringField will be signed and will add timespan,appid,appsecret; appid、appsecret from web.config or app.config
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        public static void DefaultSignProvider(List <ParmField> para)
        {
            if (para == null)
            {
                para = new List <ParmField>();
            }
            para.Add(new StringField("timespan", Authcomm.GetTimeSpan()));
            para.Add(new StringField("appid", Authcomm.GetAppConfig("appid")));
            string        appsecret = Authcomm.GetAppConfig("appsecret");
            StringBuilder sb        = new StringBuilder();

            foreach (ParmField f in para)
            {
                if (string.IsNullOrEmpty(f.Value))
                {
                    continue;
                }
                if (f.GetType() == typeof(StringField))
                {
                    sb.Append(f.Key.Trim() + "=" + f.Value.Trim() + "&");
                }
            }
            sb.Append("appsecret=" + appsecret);
            string sign = Authcomm.ToMD5String(sb.ToString());

            para.Add(new StringField("sign", sign));
        }