|
|
|
|
using DocumentFormat.OpenXml.Math;
|
|
|
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
|
|
|
using Infrastructure;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using MQTTnet;
|
|
|
|
|
using OpenAuth.App.ServiceApp;
|
|
|
|
|
using OpenAuth.Repository.Domain;
|
|
|
|
|
using System.Text;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
public AirportMaintenanceController(AirportMaintenanceApp app, MqttClientManager mqttClientManager, MqttMessageCenter mqttCenter)
|
|
|
|
|
{
|
|
|
|
|
_app = app;
|
|
|
|
|
_mqttClientManager = mqttClientManager;
|
|
|
|
|
_mqttCenter = mqttCenter;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 机场注册 注册码生成
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Obsolete]
|
|
|
|
|
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]
|
|
|
|
|
[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());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.Code = 500;
|
|
|
|
|
result.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 切换相机
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<Response<int>> ExchangeCamera(Zhibo zhiboReq)
|
|
|
|
|
{
|
|
|
|
|
Response<int> response = new Response<int>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
camera_position = zhiboReq.position,
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
return response; ;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置直播镜头
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<Response<int>> SetCamera(Zhibo zhiboReq)
|
|
|
|
|
{
|
|
|
|
|
Response<int> response = new Response<int>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置直播清晰度
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<Response<int>> SetCameraVideo(Zhibo zhiboReq)
|
|
|
|
|
{
|
|
|
|
|
Response<int> response = new Response<int>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 停止直播
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<Response<int>> EndLive(Zhibo zhiboReq)
|
|
|
|
|
{
|
|
|
|
|
Response<int> response = new Response<int>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var videoids = zhiboReq.videoId.Split("/");
|
|
|
|
|
var topicRequest = $"thing/product/" + videoids[0] + "/services";
|
|
|
|
|
var requestData = new
|
|
|
|
|
{
|
|
|
|
|
bid = Guid.NewGuid().ToString(),
|
|
|
|
|
method = "live_stop_push",
|
|
|
|
|
tid = Guid.NewGuid().ToString(),
|
|
|
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
|
|
data = new
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 开始直播
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<Response<int>> StartLive(Zhibo zhiboReq)
|
|
|
|
|
{
|
|
|
|
|
Response<int> response = new Response<int>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|