AbstractTopApiClient.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System.Net;
  2. using Topsdk.Util;
  3. namespace Topsdk.Top;
  4. public abstract class AbstractTopApiClient:ITopApiClient
  5. {
  6. protected string appkey = "";
  7. protected string appSecret = "";
  8. protected string serverUrl = "";
  9. protected string format = "json";
  10. protected string signMethod = "hmac-sha256";
  11. protected long connectTimeOut = 15000L;
  12. protected long totalTimeout = 30000L;
  13. protected string version = "2.0";
  14. protected bool simplify = true;
  15. protected bool enableLogger = true;
  16. protected bool ignoreSsl = true;
  17. protected IWebProxy? proxy;
  18. /// <summary>
  19. /// 初始化sdk
  20. /// </summary>
  21. public abstract void Init();
  22. /// <summary>
  23. /// 请求api,包含sessionKey
  24. /// </summary>
  25. /// <param name="apiCode"></param>
  26. /// <param name="requestMap"></param>
  27. /// <param name="fileMap"></param>
  28. /// <param name="session"></param>
  29. /// <returns></returns>
  30. public abstract string Execute(string apiCode,IDictionary<string,string> requestMap, IDictionary<string,TopFileItem> fileMap, string session);
  31. /// <summary>
  32. /// 请求api
  33. /// </summary>
  34. /// <param name="apiCode"></param>
  35. /// <param name="requestMap"></param>
  36. /// <param name="fileMap"></param>
  37. /// <returns></returns>
  38. public abstract string Execute(string apiCode,IDictionary<string,string> requestMap, IDictionary<string,TopFileItem> fileMap);
  39. public IDictionary<string, string> GetSystemParam()
  40. {
  41. IDictionary<string, string> systemParam = new Dictionary<string, string>();
  42. systemParam.Add(Constants.APP_KEY,this.appkey);
  43. systemParam.Add(Constants.TIMESTAMP,DateTime.Now.ToString(Constants.DATE_TIME_FORMAT));
  44. systemParam.Add(Constants.VERSION,this.version);
  45. systemParam.Add(Constants.SIGN_METHOD,this.signMethod);
  46. systemParam.Add(Constants.FORMAT,this.format);
  47. systemParam.Add(Constants.SIMPLIFY,simplify.ToString().ToLower());
  48. systemParam.Add(Constants.PARTNER_ID,Constants.SDK_VERSION);
  49. return systemParam;
  50. }
  51. public IDictionary<string, string> GetHeaderParam()
  52. {
  53. IDictionary<string, string> headerParam = new Dictionary<string, string>();
  54. return headerParam;
  55. }
  56. public string Appkey
  57. {
  58. get => appkey;
  59. set => appkey = value ?? throw new ArgumentNullException(nameof(value));
  60. }
  61. public string AppSecret
  62. {
  63. get => appSecret;
  64. set => appSecret = value ?? throw new ArgumentNullException(nameof(value));
  65. }
  66. public string ServerUrl
  67. {
  68. get => serverUrl;
  69. set => serverUrl = value ?? throw new ArgumentNullException(nameof(value));
  70. }
  71. public string Format
  72. {
  73. get => format;
  74. set => format = value ?? throw new ArgumentNullException(nameof(value));
  75. }
  76. public string SignMethod
  77. {
  78. get => signMethod;
  79. set => signMethod = value ?? throw new ArgumentNullException(nameof(value));
  80. }
  81. public long ConnectTimeOut
  82. {
  83. get => connectTimeOut;
  84. set => connectTimeOut = value;
  85. }
  86. public long TotalTimeout
  87. {
  88. get => totalTimeout;
  89. set => totalTimeout = value;
  90. }
  91. public string Version
  92. {
  93. get => version;
  94. set => version = value ?? throw new ArgumentNullException(nameof(value));
  95. }
  96. public bool Simplify
  97. {
  98. get => simplify;
  99. set => simplify = value;
  100. }
  101. public bool EnableLogger
  102. {
  103. get => enableLogger;
  104. set => enableLogger = value;
  105. }
  106. public IWebProxy Proxy
  107. {
  108. get => proxy;
  109. set => proxy = value ?? throw new ArgumentNullException(nameof(value));
  110. }
  111. public bool IgnoreSsl
  112. {
  113. get => ignoreSsl;
  114. set => ignoreSsl = value;
  115. }
  116. }