ExchangeRateJob.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 ExchangeRateJob : IJob
  14. {
  15. public Task Execute(IJobExecutionContext context)
  16. {
  17. string msg = string.Empty;
  18. //发起两次请求
  19. var client = new RestClient(JobConfig.ExchangeRateSyncApi);
  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 += "中国银行汇率同步接口调用失败!";
  32. }
  33. dingApiRequest.sendDingMessageToChat("ExchangeRateSync", msg);
  34. return null;
  35. }
  36. }
  37. }