Ejemplo n.º 1
0
 public Push_Tags(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.PUSH_TAGS;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 2
0
 public Report_Statistic_Topic(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.REPORT_STATISTIC_TOPIC;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 3
0
 public Report_Statistic_Device(string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = Baidu_Helper.HTTP_POST;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.REPORT_STATISTIC_DEVICE;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 4
0
 public App_Del_Tag(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.APP_CREATE_TAG;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 5
0
 public Tag_Device_Num(string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = Baidu_Helper.HTTP_POST;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.TAG_DEVICE_NUM;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 6
0
 public App_Del_Tag(string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = Baidu_Helper.HTTP_POST;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.APP_DEL_TAG;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 7
0
 public Push_All(string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = Baidu_Helper.HTTP_POST;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.PUSH_ALL;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 8
0
 public App_Query_Tags(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.APP_QUERY_TAGS;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 9
0
 public Tag_Del_Devices(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.TAG_DEL_DEVICES;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 10
0
 public Timer_Cancel(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.TIMER_CANCEL;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 11
0
 public Report_Statistic_Msg(string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = Baidu_Helper.HTTP_POST;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.REPORT_STATISTIC_MSG;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 12
0
 public Report_Statistic_Topic(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.REPORT_STATISTIC_TOPIC;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 13
0
 public App_Del_Tag(string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = Baidu_Helper.HTTP_POST;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.APP_DEL_TAG;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 14
0
 public Tag_Add_Devices(string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = Baidu_Helper.HTTP_POST;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.TAG_ADD_DEVICES;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 15
0
 public App_Query_Tags(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.APP_QUERY_TAGS;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
 public Report_Query_Topic_Records(string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = Baidu_Helper.HTTP_POST;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.REPORT_QUERY_TOPIC_RECORDS;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 17
0
 public Push_Tags(string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = Baidu_Helper.HTTP_POST;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.PUSH_TAGS;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 18
0
 public Push_Batch_Device(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.PUSH_BATCH_DEVICE;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 19
0
 public App_Create_Tag(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.APP_CREATE_TAG;
     this.secret_key = secret_key;
     this.mod = mod;
 }
 public Report_Query_Timer_Records(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.REPORT_QUERY_TIMER_RECORDS;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 21
0
 public Push_All(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.PUSH_ALL;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 22
0
 public Timer_Cancel(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.TIMER_CANCEL;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 23
0
 public Push_Batch_Device(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.PUSH_BATCH_DEVICE;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 24
0
 public Report_Query_Msg_Status(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.REPORT_QUERY_MSG_STATUS;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 25
0
 public Report_Query_Timer_Records(string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = Baidu_Helper.HTTP_POST;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.REPORT_QUERY_TIMER_RECORDS;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 26
0
 public Timer_Query_List(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.TIMER_QUERY_LIST;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 27
0
 public Report_Query_Msg_Status(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.REPORT_QUERY_MSG_STATUS;
     this.secret_key = secret_key;
     this.mod = mod;
 }
 public Report_Query_Topic_Records(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.REPORT_QUERY_TOPIC_RECORDS;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 29
0
 public Tag_Del_Devices(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.TAG_DEL_DEVICES;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 30
0
 public Timer_Query_List(string httpMehtod, string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = httpMehtod;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.TIMER_QUERY_LIST;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 31
0
 public Push_Single_Device(string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = Baidu_Helper.HTTP_POST;
     this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.PUSH_SIGNLE_DEVICE;
     //this.url = "http://channel.api.duapp.com/rest/2.0/channel/channel" + Baidu_Helper.PUSH_SIGNLE_DEVICE;
     this.secret_key = secret_key;
     this.mod = mod;
 }
Ejemplo n.º 32
0
 public Push_Single_Device(string secret_key, Baidu_Mod mod)
 {
     this.httpMehtod = Baidu_Helper.HTTP_POST;
     this.url        = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.PUSH_SIGNLE_DEVICE;
     //this.url = "http://channel.api.duapp.com/rest/2.0/channel/channel" + Baidu_Helper.PUSH_SIGNLE_DEVICE;
     this.secret_key = secret_key;
     this.mod        = mod;
 }
Ejemplo n.º 33
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;
        }
Ejemplo n.º 34
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);
        }
Ejemplo n.º 35
0
        public static async Task<string> SendBaidu(string httpMethod, string url, string secretKey, Baidu_Mod mod)
        {
            //获取签名
            string strSign = CreateSign(httpMethod, url, secretKey, mod);

            string responseContent = "";                //返回字符串

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(url);                                                                                  //设置WebAPI的地址+类+方法
                client.DefaultRequestHeaders.Accept.Clear();                                                                        //清空缓存  
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json") { CharSet = "utf-8" });  //返回值为json和utf-8编码

                //响应消息
                HttpResponseMessage response = null;

                //判断使用不同的HttpMethod,生成不同的参数,获取相关返回数据
                if (HttpMethod.Get.Method.ToLower().Equals(httpMethod.ToLower())) //get方法(暂不提供)
                {

                }
                else if (HttpMethod.Post.Method.ToLower().Equals(httpMethod.ToLower()))                             //post方法
                {
                    //生成post的参数,并且设置charset为utf-8
                    Dictionary<string, string> requestDictionary = GetParamerCollection(mod, strSign);
                    var contents = new FormUrlEncodedContent(requestDictionary);
                    contents.Headers.ContentType.CharSet = "utf-8";
                    await contents.LoadIntoBufferAsync();
                    try
                    {
                        response = await client.PostAsync(url, contents);

                        //返回值
                        responseContent = await response.Content.ReadAsStringAsync();
                    }
                    catch (WebException ex)
                    {
                        Stream stream = ex.Response.GetResponseStream();
                        string m = ex.Response.Headers.ToString();
                        byte[] buf = new byte[256];
                        stream.Read(buf, 0, 256);
                        stream.Close();
                        int count = 0;
                        foreach (var b in buf)
                        {
                            if (b > 0)
                            {
                                count++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        responseContent = "Post:" + url + ex.Message + "\r\n\r\n" + Encoding.UTF8.GetString(buf, 0, count);
                    }
                }



            }

            return responseContent;

        }
Ejemplo n.º 36
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);
        }
Ejemplo n.º 37
0
        public static String SendBaiduTest(string httpMethod, string url, string secretKey, Baidu_Mod mod)
        {
            //获取签名
            string strSign = CreateSign(httpMethod, url, secretKey, mod);

            string responseContent = "";                //返回字符串

            using (var webClient = new WebClient())
            {
                try
                {
                    webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");


                    byte[] data = Encoding.UTF8.GetBytes(GetParamerCollection(mod, strSign).ToString()); //编码,尤其是汉字,事先要看下抓取网页的编码方式

                    byte[] responseData = webClient.UploadData(url, "POST", data);                       //得到返回字符流

                    responseContent = Encoding.UTF8.GetString(responseData);                             //解码
                }
                catch (WebException ex)
                {
                    Stream stream = ex.Response.GetResponseStream();
                    string m      = ex.Response.Headers.ToString();
                    byte[] buf    = new byte[256];
                    stream.Read(buf, 0, 256);
                    stream.Close();
                    int count = 0;
                    foreach (var b in buf)
                    {
                        if (b > 0)
                        {
                            count++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    responseContent = "Post:" + url + ex.Message + "\r\n\r\n" + Encoding.UTF8.GetString(buf, 0, count);
                }
            }
            return(responseContent);
        }
Ejemplo n.º 38
0
        public static async Task <string> SendBaidu(string httpMethod, string url, string secretKey, Baidu_Mod mod)
        {
            //获取签名
            string strSign = CreateSign(httpMethod, url, secretKey, mod);

            string responseContent = "";                //返回字符串

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(url);                                                                                  //设置WebAPI的地址+类+方法
                client.DefaultRequestHeaders.Accept.Clear();                                                                        //清空缓存
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")
                {
                    CharSet = "utf-8"
                });                                                                                                                      //返回值为json和utf-8编码

                //响应消息
                HttpResponseMessage response = null;

                //判断使用不同的HttpMethod,生成不同的参数,获取相关返回数据
                if (HttpMethod.Get.Method.ToLower().Equals(httpMethod.ToLower())) //get方法(暂不提供)
                {
                }
                else if (HttpMethod.Post.Method.ToLower().Equals(httpMethod.ToLower()))                             //post方法
                {
                    //生成post的参数,并且设置charset为utf-8
                    Dictionary <string, string> requestDictionary = GetParamerCollection(mod, strSign);
                    var contents = new FormUrlEncodedContent(requestDictionary);
                    contents.Headers.ContentType.CharSet = "utf-8";
                    await contents.LoadIntoBufferAsync();

                    try
                    {
                        response = await client.PostAsync(url, contents);

                        //返回值
                        responseContent = await response.Content.ReadAsStringAsync();
                    }
                    catch (WebException ex)
                    {
                        Stream stream = ex.Response.GetResponseStream();
                        string m      = ex.Response.Headers.ToString();
                        byte[] buf    = new byte[256];
                        stream.Read(buf, 0, 256);
                        stream.Close();
                        int count = 0;
                        foreach (var b in buf)
                        {
                            if (b > 0)
                            {
                                count++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        responseContent = "Post:" + url + ex.Message + "\r\n\r\n" + Encoding.UTF8.GetString(buf, 0, count);
                    }
                }
            }

            return(responseContent);
        }
Ejemplo n.º 39
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;

        }
Ejemplo n.º 40
0
        public static String SendBaiduTest(string httpMethod, string url, string secretKey, Baidu_Mod mod)
        {
            //获取签名
            string strSign = CreateSign(httpMethod, url, secretKey, mod);

            string responseContent = "";                //返回字符串

            using (var webClient = new WebClient())
            {
                try
                {
                    webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");


                    byte[] data = Encoding.UTF8.GetBytes(GetParamerCollection(mod, strSign).ToString());//编码,尤其是汉字,事先要看下抓取网页的编码方式  

                    byte[] responseData = webClient.UploadData(url, "POST", data);//得到返回字符流  

                    responseContent = Encoding.UTF8.GetString(responseData);//解码  

                }
                catch (WebException ex)
                {
                    Stream stream = ex.Response.GetResponseStream();
                    string m = ex.Response.Headers.ToString();
                    byte[] buf = new byte[256];
                    stream.Read(buf, 0, 256);
                    stream.Close();
                    int count = 0;
                    foreach (var b in buf)
                    {
                        if (b > 0)
                        {
                            count++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    responseContent = "Post:" + url + ex.Message + "\r\n\r\n" + Encoding.UTF8.GetString(buf, 0, count);
                }
            }
            return responseContent;

        }