OrderMailSendJob.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Newtonsoft.Json;
  2. using Quartz;
  3. using RestSharp;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using XYY.Tool.QuotaReduction;
  10. using XYY.Tool.TimingTask.Model;
  11. namespace XYY.Tool.TimingTask.jobs
  12. {
  13. public class OrderMailSendJob : IJob
  14. {
  15. public Task Execute(IJobExecutionContext context)
  16. {
  17. string msg = string.Empty;
  18. var client = new RestClient(JobConfig.OrderMailSendApi);
  19. client.Timeout = -1;
  20. var request = new RestRequest(Method.POST);
  21. request.AddHeader("Authorization", "token 57AEDE5487260443D6BF2182D31286B1");
  22. request.AddHeader("Content-Type", "application/json");
  23. IRestResponse response = client.Execute(request);
  24. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  25. {
  26. var result = JsonConvert.DeserializeObject<ApiJsonModel>(response.Content);
  27. if (result.success == true)
  28. {
  29. msg = "订单邮件发送任务执行成功";
  30. }
  31. }
  32. else
  33. {
  34. msg += "订单邮件发送任务接口调用异常!" + response.ErrorMessage ?? response.Content;
  35. }
  36. if (msg.Contains("异常")) { dingApiRequest.sendDingMessageToChat("OrderMailSendApi", msg); }
  37. return null;
  38. }
  39. }
  40. public class OrderSingMailAddJob : IJob
  41. {
  42. public Task Execute(IJobExecutionContext context)
  43. {
  44. string msg = string.Empty;
  45. var client = new RestClient(JobConfig.OrderSingMailAddApi);
  46. client.Timeout = -1;
  47. var request = new RestRequest(Method.POST);
  48. request.AddHeader("Authorization", "token 57AEDE5487260443D6BF2182D31286B1");
  49. request.AddHeader("Content-Type", "application/json");
  50. IRestResponse response = client.Execute(request);
  51. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  52. {
  53. var result = JsonConvert.DeserializeObject<ApiJsonModel>(response.Content);
  54. if (result.success == true)
  55. {
  56. msg = "签收邮件添加任务,执行成功";
  57. }
  58. }
  59. else
  60. {
  61. msg += "签收邮件添加任务,接口调用异常!" + response.ErrorMessage ?? response.Content;
  62. }
  63. //无论成功失败,都发送
  64. dingApiRequest.sendDingMessageToChat("OrderSingMailAddApi", msg);
  65. return null;
  66. }
  67. }
  68. }