using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Text; namespace GuangFu.StringTracing.Common { public class FbtApi { #region 获取分贝通Token public string GetToken() { string path = "https://openapi.fenbeitong.com/openapi/auth/getToken"; string result = string.Empty; string JsonData = "{\"app_id\":\"5d8c75e705e5eb37c0473e3e\",\"app_key\":\"696856bdb7c341062e6d9110\"}"; HttpContent httpContent = new StringContent(JsonData); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; var obj = JObject.Parse(result); string data = obj["data"]?.ToString(); return data; } else { return ""; } } } #endregion #region 查询国内城市信息 public string QueryDomesticCity(string Token,string JsonData) { string path = "https://openapi.fenbeitong.com/openapi/apply/v1/city_detail"; string result = string.Empty; HttpContent httpContent = new StringContent(JsonData); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("access-token", Token); //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; } } return result; } #endregion #region 查询国际国家信息 public string QueryInternationalCity(string Token) { string path = "https://openapi.fenbeitong.com/openapi/apply/v1/international_country_detail"; string result = string.Empty; HttpContent httpContent = new StringContent(""); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("access-token", Token); //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; } } return result; } #endregion #region 查询国际城市信息 public string QueryInternationalCityDetail(string Token, string JsonData) { string path = "https://openapi.fenbeitong.com/openapi/apply/v1/international_city_detail "; string result = string.Empty; HttpContent httpContent = new StringContent(JsonData); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("access-token", Token); //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; } } return result; } #endregion #region 获取机票订单列表 public string GetAirList(string Token, string JsonData) { string path = "https://openapi.fenbeitong.com/openapi/order/air/v2/list"; string result = string.Empty; HttpContent httpContent = new StringContent(JsonData); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("access-token", Token); //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; } } return result; } #endregion #region 获取机票订单详情 public string GetAirDetail(string Token, string JsonData) { string path = "https://openapi.fenbeitong.com/openapi/order/air/v2/detail"; string result = string.Empty; HttpContent httpContent = new StringContent(JsonData); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("access-token", Token); //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; } } return result; } #endregion #region 获取酒店订单列表 public string GetHotelList(string Token, string JsonData) { string path = "https://openapi.fenbeitong.com/openapi/order/hotel/v2/list"; string result = string.Empty; HttpContent httpContent = new StringContent(JsonData); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("access-token", Token); //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; } } return result; } #endregion #region 获取酒店订单详情 public string GetHotelDetail(string Token, string JsonData) { string path = "https://openapi.fenbeitong.com/openapi/order/hotel/v1/detail"; string result = string.Empty; HttpContent httpContent = new StringContent(JsonData); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("access-token", Token); //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; } } return result; } #endregion #region 获取火车订单列表 public string GetTrainList(string Token, string JsonData) { string path = "https://openapi.fenbeitong.com/openapi/order/train/v1/list"; string result = string.Empty; HttpContent httpContent = new StringContent(JsonData); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("access-token", Token); //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; } } return result; } #endregion #region 获取火车订单详情 public string GetTrainDetail(string Token, string JsonData) { string path = "https://openapi.fenbeitong.com/openapi/order/train/v1/detail"; string result = string.Empty; HttpContent httpContent = new StringContent(JsonData); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("access-token", Token); //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; } } return result; } #endregion #region 获取用车正向订单列表 public string GetTaxiList(string Token, string JsonData) { string path = "https://openapi.fenbeitong.com/openapi/order/taxi/v1/list"; string result = string.Empty; HttpContent httpContent = new StringContent(JsonData); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("access-token", Token); //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; } } return result; } #endregion #region 获取用车正向订单详情 public string GetTaxiDetail(string Token, string JsonData) { string path = "https://openapi.fenbeitong.com/openapi/order/taxi/v1/detail"; string result = string.Empty; HttpContent httpContent = new StringContent(JsonData); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("access-token", Token); //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; } } return result; } #endregion #region 变更申请单可用状态 public string UpdateApplyCustomTrip(string Token, string JsonData) { string path = "https://openapi.fenbeitong.com/openapi/apply/common/v1/update_available_state"; string result = string.Empty; HttpContent httpContent = new StringContent(JsonData); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("access-token", Token); //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; } } return result; } #endregion #region 新建自定义差旅申请单 public string CreateApplyCustomTrip(string Token, string JsonData) { string path = "https://openapi.fenbeitong.com/openapi/apply/custom_trip/v1/create"; string result = string.Empty; HttpContent httpContent = new StringContent(JsonData); //设置Http的内容标头 httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //设置Http的内容标头的字符 httpContent.Headers.ContentType.CharSet = "utf-8"; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("access-token", Token); //异步Post HttpResponseMessage response = httpClient.PostAsync(path, httpContent).Result; //确保Http响应成功 if (response.IsSuccessStatusCode) { //异步读取json result = response.Content.ReadAsStringAsync().Result; } } return result; } #endregion } #region 自定义变量 #endregion }