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; }
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; }
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; }
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; }
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; }
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; }
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; }
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 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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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_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; }
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; }
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; }
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; }
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; }
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); }
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; }
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); }
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); }
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); }
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; }
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; }