Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

188 lignes
8.1 KiB

  1. using JT808.Gateway.Abstractions;
  2. using JT808.Gateway.Abstractions.Dtos;
  3. using System;
  4. using System.Buffers.Text;
  5. using System.Collections.Generic;
  6. using System.Net.Http;
  7. using System.Net.Http.Json;
  8. using System.Text;
  9. using System.Text.Json;
  10. using System.Threading.Tasks;
  11. namespace JT808.Gateway.WebApiClientTool
  12. {
  13. /// <summary>
  14. ///
  15. /// </summary>
  16. public class JT808HttpClient
  17. {
  18. /// <summary>
  19. ///
  20. /// </summary>
  21. public HttpClient HttpClient { get; }
  22. /// <summary>
  23. ///
  24. /// </summary>
  25. /// <param name="httpClient"></param>
  26. public JT808HttpClient(HttpClient httpClient)
  27. {
  28. HttpClient = httpClient;
  29. }
  30. /// <summary>
  31. /// 统一下发信息
  32. /// </summary>
  33. /// <param name="parameter"></param>
  34. /// <returns></returns>
  35. public async ValueTask<JT808ResultDto<bool>> UnificationSend(JT808UnificationSendRequestDto parameter)
  36. {
  37. var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.UnificationSend, parameter);
  38. response.EnsureSuccessStatusCode();
  39. var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<bool>>();
  40. return value;
  41. }
  42. /// <summary>
  43. /// 会话服务集合
  44. /// </summary>
  45. /// <returns></returns>
  46. public async ValueTask<JT808ResultDto<List<JT808TcpSessionInfoDto>>> GetTcpSessionAll()
  47. {
  48. var request = new HttpRequestMessage(HttpMethod.Get, JT808GatewayConstants.JT808WebApiRouteTable.SessionTcpGetAll);
  49. var response = await HttpClient.SendAsync(request);
  50. response.EnsureSuccessStatusCode();
  51. var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<List<JT808TcpSessionInfoDto>>>();
  52. return value;
  53. }
  54. /// <summary>
  55. /// 会话服务集合
  56. /// </summary>
  57. /// <returns></returns>
  58. public async ValueTask<JT808ResultDto<JT808PageResult<List<JT808TcpSessionInfoDto>>>> SessionTcpByPage(int pageIndex=0,int pageSize=10)
  59. {
  60. var request = new HttpRequestMessage(HttpMethod.Get, $"{JT808GatewayConstants.JT808WebApiRouteTable.SessionTcpByPage}?pageIndex={pageIndex}&pageSize={pageSize}");
  61. var response = await HttpClient.SendAsync(request);
  62. response.EnsureSuccessStatusCode();
  63. var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<JT808PageResult<List<JT808TcpSessionInfoDto>>>>();
  64. return value;
  65. }
  66. /// <summary>
  67. /// 会话服务-通过设备终端号查询对应会话信息
  68. /// </summary>
  69. /// <param name="parameter"></param>
  70. /// <returns></returns>
  71. public async ValueTask<JT808ResultDto<JT808TcpSessionInfoDto>> QueryTcpSessionByTerminalPhoneNo(JT808TerminalPhoneNoDto parameter)
  72. {
  73. var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.QueryTcpSessionByTerminalPhoneNo, parameter);
  74. response.EnsureSuccessStatusCode();
  75. var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<JT808TcpSessionInfoDto>>();
  76. return value;
  77. }
  78. /// <summary>
  79. /// 会话服务-通过设备终端号移除对应会话
  80. /// </summary>
  81. /// <param name="parameter"></param>
  82. /// <returns></returns>
  83. public async ValueTask<JT808ResultDto<bool>> RemoveTcpByTerminalPhoneNo(JT808TerminalPhoneNoDto parameter)
  84. {
  85. var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.SessionRemoveByTerminalPhoneNo, parameter);
  86. response.EnsureSuccessStatusCode();
  87. var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<bool>>();
  88. return value;
  89. }
  90. /// <summary>
  91. /// 会话服务集合
  92. /// </summary>
  93. /// <returns></returns>
  94. public async ValueTask<JT808ResultDto<List<JT808UdpSessionInfoDto>>> GetUdpSessionAll()
  95. {
  96. var response = await HttpClient.GetAsync(JT808GatewayConstants.JT808WebApiRouteTable.SessionUdpGetAll);
  97. response.EnsureSuccessStatusCode();
  98. var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<List<JT808UdpSessionInfoDto>>>();
  99. return value;
  100. }
  101. /// <summary>
  102. /// 会话服务集合
  103. /// </summary>
  104. /// <returns></returns>
  105. public async ValueTask<JT808ResultDto<JT808PageResult<List<JT808TcpSessionInfoDto>>>> SessionUdpByPage(int pageIndex = 0, int pageSize = 10)
  106. {
  107. var request = new HttpRequestMessage(HttpMethod.Get, $"{JT808GatewayConstants.JT808WebApiRouteTable.SessionUdpByPage}?pageIndex={pageIndex}&pageSize={pageSize}");
  108. var response = await HttpClient.SendAsync(request);
  109. response.EnsureSuccessStatusCode();
  110. var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<JT808PageResult<List<JT808TcpSessionInfoDto>>>>();
  111. return value;
  112. }
  113. /// <summary>
  114. /// 会话服务-通过设备终端号查询对应会话信息
  115. /// </summary>
  116. /// <param name="parameter"></param>
  117. /// <returns></returns>
  118. public async ValueTask<JT808ResultDto<JT808UdpSessionInfoDto>> QueryUdpSessionByTerminalPhoneNo(JT808TerminalPhoneNoDto parameter)
  119. {
  120. var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.QueryUdpSessionByTerminalPhoneNo, parameter);
  121. response.EnsureSuccessStatusCode();
  122. var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<JT808UdpSessionInfoDto>>();
  123. return value;
  124. }
  125. /// <summary>
  126. /// 会话服务-通过设备终端号移除对应会话
  127. /// </summary>
  128. /// <param name="parameter"></param>
  129. /// <returns></returns>
  130. public async ValueTask<JT808ResultDto<bool>> RemoveUdpByTerminalPhoneNo(JT808TerminalPhoneNoDto parameter)
  131. {
  132. var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.RemoveUdpByTerminalPhoneNo,parameter);
  133. response.EnsureSuccessStatusCode();
  134. var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<bool>>();
  135. return value;
  136. }
  137. /// <summary>
  138. /// SIM卡黑名单服务-将对应SIM号加入黑名单
  139. /// </summary>
  140. /// <param name="parameter"></param>
  141. /// <returns></returns>
  142. public async ValueTask<JT808ResultDto<bool>> BlacklistAdd(JT808TerminalPhoneNoDto parameter)
  143. {
  144. var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.BlacklistAdd, parameter);
  145. response.EnsureSuccessStatusCode();
  146. var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<bool>>();
  147. return value;
  148. }
  149. /// <summary>
  150. /// SIM卡黑名单服务-将对应SIM号移除黑名单
  151. /// </summary>
  152. /// <param name="parameter"></param>
  153. /// <returns></returns>
  154. public async ValueTask<JT808ResultDto<bool>> BlacklistRemove(JT808TerminalPhoneNoDto parameter)
  155. {
  156. var response = await HttpClient.PostAsJsonAsync(JT808GatewayConstants.JT808WebApiRouteTable.BlacklistRemove, parameter);
  157. response.EnsureSuccessStatusCode();
  158. var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<bool>>();
  159. return value;
  160. }
  161. /// <summary>
  162. /// SIM卡黑名单服务-获取所有sim的黑名单列表
  163. /// </summary>
  164. /// <returns></returns>
  165. public async ValueTask<JT808ResultDto<List<string>>> GetBlacklistAll()
  166. {
  167. var response = await HttpClient.GetAsync(JT808GatewayConstants.JT808WebApiRouteTable.BlacklistGet);
  168. response.EnsureSuccessStatusCode();
  169. var value = await response.Content.ReadFromJsonAsync<JT808ResultDto<List<string>>>();
  170. return value;
  171. }
  172. }
  173. }