瀏覽代碼

change all auth to local auth

Robert 1 年之前
父節點
當前提交
34fc38f1b4
共有 1 個文件被更改,包括 65 次插入2 次删除
  1. 65 2
      EVCB_OCPP.WSServer/Service/OuterBusinessService.cs

+ 65 - 2
EVCB_OCPP.WSServer/Service/OuterBusinessService.cs

@@ -2,6 +2,7 @@
 using EVCB_OCPP.Packet.Messages.SubTypes;
 using EVCB_OCPP.WSServer.Dto;
 using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
@@ -10,6 +11,7 @@ using NLog;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Net;
 using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer.Service
@@ -49,10 +51,11 @@ namespace EVCB_OCPP.WSServer.Service
     }
     public class OuterBusinessService : IBusinessService
     {
-
+        private readonly IConfiguration configuration;
         private readonly ILogger<OuterBusinessService> logger;
         private readonly IDbContextFactory<MainDBContext> maindbContextFactory;
         private readonly IMainDbService mainDbService;
+        private readonly HttpClientService service;
         private readonly OuterHttpClient httpClient;
 
         private string _CustomerId = string.Empty;
@@ -79,19 +82,79 @@ namespace EVCB_OCPP.WSServer.Service
         }
 
         public OuterBusinessService(
+            IConfiguration configuration,
             ILogger<OuterBusinessService> logger,
             IDbContextFactory<MainDBContext> maindbContextFactory,
             IMainDbService mainDbService,
+            HttpClientService service,
             OuterHttpClient httpClient)
         {
+            this.configuration = configuration;
             this.logger = logger;
             this.maindbContextFactory = maindbContextFactory;
             this.mainDbService = mainDbService;
+            this.service = service;
             this.httpClient = httpClient;
         }
 
-
         async public Task<IdTokenInfo> Authorize(string chargeBoxId, string idTag, int? connectorId = null)
+        {
+            await Task.Delay(10);
+            IdTokenInfo info = new IdTokenInfo() { IdTagInfo = new IdTagInfo() { status = AuthorizationStatus.Invalid } };
+
+            try
+            {
+                if (CustomerId.ToUpper() == "009E603C-79CD-4620-A2B8-D9349C0E8AD8")
+                {
+                    info.IdTagInfo = new IdTagInfo() { status = AuthorizationStatus.Accepted };
+                    return info;
+                }
+
+
+                //OuterHttpClient _client = new OuterHttpClient();
+
+
+                string url = configuration["LocalAuthAPI"];
+
+
+                //HttpClientService service = new HttpClientService();
+
+                Dictionary<string, string> postData = new Dictionary<string, string>()
+                {
+                  { "ChargeBoxId", chargeBoxId },
+                  { "IdTag", idTag },
+
+
+                };
+                var _innerresult = await service.PostFormDataAsync(url, postData, null);
+
+
+                if (_innerresult.StatusCode == HttpStatusCode.OK)
+                {
+                    JObject jo = JObject.Parse(_innerresult.Response);
+                    if (jo["code"].ToString() == "1")
+                    {
+                        try
+                        {
+                            info.IdTagInfo.status = (AuthorizationStatus)Enum.Parse(typeof(AuthorizationStatus), jo["message"].ToString());
+                        }
+                        catch (Exception)
+                        {
+                            ;
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                ;
+            }
+            return info;
+
+        }
+
+
+        async public Task<IdTokenInfo> Authorize_outer(string chargeBoxId, string idTag, int? connectorId = null)
         {
             //return new IdTokenInfo() { IdTagInfo = new IdTagInfo()
             //{