StandaloneChina.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Threading.Tasks;
  2. using System.Net.Http.Headers;
  3. using System.Net.Http;
  4. using LC.Newtonsoft.Json;
  5. using TapTap.AntiAddiction.Model;
  6. using TapTap.Common.Internal.Json;
  7. namespace TapTap.AntiAddiction.Internal
  8. {
  9. internal class StandaloneChina
  10. {
  11. static readonly string ANTI_ADDICTION_SETTINGS_URL = "https://tds-public-config-sh.oss-cn-shanghai.aliyuncs.com/antiaddiction-settings.json";
  12. static StandaloneResponse current;
  13. static HttpClient client;
  14. private static HttpClient HttpClient
  15. {
  16. get
  17. {
  18. if (client == null)
  19. {
  20. client = new HttpClient();
  21. client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  22. }
  23. return client;
  24. }
  25. }
  26. internal static async Task<bool> Enabled()
  27. {
  28. if (current != null)
  29. {
  30. return current.Enabled;
  31. }
  32. HttpResponseMessage response = await HttpClient.GetAsync(ANTI_ADDICTION_SETTINGS_URL);
  33. string resultString = await response.Content.ReadAsStringAsync();
  34. response.Dispose();
  35. current = JsonConvert.DeserializeObject<StandaloneResponse>(resultString, TapJsonConverter.Default);
  36. return current != null && current.Enabled;
  37. }
  38. }
  39. }