Exemplo n.º 1
0
        public static readonly string REPORT_STATISTIC_TOPIC     = "report/statistic_topic";        //查询分类主题统计信息
        #endregion


        #region 获取签名
        private static string CreateSign(string httpMethod, string url, string secretKey, Baidu_Mod mod)
        {
            string sign = "";

            if (mod != null)
            {
                Dictionary <string, string> dic = new Dictionary <string, string>();

                //将键值对按照key的升级排列
                var    props  = mod.GetType().GetProperties().OrderBy(p => p.Name);
                string pValue = "";
                foreach (var p in props)
                {
                    if (p.GetValue(mod, null) != null)
                    {
                        pValue = p.GetValue(mod, null).ToString();
                        if (pValue != "0")//unint为0是不添加,如广播消息的预定发送时间
                        {
                            dic.Add(p.Name, p.GetValue(mod, null).ToString());
                        }
                    }
                }
                //生成sign时,不能包含sign标签,所有移除
                dic.Remove("sign");

                var preData = new StringBuilder();
                foreach (var l in dic)
                {
                    preData.Append(l.Key);
                    preData.Append("=");
                    preData.Append(l.Value);
                }

                //按要求拼接字符串,并urlencode编码
                var str = HttpUtility.UrlEncode(httpMethod.ToUpper() + url + preData.ToString() + secretKey);

                var strSignUpper = new StringBuilder();
                int perIndex     = 0;
                for (int i = 0; i < str.Length; i++)
                {
                    var c = str[i].ToString();
                    if (str[i] == '%')
                    {
                        perIndex = i;
                    }
                    if (i - perIndex == 1 || i - perIndex == 2)
                    {
                        c = c.ToUpper();
                    }
                    strSignUpper.Append(c);
                }

                // 获取sign的值
                sign = Tool.Md5Hash(strSignUpper.ToString()).ToLower();
            }
            return(sign);
        }
Exemplo n.º 2
0
        private static Dictionary <string, string> GetParamerCollection(Baidu_Mod mod, string sign)
        {
            Dictionary <string, string> paramerCollection = new Dictionary <string, string>();

            var    props  = mod.GetType().GetProperties();
            string pValue = "";

            foreach (var p in props)
            {
                if (p.GetValue(mod, null) != null)
                {
                    pValue = p.GetValue(mod, null).ToString();
                    if (pValue != "0")//unint为0是不添加,如广播消息的预定发送时间
                    {
                        paramerCollection.Add(p.Name, p.GetValue(mod, null).ToString());
                    }
                }
            }


            paramerCollection.Add("sign", sign);

            return(paramerCollection);
        }
Exemplo n.º 3
0
        public static readonly string REPORT_STATISTIC_TOPIC = "report/statistic_topic";            //查询分类主题统计信息
        #endregion


        #region 获取签名
        private static string CreateSign(string httpMethod, string url, string secretKey, Baidu_Mod mod)
        {
            string sign = "";
            if (mod != null)
            {
                Dictionary<string, string> dic = new Dictionary<string, string>();

                //将键值对按照key的升级排列
                var props = mod.GetType().GetProperties().OrderBy(p => p.Name);
                string pValue = "";
                foreach (var p in props)
                {
                    if (p.GetValue(mod, null) != null)
                    {
                        pValue = p.GetValue(mod, null).ToString();
                        if (pValue != "0")//unint为0是不添加,如广播消息的预定发送时间
                            dic.Add(p.Name, p.GetValue(mod, null).ToString());
                    }
                }
                //生成sign时,不能包含sign标签,所有移除
                dic.Remove("sign");

                var preData = new StringBuilder();
                foreach (var l in dic)
                {
                    preData.Append(l.Key);
                    preData.Append("=");
                    preData.Append(l.Value);

                }

                //按要求拼接字符串,并urlencode编码
                var str = HttpUtility.UrlEncode(httpMethod.ToUpper() + url + preData.ToString() + secretKey);

                var strSignUpper = new StringBuilder();
                int perIndex = 0;
                for (int i = 0; i < str.Length; i++)
                {
                    var c = str[i].ToString();
                    if (str[i] == '%')
                    {
                        perIndex = i;
                    }
                    if (i - perIndex == 1 || i - perIndex == 2)
                    {
                        c = c.ToUpper();
                    }
                    strSignUpper.Append(c);
                }

                // 获取sign的值
                sign = Tool.Md5Hash(strSignUpper.ToString()).ToLower();

            }
            return sign;
        }
Exemplo n.º 4
0
        private static Dictionary<string, string> GetParamerCollection(Baidu_Mod mod, string sign)
        {
            Dictionary<string, string> paramerCollection = new Dictionary<string, string>();

            var props = mod.GetType().GetProperties();
            string pValue = "";
            foreach (var p in props)
            {
                if (p.GetValue(mod, null) != null)
                {
                    pValue = p.GetValue(mod, null).ToString();
                    if (pValue != "0")//unint为0是不添加,如广播消息的预定发送时间
                        paramerCollection.Add(p.Name, p.GetValue(mod, null).ToString());
                }
            }


            paramerCollection.Add("sign", sign);

            return paramerCollection;

        }