ApiResponse.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Newtonsoft.Json;
  7. namespace cuidian.OpenApi.Utils
  8. {
  9. public abstract class ApiResponse
  10. {
  11. public ApiResponse(Http.Response resp)
  12. {
  13. this.Response = resp;
  14. }
  15. [JsonIgnore]
  16. Http.Response Response { get; set; }
  17. /// <summary>
  18. /// 错误码
  19. /// </summary>
  20. [JsonProperty("errcode")]
  21. public string ErrCode { get; set; }
  22. /// <summary>
  23. /// 错误信息
  24. /// </summary>
  25. [JsonProperty("errmsg")]
  26. public string ErrMsg { get; set; }
  27. /// <summary>
  28. /// 响应原始内容
  29. /// </summary>
  30. [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  31. public string HttpBodyString { get; set; }
  32. /// <summary>
  33. /// 交易号
  34. /// </summary>
  35. [JsonProperty("tradeid", NullValueHandling = NullValueHandling.Ignore)]
  36. public string TradeId { get; set; }
  37. /// <summary>
  38. /// 新增资源返回的id
  39. /// </summary>
  40. [JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)]
  41. public string Id { get; set; }
  42. /// <summary>
  43. /// 批量查询(batch_get)返回的页号
  44. /// </summary>
  45. [JsonProperty("page_index", NullValueHandling = NullValueHandling.Ignore)]
  46. public int? PageIndex { get; set; }
  47. /// <summary>
  48. /// 批量查询(batch_get)返回的总行数
  49. /// </summary>
  50. [JsonProperty("row_count", NullValueHandling = NullValueHandling.Ignore)]
  51. public int? RowCount { get; set; }
  52. /// <summary>
  53. /// 批量查询(batch_get)返回的每页行数
  54. /// </summary>
  55. [JsonProperty("rows_per_page", NullValueHandling = NullValueHandling.Ignore)]
  56. public int? RowsPerPage { get; set; }
  57. /// <summary>
  58. /// 批量查询(batch_get)返回的页数
  59. /// </summary>
  60. [JsonProperty("page_count", NullValueHandling = NullValueHandling.Ignore)]
  61. public int? PageCount { get; set; }
  62. /// <summary>
  63. /// HTTP 原生响应
  64. /// </summary>
  65. [JsonIgnore]
  66. public string NativeResponseString { get; set; }
  67. /// <summary>
  68. /// 响应结果是否错误
  69. /// </summary>
  70. [JsonIgnore]
  71. public bool IsError
  72. {
  73. get
  74. {
  75. if (string.IsNullOrEmpty(this.ErrCode))
  76. this.ErrCode = "0";
  77. return !this.ErrCode.Equals("0");
  78. }
  79. }
  80. }
  81. }