BaseTopRequest.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Top.Api
  4. {
  5. /// <summary>
  6. /// 基础TOP请求类,存放一些通用的请求参数。
  7. /// </summary>
  8. public abstract class BaseTopRequest<T> : ITopRequest<T> where T : TopResponse
  9. {
  10. /// <summary>
  11. /// HTTP请求URL参数
  12. /// </summary>
  13. internal TopDictionary otherParams;
  14. /// <summary>
  15. /// HTTP请求头参数
  16. /// </summary>
  17. private TopDictionary headerParams;
  18. /// <summary>
  19. /// 请求目标AppKey
  20. /// </summary>
  21. private string targetAppKey;
  22. /// <summary>
  23. /// 批量API请求的用户授权码
  24. /// </summary>
  25. private string batchApiSession;
  26. /// <summary>
  27. /// API在批量调用中的顺序
  28. /// </summary>
  29. private int batchApiOrder;
  30. public void AddOtherParameter(string key, string value)
  31. {
  32. if (this.otherParams == null)
  33. {
  34. this.otherParams = new TopDictionary();
  35. }
  36. this.otherParams.Add(key, value);
  37. }
  38. public void AddHeaderParameter(string key, string value)
  39. {
  40. GetHeaderParameters().Add(key, value);
  41. }
  42. public IDictionary<string, string> GetHeaderParameters()
  43. {
  44. if (this.headerParams == null)
  45. {
  46. this.headerParams = new TopDictionary();
  47. }
  48. return this.headerParams;
  49. }
  50. public string GetTargetAppKey()
  51. {
  52. return this.targetAppKey;
  53. }
  54. public void SetTargetAppKey(string targetAppKey)
  55. {
  56. this.targetAppKey = targetAppKey;
  57. }
  58. public string GetBatchApiSession()
  59. {
  60. return this.batchApiSession;
  61. }
  62. public void SetBatchApiSession(string session)
  63. {
  64. this.batchApiSession = session;
  65. }
  66. public int GetBatchApiOrder()
  67. {
  68. return this.batchApiOrder;
  69. }
  70. public void SetBatchApiOrder(int order)
  71. {
  72. this.batchApiOrder = order;
  73. }
  74. public abstract string GetApiName();
  75. public abstract void Validate();
  76. public abstract IDictionary<string, string> GetParameters();
  77. }
  78. }