LocalBusinessService.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using EVCB_OCPP.Packet.Messages.SubTypes;
  9. using EVCB_OCPP.WSServer.Dto;
  10. using Newtonsoft.Json.Linq;
  11. namespace EVCB_OCPP.WSServer.Service
  12. {
  13. public class LocalBusinessService : IBusinessService
  14. {
  15. string customerId = string.Empty;
  16. public LocalBusinessService(string customerId)
  17. {
  18. this.customerId = customerId;
  19. }
  20. async public Task<IdTagInfo> Authorize(string chargeBoxId, string idTag)
  21. {
  22. await Task.Delay(10);
  23. IdTagInfo info = new IdTagInfo() { status = AuthorizationStatus.Invalid };
  24. try
  25. {
  26. OuterHttpClient _client = new OuterHttpClient();
  27. string url = ConfigurationManager.AppSettings["LocalAuthAPI"];
  28. HttpClientService service = new HttpClientService();
  29. Dictionary<string, string> postData = new Dictionary<string, string>()
  30. {
  31. { "ChargeBoxId", chargeBoxId },
  32. { "IdTag", idTag },
  33. };
  34. var _innerresult = await service.PostFormDataAsync(url, postData, null);
  35. if (_innerresult.StatusCode == HttpStatusCode.OK)
  36. {
  37. JObject jo = JObject.Parse(_innerresult.Response);
  38. if (jo["code"].ToString() == "1")
  39. {
  40. try
  41. {
  42. info.status = (AuthorizationStatus)Enum.Parse(typeof(AuthorizationStatus), jo["message"].ToString());
  43. }
  44. catch(Exception)
  45. {
  46. ;
  47. }
  48. }
  49. }
  50. }
  51. catch (Exception ex)
  52. {
  53. ;
  54. }
  55. return info;
  56. }
  57. async public Task NotifyFaultStatus(ErrorDetails details)
  58. {
  59. await Task.Delay(10);
  60. }
  61. }
  62. }