PBPostManifestJob.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Quartz;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Http;
  7. using System.Net.Http.Headers;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace XYY.Tool.TimingTask.jobs
  11. {
  12. public class PBPostManifestJob : IJob
  13. {
  14. public async Task Execute(IJobExecutionContext context)
  15. {
  16. System.Threading.Thread.Sleep(10 * 1000);
  17. HttpClient client = new HttpClient();
  18. HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, XYY.Tool.QuotaReduction.JobConfig.PBPostManifestAction);
  19. requestMessage.Headers.Add("Authorization", "token 985833DB91DA7B38C3918D3F1F9D2339");
  20. requestMessage.Content = new StringContent("{}");
  21. requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
  22. try
  23. {
  24. var response = client.Send(requestMessage);
  25. if (response.IsSuccessStatusCode)
  26. {
  27. dingApiRequest.sendDingMessageToChat("PBPostManifestJob-PB预报", null);
  28. Console.WriteLine($"{DateTime.Now}预报成功");
  29. }
  30. else
  31. {
  32. string message = await response.Content.ReadAsStringAsync();
  33. dingApiRequest.sendDingMessageToChat("PBPostManifestJob-PB预报", message.Trim());
  34. }
  35. //Console.WriteLine(message);
  36. }
  37. catch (WebException ex)
  38. {
  39. //错误消息
  40. string errorMessage = new System.IO.StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
  41. dingApiRequest.sendDingMessageToChat("PBPostManifestJob-PB预报", errorMessage.Trim());
  42. }
  43. }
  44. }
  45. }