[BGService][WebApi]將obix帳密寫死的地方改成DB撈

This commit is contained in:
張家睿 2024-10-25 17:47:38 +08:00
parent db77070dd3
commit b97828ca6a
4 changed files with 23 additions and 10 deletions

View File

@ -1,6 +1,7 @@
using FrontendWebApi.Models; using FrontendWebApi.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Quartz; using Quartz;
using Repository.BackendRepository.Implement;
using Repository.BackendRepository.Interface; using Repository.BackendRepository.Interface;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -52,8 +53,10 @@ namespace BackendWorkerService.Quartz.Jobs
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{ {
string username = "stanGG"; var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'";
string password = "St12345678"; var variableObix = backendRepository.GetAllAsync<KeyValue>(sqlObix).Result;
string username = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault();
string password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded); client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded);

View File

@ -42,8 +42,11 @@ namespace BackendWorkerService.Quartz.Jobs
{ {
try try
{ {
string username = "stanGG"; var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'";
string password = "St12345678";
var variableObix = backgroundServiceRepository.GetAllAsync<KeyValue>(sqlObix).Result;
string username = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault();
string password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
HttpWebRequest Postrequest = (HttpWebRequest)WebRequest.Create(url); HttpWebRequest Postrequest = (HttpWebRequest)WebRequest.Create(url);
Postrequest.Method = "POST"; Postrequest.Method = "POST";

View File

@ -61,8 +61,10 @@ namespace FrontendWebApi.ApiControllers
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{ {
string username = "stanGG"; var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'";
string password = "St12345678"; var variableObix = frontendRepository.GetAllAsync<KeyValue>(sqlObix).Result;
string username = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault();
string password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded); client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded);

View File

@ -6,6 +6,7 @@ using Newtonsoft.Json;
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel; using NPOI.XSSF.UserModel;
using Repository.BackendRepository.Implement; using Repository.BackendRepository.Implement;
using Repository.BackendRepository.Interface;
using Repository.FrontendRepository.Interface; using Repository.FrontendRepository.Interface;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -82,8 +83,10 @@ namespace FrontendWebApi.ApiControllers
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{ {
apiUrl = Path.Combine(baseApiUrl, "obix/config/", apiUrl); apiUrl = Path.Combine(baseApiUrl, "obix/config/", apiUrl);
string username = "stanGG"; var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'";
string password = "St12345678"; var variableObix = frontendRepository.GetAllAsync<KeyValue>(sqlObix).Result;
string username = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault();
string password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded); client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded);
@ -165,8 +168,10 @@ namespace FrontendWebApi.ApiControllers
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{ {
apiUrl = Path.Combine(baseApiUrl, "obix/config/", apiUrl); apiUrl = Path.Combine(baseApiUrl, "obix/config/", apiUrl);
string username = "stanGG"; var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'";
string password = "St12345678"; var variableObix = frontendRepository.GetAllAsync<KeyValue>(sqlObix).Result;
string username = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault();
string password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault();
string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded); client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded);