fix sap-api凭证
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Text;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using Dlhis.ScheduledTask.SyncSapInfo.Dto;
|
||||
using Dlhis.ScheduledTask.SyncSapInfo.Response;
|
||||
using Dlhis.Sys.Api;
|
||||
@@ -8,22 +10,33 @@ namespace Dlhis.ScheduledTask.SyncSapInfo.Services.Implements;
|
||||
|
||||
public class JinkoSapService : IJinkoSapService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly ILogger<JinkoSapService> _logger;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly ITenantApi _tenantApi;
|
||||
|
||||
public JinkoSapService(IHttpClientFactory httpClientFactory, ILogger<JinkoSapService> logger, ITenantApi tenantApi)
|
||||
{
|
||||
_httpClient = httpClientFactory.CreateClient("jinko:sap");
|
||||
_logger = logger;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_tenantApi = tenantApi;
|
||||
}
|
||||
|
||||
private HttpClient GetHttpClient()
|
||||
{
|
||||
var httpClient = _httpClientFactory.CreateClient("jinko:sap");
|
||||
httpClient.Timeout = TimeSpan.FromMinutes(10);
|
||||
var credentials = string.Format("{0}:{1}", "EHS_USER", "y3R1hd2h*RICAC");
|
||||
var headerValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials));
|
||||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", headerValue);
|
||||
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
public async Task<SapOrganizationResponse> GetSapOrganizationsAsync()
|
||||
{
|
||||
string apiUrl = "http://sappidap.jinkosolar.cn:51000/RESTAdapter/Rest/EHR_ORGANIZATION/";
|
||||
|
||||
var response = await _httpClient.PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
|
||||
var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
string responseJson = await response.Content.ReadAsStringAsync();
|
||||
@@ -36,7 +49,7 @@ public class JinkoSapService : IJinkoSapService
|
||||
{
|
||||
string apiUrl = "http://sappidap.jinkosolar.cn:51000/RESTAdapter/Rest/EHR_POSITION/";
|
||||
|
||||
var response = await _httpClient.PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
|
||||
var response = await GetHttpClient().PostAsync(apiUrl, new StringContent("{}", Encoding.UTF8, "application/json"));
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
string responseJson = await response.Content.ReadAsStringAsync();
|
||||
@@ -75,7 +88,7 @@ public class JinkoSapService : IJinkoSapService
|
||||
};
|
||||
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
|
||||
|
||||
var response = await _httpClient.PostAsync(apiUrl, content);
|
||||
var response = await GetHttpClient().PostAsync(apiUrl, content);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
|
||||
Reference in New Issue
Block a user