|
@@ -7,9 +7,13 @@ namespace Ai.AgentServer.Server
|
|
|
public class HttpServer: IHttpServer
|
|
|
{
|
|
|
public IHttpClientFactory _httpClientFactory;
|
|
|
- public HttpServer(IHttpClientFactory httpClientFactory)
|
|
|
+ public ILogger _logger { get; set; }
|
|
|
+ public IConfiguration configuration1 { get; set; }
|
|
|
+ public HttpServer(IHttpClientFactory httpClientFactory,ILogger<HttpServer> logger,IConfiguration configuration)
|
|
|
{
|
|
|
_httpClientFactory=httpClientFactory;
|
|
|
+ _logger=logger;
|
|
|
+ configuration1 = configuration;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -22,15 +26,24 @@ namespace Ai.AgentServer.Server
|
|
|
{
|
|
|
if (request == null||string.IsNullOrWhiteSpace(request.Type)) return new FuelReponse(5001, request);
|
|
|
var client = _httpClientFactory.CreateClient("FuelClient");
|
|
|
+ var xunfeiUrl = "http://211.91.71.15:8899";
|
|
|
//配置文件读取
|
|
|
- client.BaseAddress =new Uri("http://211.91.71.15:8899");
|
|
|
- var requesStr = new StringContent(JsonConvert.SerializeObject(request.BuildDto()), Encoding.UTF8, "application/json");
|
|
|
+ if (!string.IsNullOrWhiteSpace(configuration1.GetSection("XunFei").Value))
|
|
|
+ {
|
|
|
+ xunfeiUrl = configuration1.GetSection("XunFei").Value;
|
|
|
+ }
|
|
|
+
|
|
|
+ client.BaseAddress =new Uri(xunfeiUrl);
|
|
|
+ var requestJson = JsonConvert.SerializeObject(request.BuildDto());
|
|
|
+ _logger.LogInformation($"讯飞request:{DateTime.Now}-{requestJson}");
|
|
|
+ var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
try
|
|
|
{
|
|
|
var response = await client.PostAsync("/app-control-center/app/manualDrive", requesStr);
|
|
|
+ _logger.LogInformation($"讯飞reponse:{DateTime.Now}-{response.IsSuccessStatusCode}");
|
|
|
if (response != null && response.IsSuccessStatusCode)
|
|
|
{
|
|
|
- Console.WriteLine("Success");
|
|
|
+ Console.WriteLine("xunfei Success");
|
|
|
var fuelreponse = JsonConvert.DeserializeObject<FuelReponse>(await response.Content.ReadAsStringAsync());
|
|
|
return fuelreponse.SetID(request);
|
|
|
}
|
|
@@ -39,6 +52,8 @@ namespace Ai.AgentServer.Server
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Console.WriteLine(ex.Message);
|
|
|
+ _logger.LogError($"讯飞reponse:{DateTime.Now}-{ex.Message} \r\n {requestJson}");
|
|
|
+
|
|
|
return new FuelReponse(5001, request);
|
|
|
}
|
|
|
return new FuelReponse(5000, request);
|