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 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 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_Statistic_Msg(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_MSG; 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.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 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 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 Tag_Device_Num(string httpMehtod, string secret_key, Baidu_Mod mod) { this.httpMehtod = httpMehtod; this.url = "http://api.tuisong.baidu.com/rest/3.0/" + Baidu_Helper.TAG_DEVICE_NUM; 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 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_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 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 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 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 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 Push_Single_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_SIGNLE_DEVICE; this.secret_key = secret_key; this.mod = mod; }
public Push_Batch_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_BATCH_DEVICE; 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 Report_Statistic_Topic(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_TOPIC; 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 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 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 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 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); }
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 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 async Task <string> SendBaidu(string httpMethod, string url, string secretKey, Baidu_Mod mod) { //获取签名 string strSign = CreateSign(httpMethod, url, secretKey, mod); string responseContent = ""; //返回字符串 //使用本机代理fiddler进行测试 //var handler = new HttpClientHandler() //{ // Proxy = new WebProxy("http://127.0.0.1:8888", false, new string[] { }), // UseProxy = true //}; 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(); response = await client.PostAsync(url, contents); } //返回值 responseContent = await response.Content.ReadAsStringAsync(); }// http完结 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 = ""; //返回字符串 //使用本机代理fiddler进行测试 //var handler = new HttpClientHandler() //{ // Proxy = new WebProxy("http://127.0.0.1:8888", false, new string[] { }), // UseProxy = true //}; 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(); response = await client.PostAsync(url, contents); } //返回值 responseContent = await response.Content.ReadAsStringAsync(); }// http完结 return responseContent; }