You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

394 lines
13 KiB
C#

3 months ago
using DocumentFormat.OpenXml.Math;
using DocumentFormat.OpenXml.Spreadsheet;
3 months ago
using Infrastructure;
3 months ago
using Microsoft.AspNetCore.Authorization;
3 months ago
using Microsoft.AspNetCore.Mvc;
using MQTTnet;
using OpenAuth.App.ServiceApp;
using OpenAuth.Repository.Domain;
using System.Text;
3 months ago
using System.Text.Json;
namespace OpenAuth.WebApi.Controllers.ServiceControllers
{
/// <summary>
/// 机场运维
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class AirportMaintenanceController : ControllerBase
{
private readonly AirportMaintenanceApp _app;
private readonly MqttClientManager _mqttClientManager;
private readonly MqttMessageCenter _mqttCenter;
3 months ago
public AirportMaintenanceController(AirportMaintenanceApp app, MqttClientManager mqttClientManager, MqttMessageCenter mqttCenter)
3 months ago
{
_app = app;
_mqttClientManager = mqttClientManager;
_mqttCenter = mqttCenter;
3 months ago
}
3 months ago
/// <summary>
/// 机场注册 注册码生成
/// </summary>
/// <returns></returns>
3 months ago
[HttpPost]
3 months ago
[Obsolete]
3 months ago
public async Task<Response<LasaDeviceBindingCode>> GetDeviceBindingCode()
{
var result = new Response<LasaDeviceBindingCode>();
try
{
result = await _app.GetDeviceBindingCode();
//发送MQTT消息
if (result.Code == 200 && result.Result != null)
{
var topicRequest = $"thing/product/{result.Result.DeviceBindingCode}/requests";
var requestData = new
{
bid = Guid.NewGuid().ToString(),
method = "airport_organization_bind",
tid = Guid.NewGuid().ToString(),
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
bind_devices = new[]
{
new
{
device_binding_code = result.Result.DeviceBindingCode,
organization_id = result.Result.OrgId
}
}
}
};
string payload = JsonSerializer.Serialize(requestData);
await _mqttClientManager.PublishAsync(topicRequest, payload);
//在这个地方在接收一下?
}
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.Message;
}
return result;
}
3 months ago
/// <summary>
/// 机场注册 注册码生成
/// </summary>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public async Task<Response<LasaGateway>> GetGateway()
{
var result = new Response<LasaGateway>();
try
{
result = await _app.GetGateway();
//自动更新主题
string sn = result.Result.GatewaySn;
var topics = new List<string>();
topics.AddRange(new[]
{
$"thing/product/{sn}/osd",
$"thing/product/{sn}/events",
$"thing/product/{sn}/requests",
$"thing/product/{sn}/services"
});
await _mqttCenter.SubscribeAsync(topics.ToArray());
3 months ago
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.Message;
}
return result;
}
#region 固件版本管理
/// <summary>
/// 添加固件版本
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public async Task<Response<bool>> AddFirmware(LasaFirmware info)
{
var result = new Response<bool>();
try
{
result = await _app.AddFirmware(info);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.Message;
}
return result;
}
#endregion
/// <summary>
/// 切换相机
/// </summary>
/// <returns></returns>
[HttpPost]
3 months ago
public async Task<Response<int>> ExchangeCamera(Zhibo zhiboReq)
{
Response<int> response = new Response<int>();
try
{
3 months ago
var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
bid = Guid.NewGuid().ToString(),
method = "live_camera_change",
tid = Guid.NewGuid().ToString(),
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
3 months ago
camera_position = zhiboReq.position,
video_id = zhiboReq.videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
await _mqttClientManager.PublishAsync(topicRequest, payload);
3 months ago
var topicRequest1 = $"thing/product/" + videoids[0] + "/services_reply";
await _mqttClientManager.SubscribeAsync(topicRequest1, async (args) =>
{
var payload = args.ApplicationMessage.Payload;
var message = Encoding.UTF8.GetString(payload);
Console.WriteLine($"收到主题 [{args.ApplicationMessage.Topic}] 的消息: {message}");
3 months ago
await Task.CompletedTask;
});
response.Result = 0;
}
catch (Exception ex)
{
response.Code = 500;
response.Message = ex.Message;
}
return response; ;
3 months ago
}
/// <summary>
/// 设置直播镜头
/// </summary>
/// <returns></returns>
[HttpPost]
3 months ago
public async Task<Response<int>> SetCamera(Zhibo zhiboReq)
{
Response<int> response = new Response<int>();
try
{
3 months ago
var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
bid = Guid.NewGuid().ToString(),
method = "live_lens_change",
tid = Guid.NewGuid().ToString(),
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
3 months ago
video_type = zhiboReq.cameraType,
video_id = zhiboReq.videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
await _mqttClientManager.PublishAsync(topicRequest, payload);
var topicRequest1 = $"thing/product/" + videoids[0] + "/services_reply";
await _mqttClientManager.SubscribeAsync(topicRequest1, async (args) =>
{
var payload = args.ApplicationMessage.Payload;
var message = Encoding.UTF8.GetString(payload);
Console.WriteLine($"收到主题 [{args.ApplicationMessage.Topic}] 的消息: {message}");
await Task.CompletedTask;
});
response.Result = 0;
}
catch (Exception ex)
{
response.Code = 500;
response.Message = ex.Message;
}
3 months ago
return response;
}
/// <summary>
/// 设置直播清晰度
/// </summary>
/// <returns></returns>
[HttpPost]
3 months ago
public async Task<Response<int>> SetCameraVideo(Zhibo zhiboReq)
{
Response<int> response = new Response<int>();
try
{
3 months ago
var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
bid = Guid.NewGuid().ToString(),
method = "live_set_quality",
tid = Guid.NewGuid().ToString(),
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
3 months ago
video_quality = zhiboReq.videoQuality,
video_id = zhiboReq.videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
await _mqttClientManager.PublishAsync(topicRequest, payload);
var topicRequest1 = $"thing/product/" + videoids[0] + "/services_reply";
await _mqttClientManager.SubscribeAsync(topicRequest1, async (args) =>
{
var payload = args.ApplicationMessage.Payload;
var message = Encoding.UTF8.GetString(payload);
Console.WriteLine($"收到主题 [{args.ApplicationMessage.Topic}] 的消息: {message}");
await Task.CompletedTask;
});
response.Result = 0;
}
catch (Exception ex)
{
response.Code = 500;
response.Message = ex.Message;
}
3 months ago
return response;
}
/// <summary>
/// 停止直播
/// </summary>
/// <returns></returns>
[HttpPost]
3 months ago
public async Task<Response<int>> EndLive(Zhibo zhiboReq)
{
Response<int> response = new Response<int>();
try
{
3 months ago
var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
3 months ago
{
bid = Guid.NewGuid().ToString(),
method = "live_stop_push",
tid = Guid.NewGuid().ToString(),
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
3 months ago
video_id = zhiboReq.videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
await _mqttClientManager.PublishAsync(topicRequest, payload);
var topicRequest1 = $"thing/product/" + videoids[0] + "/services_reply";
await _mqttClientManager.SubscribeAsync(topicRequest1, async (args) =>
{
var payload = args.ApplicationMessage.Payload;
var message = Encoding.UTF8.GetString(payload);
Console.WriteLine($"收到主题 [{args.ApplicationMessage.Topic}] 的消息: {message}");
await Task.CompletedTask;
});
response.Result = 0;
3 months ago
}
catch (Exception ex)
{
response.Code = 500;
response.Message = ex.Message;
}
return response;
}
/// <summary>
/// 开始直播
/// </summary>
/// <returns></returns>
[HttpPost]
3 months ago
public async Task<Response<int>> StartLive(Zhibo zhiboReq)
{
Response<int> response = new Response<int>();
try
{
3 months ago
var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
bid = Guid.NewGuid().ToString(),
method = "live_start_push",
tid = Guid.NewGuid().ToString(),
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
3 months ago
url_type = zhiboReq.urlType,
url = zhiboReq.url,
video_quality = zhiboReq.videoQuality,
video_id = zhiboReq.videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
await _mqttClientManager.PublishAsync(topicRequest, payload);
var topicRequest1 = $"thing/product/" + videoids[0] + "/services_reply";
await _mqttClientManager.SubscribeAsync(topicRequest1, async (args) =>
{
var payload1 = args.ApplicationMessage.Payload;
var message = Encoding.UTF8.GetString(payload1);
Console.WriteLine($"收到主题 [{args.ApplicationMessage.Topic}] 的消息: {message}");
await Task.CompletedTask;
});
response.Result = 0;
}
catch (Exception ex)
{
response.Code = 500;
response.Message = ex.Message;
}
return response;
}
3 months ago
}
}