static void Main(string[] args) { //直销 HttpClient httpClient = new HttpClient(); string strFrom = GetTimeStamp(DateTime.UtcNow.AddHours(-72)); string strTo = GetTimeStamp(DateTime.UtcNow); string url = $"12345?appName=12345&from={strFrom}&to={strTo}&agentId=&env=1"; var task = httpClient.GetStringAsync(url); task.Wait(); string str = task.Result; Welcome[] r1 = Welcome.FromJson(str); StringBuilder strBuilder = null; if (r1 != null && r1.Any() && r1.First().Result.Any()) { strBuilder = new StringBuilder(); strBuilder.Append($"Web请求,访问量{Environment.NewLine}"); foreach (var item in r1.First().Result) { strBuilder.Append($"{item.DestId},{item.Count}{Environment.NewLine}"); } } if (strBuilder != null) { System.IO.File.WriteAllText("d:\\SOA线上直销还在被调用的列表.txt", strBuilder.ToString()); } //分销 url = $"12345?appName=hotel.12345&from={strFrom}&to={strTo}&agentId=&env=1"; var task1 = httpClient.GetStringAsync(url); task1.Wait(); r1 = Welcome.FromJson(task1.Result); if (r1 != null && r1.Any() && r1.First().Result.Any()) { if (strBuilder == null) { strBuilder = new StringBuilder(); } else { strBuilder.Clear(); } strBuilder.Append($"Web请求,访问量{Environment.NewLine}"); foreach (var item in r1.First().Result) { strBuilder.Append($"{item.DestId},{item.Count}{Environment.NewLine}"); } } if (strBuilder != null) { System.IO.File.WriteAllText("d:\\SOA线上分销还在被调用的列表.txt", strBuilder.ToString()); } }
static void Main(string[] args) { using (HttpClient hc12 = new HttpClient()) { //hc.DefaultRequestHeaders.Add("Content-type", "application/x-www-form-urlencoded; charset=utf-8"); //hc.DefaultRequestHeaders.Add("Connection", "Close"); var nvc = new List <KeyValuePair <string, string> >(); nvc.Add(new KeyValuePair <string, string>("uid", "240000000539259828")); nvc.Add(new KeyValuePair <string, string>("gorderId", "65946222")); var client = new HttpClient(); var req = new HttpRequestMessage(HttpMethod.Post, "xxxxxx/GetShortLink") { Content = new FormUrlEncodedContent(nvc) }; var sendTask = hc12.SendAsync(req); sendTask.Wait(); var res = sendTask.Result.Content.ReadAsStringAsync(); res.Wait(); JObject jobject = JsonConvert.DeserializeObject <JObject>(res.Result); if (jobject != null) { if (jobject["msg"]?.ToString() == "success") { string teset1 = jobject["shortLink"]?.ToString(); } } } DateTime begin = DateTime.Now.AddHours(-72); DateTime end = DateTime.Now; var handler = new HttpClientHandler() { UseCookies = true }; handler.CookieContainer = new CookieContainer(); handler.CookieContainer.Add(new Cookie() { Name = "userJob1NO", Value = "12345", Domain = "xxxxxx" }); handler.CookieContainer.Add(new Cookie() { Name = "userNam2e", Value = "%E5%94%90%E4%BC%9F%E4%BC%9F", Domain = "xxxxxx" }); handler.CookieContainer.Add(new Cookie() { Name = "userTok3en", Value = "92add0a4ee8", Domain = "xxxxxx" }); HttpClient hc = new HttpClient(handler); //hc.DefaultRequestHeaders.Add("Accept", "application/*+xml;version=5.1"); var handler1 = new HttpClientHandler() { UseCookies = true }; HttpClient hc1 = new HttpClient(handler1); handler1.CookieContainer = new CookieContainer(); handler1.CookieContainer.Add(new Cookie() { Name = "__tctma", Value = "1527748740333.6", Domain = "xxxxxxxxxx" }); handler1.CookieContainer.Add(new Cookie() { Name = "access_token", Value = "54ae269", Domain = "xxxxxxx" }); handler1.CookieContainer.Add(new Cookie() { Name = "state", Value = "78e46bd2b8", Domain = "xxxxxxx" }); StringBuilder sb = new StringBuilder(); sb.Append($"方法名,调用次数,上级调用,产品线,应用名,责任人,运维负责人{Environment.NewLine}"); foreach (var item in zhixiao1) { var param = Newtonsoft.Json.JsonConvert.SerializeObject( new { agentId = "", appName = "test12345", entryPoint = item.DestId, env = 1, from = GetTimeStamp(begin), to = GetTimeStamp(end) }); HttpContent contentPost = new StringContent(param, Encoding.UTF8, "application/json"); var result = hc.PostAsync("xxxxxxxxxxxxxxxxxxx", contentPost).Result; var res1 = result.Content.ReadAsStringAsync().Result; Welcome[] r1 = Welcome.FromJson(res1); if (r1 != null && r1.Any() && r1.First().Result.Any()) { foreach (var item1 in r1.First().Result) { if (item1.DestId != "USER") { var res = hc1.GetStringAsync($"xxxxxxxxxxxxxxxxxxxxxxxxxxxxx").Result; dynamic res1234 = JsonConvert.DeserializeObject <JObject>(res); if (res1234.result.rows == 0) { sb.Append($"{item.DestId},{item.Count},{item1.DestId},,,,{Environment.NewLine}"); } else if (res1234.result.rows == 1) { sb.Append($"{item.DestId},{item.Count},{item1.DestId},{res1234.result.list[0].productLineName},{res1234.result.list[0].aChname},{res1234.result.list[0].aLinkMan},{res1234.result.list[0].aOpsMaintenanceName}{Environment.NewLine}"); } //筛选出多个的情况 else { int j = Convert.ToInt32(res1234.result.rows); for (int i = 0; i < j; i++) { if (res1234.result.list[i].aUk == item1.DestId) { sb.Append($"{item.DestId},{item.Count},{item1.DestId},{res1234.result.list[i].productLineName},{res1234.result.list[i].aChname},{res1234.result.list[i].aLinkMan},{res1234.result.list[i].aOpsMaintenanceName}{Environment.NewLine}"); } } } } } } else { sb.Append($"{item.DestId},{item.Count},,,,,{Environment.NewLine}"); } } System.IO.File.WriteAllText($"d:\\被调用的列表4.txt", sb.ToString()); }