345 lines
12 KiB
C#
345 lines
12 KiB
C#
using DocumentFormat.OpenXml.Math;
|
|
using Infrastructure;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using MQTTnet;
|
|
using OpenAuth.App.ServiceApp;
|
|
using OpenAuth.Repository.Domain;
|
|
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;
|
|
|
|
public AirportMaintenanceController(AirportMaintenanceApp app, MqttClientManager mqttClientManager)
|
|
{
|
|
_app = app;
|
|
_mqttClientManager = mqttClientManager;
|
|
}
|
|
/// <summary>
|
|
/// 机场注册 注册码生成
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 切换相机
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<int>> ExchangeCamera(string camera,int position,string videoId)
|
|
{
|
|
Response<int> response = new Response<int>();
|
|
try
|
|
{
|
|
|
|
var topicRequest = $"thing/product/8UUXN5400A079H/services";
|
|
var requestData = new
|
|
{
|
|
bid = Guid.NewGuid().ToString(),
|
|
method = "live_camera_change",
|
|
tid = Guid.NewGuid().ToString(),
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
data = new
|
|
{
|
|
camera_position = position,
|
|
video_id = "8UUXN5400A079H/165-0-7/normal-0"
|
|
}
|
|
};
|
|
string payload = JsonSerializer.Serialize(requestData);
|
|
await _mqttClientManager.PublishAsync(topicRequest, payload);
|
|
|
|
var topicRequest1 = $"thing/product/8UUXN5400A079H/services_reply";
|
|
var requestData1 = new
|
|
{
|
|
bid = Guid.NewGuid().ToString(),
|
|
method = "live_camera_change",
|
|
tid = Guid.NewGuid().ToString(),
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
data = new
|
|
{
|
|
result = 0
|
|
}
|
|
};
|
|
string payload1 = JsonSerializer.Serialize(requestData1);
|
|
await _mqttClientManager.PublishAsync(topicRequest1, payload1);
|
|
|
|
response.Result = 1;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
response.Code = 500;
|
|
response.Message = ex.Message;
|
|
}
|
|
return response; ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 设置直播镜头
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<int>> SetCamera(string cameraType, string videoId)
|
|
{
|
|
Response<int> response = new Response<int>();
|
|
try
|
|
{
|
|
|
|
var topicRequest = $"thing/product/8UUXN5400A079H/services";
|
|
var requestData = new
|
|
{
|
|
bid = Guid.NewGuid().ToString(),
|
|
method = "live_lens_change",
|
|
tid = Guid.NewGuid().ToString(),
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
data = new
|
|
{
|
|
video_type = cameraType,
|
|
video_id = "8UUXN5400A079H/165-0-7/normal-0"
|
|
}
|
|
};
|
|
string payload = JsonSerializer.Serialize(requestData);
|
|
await _mqttClientManager.PublishAsync(topicRequest, payload);
|
|
|
|
var topicRequest1 = $"thing/product/8UUXN5400A079H/services_reply";
|
|
var requestData1 = new
|
|
{
|
|
bid = Guid.NewGuid().ToString(),
|
|
method = "live_lens_change",
|
|
tid = Guid.NewGuid().ToString(),
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
data = new
|
|
{
|
|
result = 0
|
|
}
|
|
};
|
|
string payload1 = JsonSerializer.Serialize(requestData1);
|
|
await _mqttClientManager.PublishAsync(topicRequest1, payload1);
|
|
|
|
response.Result = 1;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
response.Code = 500;
|
|
response.Message = ex.Message;
|
|
}
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 设置直播清晰度
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<int>> SetCameraVideo(int videoQuality, string videoId)
|
|
{
|
|
Response<int> response = new Response<int>();
|
|
try
|
|
{
|
|
|
|
var topicRequest = $"thing/product/8UUXN5400A079H/services";
|
|
var requestData = new
|
|
{
|
|
bid = Guid.NewGuid().ToString(),
|
|
method = "live_set_quality",
|
|
tid = Guid.NewGuid().ToString(),
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
data = new
|
|
{
|
|
video_quality = videoQuality,
|
|
video_id = "8UUXN5400A079H/165-0-7/normal-0"
|
|
}
|
|
};
|
|
string payload = JsonSerializer.Serialize(requestData);
|
|
await _mqttClientManager.PublishAsync(topicRequest, payload);
|
|
|
|
var topicRequest1 = $"thing/product/8UUXN5400A079H/services_reply";
|
|
var requestData1 = new
|
|
{
|
|
bid = Guid.NewGuid().ToString(),
|
|
method = "live_set_quality",
|
|
tid = Guid.NewGuid().ToString(),
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
data = new
|
|
{
|
|
result = 0
|
|
}
|
|
};
|
|
string payload1 = JsonSerializer.Serialize(requestData1);
|
|
await _mqttClientManager.PublishAsync(topicRequest1, payload1);
|
|
|
|
response.Result = 1;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
response.Code = 500;
|
|
response.Message = ex.Message;
|
|
}
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 停止直播
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<int>> EndLive( string videoId)
|
|
{
|
|
Response<int> response = new Response<int>();
|
|
try
|
|
{
|
|
|
|
var topicRequest = $"thing/product/8UUXN5400A079H/services";
|
|
var requestData = new
|
|
{
|
|
bid = Guid.NewGuid().ToString(),
|
|
method = "live_stop_push",
|
|
tid = Guid.NewGuid().ToString(),
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
data = new
|
|
{
|
|
|
|
video_id = "8UUXN5400A079H/165-0-7/normal-0"
|
|
}
|
|
};
|
|
string payload = JsonSerializer.Serialize(requestData);
|
|
await _mqttClientManager.PublishAsync(topicRequest, payload);
|
|
|
|
var topicRequest1 = $"thing/product/8UUXN5400A079H/services_reply";
|
|
var requestData1 = new
|
|
{
|
|
bid = Guid.NewGuid().ToString(),
|
|
method = "live_start_push",
|
|
tid = Guid.NewGuid().ToString(),
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
data = new
|
|
{
|
|
result = 0
|
|
}
|
|
};
|
|
string payload1 = JsonSerializer.Serialize(requestData1);
|
|
await _mqttClientManager.PublishAsync(topicRequest1, payload1);
|
|
|
|
response.Result = 1;
|
|
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
response.Code = 500;
|
|
response.Message = ex.Message;
|
|
}
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 开始直播
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<int>> StartLive(string videoId,int urlType,string url,int quality)
|
|
{
|
|
Response<int> response = new Response<int>();
|
|
try
|
|
{
|
|
|
|
var topicRequest = $"thing/product/8UUXN5400A079H/services";
|
|
var requestData = new
|
|
{
|
|
bid = Guid.NewGuid().ToString(),
|
|
method = "live_start_push",
|
|
tid = Guid.NewGuid().ToString(),
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
data = new
|
|
{
|
|
url_type = urlType,
|
|
url = url,
|
|
video_quality = quality,
|
|
video_id = "8UUXN5400A079H/165-0-7/normal-0"
|
|
}
|
|
};
|
|
string payload = JsonSerializer.Serialize(requestData);
|
|
await _mqttClientManager.PublishAsync(topicRequest, payload);
|
|
|
|
|
|
|
|
response.Result = 1;
|
|
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
response.Code = 500;
|
|
response.Message = ex.Message;
|
|
}
|
|
return response;
|
|
|
|
}
|
|
}
|
|
}
|