FuelSurchargeJob.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 FuelSurchargeJob : IJob
  14. {
  15. public Task Execute(IJobExecutionContext context)
  16. {
  17. string msg = string.Empty;
  18. //发起两次请求
  19. var client = new RestClient(JobConfig.FedexSurchargesSyncApi);
  20. client.Timeout = -1;
  21. var request = new RestRequest(Method.GET);
  22. IRestResponse response = client.Execute(request);
  23. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  24. {
  25. var result = JsonConvert.DeserializeObject<ApiJsonModel>(response.Content);
  26. Tuple<bool, string> tuple = JsonConvert.DeserializeObject<Tuple<bool, string>>(result.data.ToString());
  27. msg = tuple.Item2;
  28. }
  29. else
  30. {
  31. msg += "fedex燃油费同步接口调用失败!";
  32. }
  33. string msg2 = string.Empty;
  34. var client2 = new RestClient(JobConfig.DHLSurchargesSyncApi);
  35. client2.Timeout = -1;
  36. var request2 = new RestRequest(Method.GET);
  37. IRestResponse response2 = client2.Execute(request2);
  38. if (response2.StatusCode == System.Net.HttpStatusCode.OK)
  39. {
  40. var result = JsonConvert.DeserializeObject<ApiJsonModel>(response2.Content);
  41. Tuple<bool, string> tuple = JsonConvert.DeserializeObject<Tuple<bool, string>>(result.data.ToString());
  42. msg2 = tuple.Item2;
  43. }
  44. else
  45. {
  46. msg2 += "dhl燃油费同步接口调用失败!";
  47. }
  48. //string msg = "调用服务";string msg2 = "服务2";
  49. dingApiRequest.sendMessageToWeChat("FedexSurchargesSyncApi", msg,new List<string>() { "LiuZhengKai","33", "fanlihang" });
  50. dingApiRequest.sendMessageToWeChat("DHLSurchargesSyncApi", msg2, new List<string>() { "LiuZhengKai","33", "fanlihang" });
  51. Console.WriteLine("燃油附加费任务已执行,请注意查看钉钉消息");
  52. return null;
  53. }
  54. }
  55. }