You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

82 lines
3.5 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.Text;
  8. using System.Text.Json;
  9. using System.Threading.Tasks;
  10. namespace JT808.Gateway.WebApiClientTool
  11. {
  12. public class JT808HttpClient
  13. {
  14. //todo:其余接口待接入
  15. public HttpClient HttpClient { get; }
  16. public JT808HttpClient(HttpClient httpClient)
  17. {
  18. HttpClient = httpClient;
  19. }
  20. /// <summary>
  21. /// 会话服务集合
  22. /// </summary>
  23. /// <returns></returns>
  24. public async ValueTask<JT808ResultDto<List<JT808TcpSessionInfoDto>>> GetTcpSessionAll()
  25. {
  26. var request = new HttpRequestMessage(HttpMethod.Get, JT808GatewayConstants.JT808WebApiRouteTable.SessionTcpGetAll);
  27. var response = HttpClient.SendAsync(request).Result;
  28. response.EnsureSuccessStatusCode();
  29. var data = await response.Content.ReadAsStreamAsync();
  30. var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<List<JT808TcpSessionInfoDto>>>(data);
  31. return value;
  32. }
  33. /// <summary>
  34. /// 会话服务-通过设备终端号移除对应会话
  35. /// </summary>
  36. /// <param name="terminalPhoneNo"></param>
  37. /// <returns></returns>
  38. public async ValueTask<JT808ResultDto<bool>> RemoveByTerminalPhoneNo(string terminalPhoneNo)
  39. {
  40. var request = new HttpRequestMessage(HttpMethod.Post, JT808GatewayConstants.JT808WebApiRouteTable.SessionRemoveByTerminalPhoneNo);
  41. request.Content = new StringContent(terminalPhoneNo);
  42. var response = HttpClient.SendAsync(request).Result;
  43. response.EnsureSuccessStatusCode();
  44. var data = await response.Content.ReadAsStreamAsync();
  45. var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<bool>>(data);
  46. return value;
  47. }
  48. /// <summary>
  49. /// 统一下发信息
  50. /// </summary>
  51. /// <param name="jT808UnificationSendRequestDto"></param>
  52. /// <returns></returns>
  53. public async ValueTask<JT808ResultDto<bool>> UnificationSend(JT808UnificationSendRequestDto jT808UnificationSendRequestDto)
  54. {
  55. var request = new HttpRequestMessage(HttpMethod.Post, JT808GatewayConstants.JT808WebApiRouteTable.UnificationSend);
  56. request.Content = new StringContent(JsonSerializer.Serialize(jT808UnificationSendRequestDto));
  57. var response = HttpClient.SendAsync(request).Result;
  58. response.EnsureSuccessStatusCode();
  59. var data = await response.Content.ReadAsStreamAsync();
  60. var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<bool>>(data);
  61. return value;
  62. }
  63. /// <summary>
  64. /// 会话服务集合
  65. /// </summary>
  66. /// <returns></returns>
  67. public async ValueTask<JT808ResultDto<List<JT808UdpSessionInfoDto>>> GetUdpSessionAll()
  68. {
  69. var request = new HttpRequestMessage(HttpMethod.Get, JT808GatewayConstants.JT808WebApiRouteTable.SessionUdpGetAll);
  70. var response = HttpClient.SendAsync(request).Result;
  71. response.EnsureSuccessStatusCode();
  72. var data = await response.Content.ReadAsStreamAsync();
  73. var value = await JsonSerializer.DeserializeAsync<JT808ResultDto<List<JT808UdpSessionInfoDto>>>(data);
  74. return value;
  75. }
  76. }
  77. }