Compare commits
2 Commits
fd5b40fc95
...
bcb13fd7f5
| Author | SHA1 | Date |
|---|---|---|
|
|
bcb13fd7f5 | |
|
|
8684a6e35d |
|
|
@ -5,6 +5,7 @@ using System.Buffers.Text;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Text.Unicode;
|
||||
|
|
@ -16,6 +17,7 @@ namespace Infrastructure.Helpers
|
|||
{
|
||||
String privateKey = "ABA4354EFAFE944C2F226A3981C7DC70F43BD6053EDA83F4DC274242BBB23CAA";
|
||||
String publicKey = "04F1BF1BEFD63F16E5DB3BCD32CA5D9A8E8DF7ADD67D6C4F293FB23F7BDA74F52D31B8DDAD03D955D566505A15D8B7DBE83B42378B8E8749C0EB6E2FBC8675838B";
|
||||
string publickey = "04D6974E2384ECE39F5ADF1473E4B9B60E0D438A6F701F667C0C88D25BE2F8508A3AAFF9D9500ECFFD8E79B2DE58C024B689B5C207486646EA08A352FBB0016D46";
|
||||
byte[] sm4Key = null;
|
||||
public EncryptionHelper()
|
||||
{
|
||||
|
|
@ -31,9 +33,9 @@ namespace Infrastructure.Helpers
|
|||
{
|
||||
sm4Key = SM4CryptoHelper.GenerateSM4Key();
|
||||
}
|
||||
string publickey = "04D6974E2384ECE39F5ADF1473E4B9B60E0D438A6F701F667C0C88D25BE2F8508A3AAFF9D9500ECFFD8E79B2DE58C024B689B5C207486646EA08A352FBB0016D46";
|
||||
//十六进制字符串 → 字节数组
|
||||
byte[] publickeybyte = HexToBytes(publickey);
|
||||
|
||||
//十六进制字符串 → 字节数组 publickey
|
||||
byte[] publickeybyte = HexToBytes(publicKey);
|
||||
var encryptdatasm2 = SM2CryptoHelper.Encrypt(publickeybyte, sm4Key);
|
||||
return Convert.ToBase64String(encryptdatasm2);
|
||||
}
|
||||
|
|
@ -95,9 +97,6 @@ namespace Infrastructure.Helpers
|
|||
{
|
||||
throw new InvalidOperationException("SM2签名失败", ex);
|
||||
}
|
||||
// SM2 签名
|
||||
|
||||
//byte[] signData = SM2CryptoHelper.Sign(privatekeybyte, needSignDataByte);
|
||||
|
||||
// Base64 编码签名(直接使用 Convert)
|
||||
string signDataBase64 = Convert.ToBase64String(signData);
|
||||
|
|
@ -108,6 +107,32 @@ namespace Infrastructure.Helpers
|
|||
return token;
|
||||
}
|
||||
|
||||
public bool Verify(string str)
|
||||
{
|
||||
string signData = "";
|
||||
// 拼接待签名数据
|
||||
string needSignData = "";
|
||||
|
||||
if (!string.IsNullOrEmpty(str))
|
||||
{
|
||||
string[] tokenstr = str.Split(".");
|
||||
signData=tokenstr[2];
|
||||
needSignData = tokenstr[0] + tokenstr[1];
|
||||
}
|
||||
byte[] signbyte=Convert.FromBase64String(signData);
|
||||
byte[] needSignDataByte = Encoding.UTF8.GetBytes(needSignData);
|
||||
// 4. SM2验签 publickey
|
||||
byte[] publickeybyte = HexToBytes(publicKey);
|
||||
try
|
||||
{
|
||||
return SM2CryptoHelper.Verify(publickeybyte, needSignDataByte, signbyte);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("SM2签名失败", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内部转byte方法
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -512,17 +512,17 @@ namespace OpenAuth.App
|
|||
{
|
||||
using (var uow = base.UnitWork.CreateContext())
|
||||
{
|
||||
foreach (var item in uow.Db.DbMaintenance.GetTableInfoList().Where(r => r.Name.ToLower().StartsWith("lasa_shpdata")))
|
||||
foreach (var item in uow.Db.DbMaintenance.GetTableInfoList().Where(r => r.Name.ToLower().StartsWith("drone_docktask")))
|
||||
{
|
||||
//string entityName = item.Name.Substring(0, 1).ToUpper() + item.Name.Substring(1, 7).ToLower() + item.Name.Substring(9, 1).ToUpper() + item.Name.Substring(10).ToLower();/*实体名大写*/
|
||||
string entityName = "LasaShpData";
|
||||
string entityName = item.Name.Substring(0, 1).ToUpper() + item.Name.Substring(1, 4).ToLower() + item.Name.Substring(6, 1).ToUpper() + item.Name.Substring(7).ToLower();/*实体名大写*/
|
||||
//string entityName = "LasaShpData";
|
||||
uow.Db.MappingTables.Add(entityName, item.Name);
|
||||
//foreach (var col in db.DbMaintenance.GetColumnInfosByTableName(item.Name))
|
||||
//{
|
||||
// db.MappingColumns.Add(col.DbColumnName.ToUpper() /*类的属性大写*/, col.DbColumnName, entityName);
|
||||
//}
|
||||
}
|
||||
uow.Db.DbFirst.Where(r => r.ToLower().StartsWith("lasa_shpdata")).IsCreateAttribute().CreateClassFile("E:\\低空态势感知\\code\\OpenAuth.Repository\\Domain", "OpenAuth.Repository.Domain");
|
||||
uow.Db.DbFirst.Where(r => r.ToLower().StartsWith("drone_docktask")).IsCreateAttribute().CreateClassFile("E:\\低空态势感知\\code\\OpenAuth.Repository\\Domain", "OpenAuth.Repository.Domain");
|
||||
uow.Commit();
|
||||
}
|
||||
return "更新实体成功";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,398 @@
|
|||
using OpenAuth.App.BaseApp.Base;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository;
|
||||
using System.Text;
|
||||
using OpenAuth.App.Interface;
|
||||
using SqlSugar;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Helpers;
|
||||
using System.Text.Json;
|
||||
using OpenAuth.App.ServiceApp.Response;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using OpenAuth.App.ServiceApp.DroneDocking.Request;
|
||||
using DocumentFormat.OpenXml.Office.CustomUI;
|
||||
|
||||
|
||||
namespace OpenAuth.App.ServiceApp.DroneDocking
|
||||
{
|
||||
public class DroneDockApp : SqlSugarBaseApp<LasaDronePort, SugarDbContext>
|
||||
{
|
||||
private EncryptionHelper _helper;
|
||||
private IConfiguration configuration;
|
||||
public DroneDockApp(EncryptionHelper helper, IConfiguration configuration, ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<LasaDronePort> repository, IAuth auth) : base(unitWork, repository, auth)
|
||||
{
|
||||
_helper = helper;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 无人机机场接口注册更新
|
||||
/// </summary>
|
||||
/// <param name="req"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Response<string>> RegistService(AirPortRegistReq req )
|
||||
{
|
||||
Response<string> Response = new Response<string>();
|
||||
|
||||
var handler = new HttpClientHandler();
|
||||
// 如果需要忽略服务器证书错误(仅测试环境)
|
||||
handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
try
|
||||
{
|
||||
string url = configuration.GetSection("DroneDocking:Url").Value + "/droneAirport/RegistService";
|
||||
string x_lc_secret = _helper.getxseret();
|
||||
string centercode = "UAV32_LJY2FPMYDE6UDES3P3ZD7V3IKQ";
|
||||
string x_token = _helper.GetToken(centercode);
|
||||
|
||||
// 序列化为 JSON 字符串
|
||||
string json = JsonSerializer.Serialize(req);
|
||||
|
||||
// 转换为字节数组
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(json);
|
||||
|
||||
var encryptedData = _helper.Encrypt(bytes);
|
||||
// 创建请求体
|
||||
var httpContent = new StringContent(encryptedData, Encoding.UTF8, "application/json");
|
||||
|
||||
// 添加请求头
|
||||
client.DefaultRequestHeaders.Add("x-lc-secret", x_lc_secret);
|
||||
client.DefaultRequestHeaders.Add("x-lc-token", x_token);
|
||||
|
||||
//发送请求
|
||||
HttpResponseMessage response = await client.PostAsync(url, httpContent);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
// 获取响应头中的 x_cl_screte 参数
|
||||
string resx_cl_screte = GetHeaderValue(response, "x-lc-secret");
|
||||
|
||||
// 读取响应内容并反序列化
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonSerializer.Deserialize<ReciveData<string>>(responseBody);
|
||||
|
||||
//解密数据
|
||||
byte[] resbytesx = Convert.FromBase64String(resx_cl_screte);
|
||||
byte[] resdatabytes = Convert.FromBase64String(result?.data);
|
||||
string data = _helper.Decrypt(resbytesx, resdatabytes);
|
||||
|
||||
Response.Result = data;
|
||||
Response.Message = result.message;
|
||||
Response.Code = result.code;
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
Console.WriteLine("\nException Caught!");
|
||||
Console.WriteLine("Message :{0} ", e.Message);
|
||||
Response.Result = "连接错误";
|
||||
}
|
||||
}
|
||||
|
||||
return Response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 无人机机场设备注册/更新
|
||||
/// </summary>
|
||||
/// <param name="req"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Response<string>> AddDevice(AddDeviceReq req)
|
||||
{
|
||||
Response<string> Response = new Response<string>();
|
||||
|
||||
var handler = new HttpClientHandler();
|
||||
// 如果需要忽略服务器证书错误(仅测试环境)
|
||||
handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
try
|
||||
{
|
||||
string url = configuration.GetSection("DroneDocking:Url").Value+ "/droneAirport/addDevice";
|
||||
string x_lc_secret = _helper.getxseret();
|
||||
string centercode = "UAV32_LJY2FPMYDE6UDES3P3ZD7V3IKQ";
|
||||
string x_token = _helper.GetToken(centercode);
|
||||
|
||||
// 序列化为 JSON 字符串
|
||||
string json = JsonSerializer.Serialize(req);
|
||||
|
||||
// 转换为字节数组
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(json);
|
||||
|
||||
var encryptedData = _helper.Encrypt(bytes);
|
||||
// 创建请求体
|
||||
var httpContent = new StringContent(encryptedData, Encoding.UTF8, "application/json");
|
||||
|
||||
// 添加请求头
|
||||
client.DefaultRequestHeaders.Add("x-lc-secret", x_lc_secret);
|
||||
client.DefaultRequestHeaders.Add("x-lc-token", x_token);
|
||||
|
||||
//发送请求
|
||||
HttpResponseMessage response = await client.PostAsync(url, httpContent);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
// 获取响应头中的 x_cl_screte 参数
|
||||
string resx_cl_screte = GetHeaderValue(response, "x-lc-secret");
|
||||
|
||||
// 读取响应内容并反序列化
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonSerializer.Deserialize<ReciveData<string>>(responseBody);
|
||||
|
||||
//解密数据
|
||||
byte[] resbytesx = Convert.FromBase64String(resx_cl_screte);
|
||||
byte[] resdatabytes = Convert.FromBase64String(result?.data);
|
||||
string data = _helper.Decrypt(resbytesx, resdatabytes);
|
||||
|
||||
Response.Result = data;
|
||||
Response.Message = result.message;
|
||||
Response.Code = result.code;
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
Console.WriteLine("\nException Caught!");
|
||||
Console.WriteLine("Message :{0} ", e.Message);
|
||||
Response.Result = "连接错误";
|
||||
}
|
||||
}
|
||||
|
||||
return Response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 无人机机场授权
|
||||
/// </summary>
|
||||
/// <param name="req"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Response<string>> Authorization(AuthorizationReq req)
|
||||
{
|
||||
Response<string> Response = new Response<string>();
|
||||
|
||||
var handler = new HttpClientHandler();
|
||||
// 如果需要忽略服务器证书错误(仅测试环境)
|
||||
handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
try
|
||||
{
|
||||
string url = configuration.GetSection("DroneDocking:Url").Value + "/droneAirport/authorization";
|
||||
string x_lc_secret = _helper.getxseret();
|
||||
string centercode = "UAV32_LJY2FPMYDE6UDES3P3ZD7V3IKQ";
|
||||
string x_token = _helper.GetToken(centercode);
|
||||
|
||||
// 序列化为 JSON 字符串
|
||||
string json = JsonSerializer.Serialize(req);
|
||||
|
||||
// 转换为字节数组
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(json);
|
||||
|
||||
var encryptedData = _helper.Encrypt(bytes);
|
||||
// 创建请求体
|
||||
var httpContent = new StringContent(encryptedData, Encoding.UTF8, "application/json");
|
||||
|
||||
// 添加请求头
|
||||
client.DefaultRequestHeaders.Add("x-lc-secret", x_lc_secret);
|
||||
client.DefaultRequestHeaders.Add("x-lc-token", x_token);
|
||||
|
||||
//发送请求
|
||||
HttpResponseMessage response = await client.PostAsync(url, httpContent);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
// 获取响应头中的 x_cl_screte 参数
|
||||
string resx_cl_screte = GetHeaderValue(response, "x-lc-secret");
|
||||
|
||||
// 读取响应内容并反序列化
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonSerializer.Deserialize<ReciveData<string>>(responseBody);
|
||||
|
||||
//解密数据
|
||||
byte[] resbytesx = Convert.FromBase64String(resx_cl_screte);
|
||||
byte[] resdatabytes = Convert.FromBase64String(result?.data);
|
||||
string data = _helper.Decrypt(resbytesx, resdatabytes);
|
||||
|
||||
Response.Result = data;
|
||||
Response.Message = result.message;
|
||||
Response.Code = result.code;
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
Console.WriteLine("\nException Caught!");
|
||||
Console.WriteLine("Message :{0} ", e.Message);
|
||||
Response.Result = "连接错误";
|
||||
}
|
||||
}
|
||||
|
||||
return Response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 无人机机场授权
|
||||
/// </summary>
|
||||
/// <param name="req"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Response<string>> Test(AirPortTaskReq req)
|
||||
{
|
||||
Response<string> Response = new Response<string>();
|
||||
|
||||
var handler = new HttpClientHandler();
|
||||
// 如果需要忽略服务器证书错误(仅测试环境)
|
||||
handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
try
|
||||
{
|
||||
string url = "http://localhost:10042/zhcfzx/droneAirport/AddTask";
|
||||
string x_lc_secret = _helper.getxseret();
|
||||
string centercode = "UAV32_LJY2FPMYDE6UDES3P3ZD7V3IKQ";
|
||||
string x_token = _helper.GetToken(centercode);
|
||||
|
||||
// 序列化为 JSON 字符串
|
||||
string json = JsonSerializer.Serialize(req);
|
||||
|
||||
// 转换为字节数组
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(json);
|
||||
|
||||
var encryptedData = _helper.Encrypt(bytes);
|
||||
// 创建请求体
|
||||
var httpContent = new StringContent(encryptedData, Encoding.UTF8, "application/json");
|
||||
|
||||
// 添加请求头
|
||||
client.DefaultRequestHeaders.Add("x-lc-secret", x_lc_secret);
|
||||
client.DefaultRequestHeaders.Add("x-lc-token", x_token);
|
||||
|
||||
//发送请求
|
||||
HttpResponseMessage response = await client.PostAsync(url, httpContent);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
// 获取响应头中的 x_cl_screte 参数
|
||||
string resx_cl_screte = GetHeaderValue(response, "x-lc-secret");
|
||||
|
||||
// 读取响应内容并反序列化
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonSerializer.Deserialize<ReciveData<string>>(responseBody);
|
||||
|
||||
//解密数据
|
||||
byte[] resbytesx = Convert.FromBase64String(resx_cl_screte);
|
||||
byte[] resdatabytes = Convert.FromBase64String(result?.data);
|
||||
string data = _helper.Decrypt(resbytesx, resdatabytes);
|
||||
|
||||
Response.Result = data;
|
||||
Response.Message = result.message;
|
||||
Response.Code = result.code;
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
Console.WriteLine("\nException Caught!");
|
||||
Console.WriteLine("Message :{0} ", e.Message);
|
||||
Response.Result = "连接错误";
|
||||
}
|
||||
}
|
||||
|
||||
return Response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 无人机任务添加
|
||||
/// </summary>
|
||||
/// <param name="req"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ResData> AddTask(string req,string secret)
|
||||
{
|
||||
ResData Response = new ResData();
|
||||
|
||||
//解密数据
|
||||
byte[] secretbyte = Convert.FromBase64String(secret); //x-lc-secret
|
||||
byte[] reqbyte = Convert.FromBase64String(req); //返回数据
|
||||
string data = _helper.Decrypt(secretbyte, reqbyte);
|
||||
|
||||
//序列化返回数据并处理
|
||||
var task = JsonSerializer.Deserialize<AirPortTaskReq>(data);
|
||||
|
||||
//task数据生成
|
||||
DroneDocktask dt= new DroneDocktask();
|
||||
dt.id=Guid.NewGuid().ToString();
|
||||
dt.deviceid=task.deviceid.ToString();
|
||||
dt.bizidname=task.bizidname.ToString();
|
||||
dt.taskid = task.taskid;
|
||||
dt.taskname = task.taskname;
|
||||
dt.datacode= task.datacode;
|
||||
|
||||
//taskdetail数据生成
|
||||
List<DroneDocktaskdetail> dalist= new List<DroneDocktaskdetail>();
|
||||
if (task.tasklist.Count > 0 )
|
||||
{
|
||||
foreach(var item in task.tasklist)
|
||||
{
|
||||
DroneDocktaskdetail da= new DroneDocktaskdetail();
|
||||
da.id = Guid.NewGuid().ToString();
|
||||
da.taskid = dt.id;
|
||||
da.bz=item.bz;
|
||||
da.dkbh=item.dkbh;
|
||||
da.dkfw=item.dkfw;
|
||||
da.dkmj=item.dkmj;
|
||||
da.dkmc=item.dkmc;
|
||||
da.xzqdm=item.xzqdm;
|
||||
da.zdkbh=item.zdkbh;
|
||||
da.bsm=item.bsm;
|
||||
da.dklx=item.dklx;
|
||||
dalist.Add(da);
|
||||
}
|
||||
}
|
||||
|
||||
using (var uow = base.UnitWork.CreateContext())
|
||||
{
|
||||
//本地数据库数据添加
|
||||
await uow.DroneDocktask.InsertAsync(dt);
|
||||
await uow.DroneDocktaskdetail.InsertRangeAsync(dalist);
|
||||
var flag = uow.Commit();
|
||||
|
||||
//返回数据
|
||||
if (flag)
|
||||
{
|
||||
string x_lc_secret = _helper.getxseret();
|
||||
// 转换为字节数组
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(dt.taskid);
|
||||
var encryptedResData = _helper.Encrypt(bytes);
|
||||
Response.Result = encryptedResData;
|
||||
Response.Message = "无人机机场任务添加成功";
|
||||
Response.Code = 200;
|
||||
Response.Secret = x_lc_secret;
|
||||
return Response;
|
||||
}
|
||||
else
|
||||
{
|
||||
string x_lc_secret = _helper.getxseret();
|
||||
// 转换为字节数组
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(" ");
|
||||
|
||||
var encryptedResData = _helper.Encrypt(bytes);
|
||||
Response.Result = encryptedResData;
|
||||
Response.Message = "无人机机场任务添加失败";
|
||||
Response.Code = 500;
|
||||
Response.Secret = x_lc_secret;
|
||||
return Response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 安全获取响应头值的方法
|
||||
private static string GetHeaderValue(HttpResponseMessage response, string headerName)
|
||||
{
|
||||
if (response.Headers.TryGetValues(headerName, out IEnumerable<string> values))
|
||||
{
|
||||
return string.Join(", ", values); // 如果多个值则合并
|
||||
}
|
||||
|
||||
// 尝试忽略大小写再次查找
|
||||
foreach (var header in response.Headers)
|
||||
{
|
||||
if (header.Key.Equals(headerName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return string.Join(", ", header.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return null; // 未找到
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,173 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenAuth.App.ServiceApp.DroneDocking.Request
|
||||
{
|
||||
public class AirPortRegistReq
|
||||
{
|
||||
public string serviceUrl { get; set; }
|
||||
public string liveStreampluginUrl { get; set; }
|
||||
public string contacts { get; set; }
|
||||
public string phone { get; set; }
|
||||
}
|
||||
|
||||
public class AddDeviceReq
|
||||
{
|
||||
//区域代码
|
||||
public string regioncode { get; set; }
|
||||
//无人机设备id
|
||||
public string deviceid { get; set; }
|
||||
//无人机品牌
|
||||
public string brand { get; set; }
|
||||
//无人机型号
|
||||
public string model { get; set; }
|
||||
//无人机机场经度,保留7位小数
|
||||
public double longitude { get; set; }
|
||||
//无人机机场维度,保留7位小数
|
||||
public double latitude { get; set; }
|
||||
//无人机机场高度
|
||||
public double height { get; set; }
|
||||
//无人机机场飞行半径,单位米
|
||||
public double radius { get; set; }
|
||||
//设备类型(默认0),0表示机场无人机 1表示手持无人机
|
||||
public int devicetype { get; set; }
|
||||
//紧急联系人,devicetype=1时必填
|
||||
public string contacts { get; set; }
|
||||
//紧急联系电话 ,devicetype=1时必填
|
||||
public string phone { get; set; }
|
||||
}
|
||||
|
||||
public class AuthorizationReq
|
||||
{
|
||||
//无人机机场设备唯一id
|
||||
public string deviceid { get; set; }
|
||||
//0:不可用 1:可用
|
||||
public int status { get; set; }
|
||||
}
|
||||
|
||||
public class AirPortTaskReq
|
||||
{
|
||||
//无人机机场设备唯一id
|
||||
public List<string> deviceid { get; set; }
|
||||
/// <summary>
|
||||
/// Desc:业务类型,用于标识数据来源
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string bizidname { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:下发任务名称
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string taskname { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:下发任务id
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string taskid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:数据类型, 用于后续成果上传获取上传路径
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string datacode { get; set; }
|
||||
|
||||
public List<TaskDetail> tasklist { get; set; }
|
||||
}
|
||||
|
||||
public class TaskDetail
|
||||
{
|
||||
/// <summary>
|
||||
/// Desc:图斑标识码
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string bsm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:县级行政区代码
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string xzqdm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:地块编号
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string dkbh { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:地块类型
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string dklx { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:子地块编号
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string zdkbh { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:地块名称
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string dkmc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:地块面积
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public decimal? dkmj { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:地块范围,cgcs2000的经纬度坐标,wkt格式
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string dkfw { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:备注
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string bz { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class ResData
|
||||
{
|
||||
/// <summary>
|
||||
/// 操作消息【当Status不为 200时,显示详细的错误信息】
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 操作状态码,200为正常
|
||||
/// </summary>
|
||||
public int Code { get; set; }
|
||||
|
||||
public ResData()
|
||||
{
|
||||
Code = 200;
|
||||
Message = "操作成功";
|
||||
}
|
||||
public string Result { get; set; }
|
||||
public string Secret {get;set;}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
using OpenAuth.App.BaseApp.Base;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Infrastructure.CloudSdk.minio;
|
||||
using OpenAuth.App.BasicQueryService;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.WebApi;
|
||||
using SqlSugar;
|
||||
using Infrastructure;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
using Infrastructure.Helpers;
|
||||
using System.Text.Json;
|
||||
using NetModular.DocX.Core;
|
||||
using System.DirectoryServices.Protocols;
|
||||
using OpenAuth.App.ServiceApp.Response;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
|
||||
namespace OpenAuth.App.ServiceApp
|
||||
{
|
||||
public class TestApp : SqlSugarBaseApp<LasaDronePort, SugarDbContext>
|
||||
{
|
||||
private EncryptionHelper _helper;
|
||||
public TestApp(EncryptionHelper helper, ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<LasaDronePort> repository, IAuth auth): base(unitWork, repository, auth)
|
||||
{
|
||||
_helper = helper;
|
||||
}
|
||||
|
||||
public async Task<Response<string>> RegistService()
|
||||
{
|
||||
//using var httpClient = new HttpClient();
|
||||
Response<string> Response=new Response<string>();
|
||||
|
||||
var handler = new HttpClientHandler();
|
||||
//handler.ClientCertificates.Add(cert);
|
||||
// 如果需要忽略服务器证书错误(仅测试环境)
|
||||
handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
try
|
||||
{
|
||||
string url = "https://wp.tianmu.cloud:5443/zhcfzx/droneAirport/RegistService";
|
||||
// var param = new Dictionary<string, string>()
|
||||
//{
|
||||
// { "serviceUrl", "https://xxx.com/mdc/v1/" },
|
||||
// { "1iveStreampluginUrl", "https://ss.com/drone/v1/livestream.js" },
|
||||
// { "contacts", "孟三" },
|
||||
// { "phone", "18390849120" },
|
||||
|
||||
//};
|
||||
string json= "{" +
|
||||
"\"serviceUrl\": \"https://xxx.com/mdc/v1/\"," +
|
||||
"\"liveStreampluginUrl\": \"https://xxx.com/drone/v1/livestream.js\"," +
|
||||
"\"contacts\": \"孟三\"," +
|
||||
"\"phone\": \"18390849120\"" +
|
||||
"}";
|
||||
string x_lc_secret = _helper.getxseret();
|
||||
string centercode = "UAV32_LJY2FPMYDE6UDES3P3ZD7V3IKQ";
|
||||
string x_token = _helper.GetToken(centercode);
|
||||
|
||||
// 序列化为 JSON 字符串
|
||||
//string json = JsonSerializer.Serialize(param);
|
||||
|
||||
// 转换为字节数组
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(json);
|
||||
|
||||
var encryptedData = _helper.Encrypt(bytes);
|
||||
// 创建请求体
|
||||
var httpContent = new StringContent(encryptedData, Encoding.UTF8, "application/json");
|
||||
|
||||
// 添加请求头
|
||||
client.DefaultRequestHeaders.Add("x-lc-secret", x_lc_secret);
|
||||
client.DefaultRequestHeaders.Add("x-lc-token", x_token);
|
||||
|
||||
//发送请求
|
||||
HttpResponseMessage response = await client.PostAsync(url, httpContent);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
// 获取响应头中的 x_cl_screte 参数
|
||||
string resx_cl_screte = GetHeaderValue(response, "x-lc-secret");
|
||||
|
||||
// 读取响应内容并反序列化
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonSerializer.Deserialize<ReciveData<string>>(responseBody);
|
||||
|
||||
//解密数据
|
||||
byte[] resbytesx = Convert.FromBase64String(resx_cl_screte);
|
||||
byte[] resdatabytes = Convert.FromBase64String(result?.data);
|
||||
string data = _helper.Decrypt(resbytesx, resdatabytes);
|
||||
|
||||
Response.Result = data;
|
||||
Response.Message = result.message;
|
||||
Response.Result = result.code.ToString();
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
Console.WriteLine("\nException Caught!");
|
||||
Console.WriteLine("Message :{0} ", e.Message);
|
||||
Response.Result = "连接错误";
|
||||
}
|
||||
}
|
||||
|
||||
return Response;
|
||||
}
|
||||
|
||||
|
||||
// 安全获取响应头值的方法
|
||||
private static string GetHeaderValue(HttpResponseMessage response, string headerName)
|
||||
{
|
||||
if (response.Headers.TryGetValues(headerName, out IEnumerable<string> values))
|
||||
{
|
||||
return string.Join(", ", values); // 如果多个值则合并
|
||||
}
|
||||
|
||||
// 尝试忽略大小写再次查找
|
||||
foreach (var header in response.Headers)
|
||||
{
|
||||
if (header.Key.Equals(headerName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return string.Join(", ", header.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return null; // 未找到
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
|
||||
namespace OpenAuth.Repository.Domain
|
||||
{
|
||||
///<summary>
|
||||
///省对接无人机任务表
|
||||
///</summary>
|
||||
[SugarTable("drone_docktask")]
|
||||
public partial class DroneDocktask
|
||||
{
|
||||
public DroneDocktask(){
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:主键
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey=true)]
|
||||
public string id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:无人机机场设备唯一id(多个)
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string deviceid {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:业务类型,用于标识数据来源
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string bizidname {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:下发任务名称
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string taskname {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:下发任务id
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string taskid {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:数据类型, 用于后续成果上传获取上传路径
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string datacode {get;set;}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
|
||||
namespace OpenAuth.Repository.Domain
|
||||
{
|
||||
///<summary>
|
||||
///省对接,任务添加详情
|
||||
///</summary>
|
||||
[SugarTable("drone_docktaskdetail")]
|
||||
public partial class DroneDocktaskdetail
|
||||
{
|
||||
public DroneDocktaskdetail(){
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:主键
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey=true)]
|
||||
public string id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:图斑标识码
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string bsm {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:县级行政区代码
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string xzqdm {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:地块编号
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string dkbh {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:地块类型
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string dklx {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:子地块编号
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string zdkbh {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:地块名称
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string dkmc {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:地块面积
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public decimal? dkmj {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:地块范围,cgcs2000的经纬度坐标,wkt格式
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string dkfw {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:备注
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string bz {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:任务id,对应任务表id
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string taskid {get;set;}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -76,6 +76,8 @@ namespace OpenAuth.Repository
|
|||
public SugarRepositiry<LasaLog> LasaLog { get; set; }
|
||||
public SugarRepositiry<LasaFirmware> LasaFirmware { get; set; }
|
||||
public SugarRepositiry<LasaDeviceDictionary> LasaDeviceDictionary { get; set; }
|
||||
public SugarRepositiry<DroneDocktaskdetail> DroneDocktaskdetail { get; set; }
|
||||
public SugarRepositiry<DroneDocktask> DroneDocktask { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,173 @@
|
|||
using Infrastructure;
|
||||
using Infrastructure.Cache;
|
||||
using Infrastructure.Helpers;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OpenAuth.App.ServiceApp.DroneDocking;
|
||||
using OpenAuth.App.ServiceApp.DroneDocking.Request;
|
||||
using OpenAuth.App.ServiceApp.Response;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 对接
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class DroneDockController: ControllerBase
|
||||
{
|
||||
private readonly DroneDockApp _app;
|
||||
private EncryptionHelper _helper;
|
||||
public DroneDockController(DroneDockApp app,EncryptionHelper helper)
|
||||
{
|
||||
_app = app;
|
||||
_helper = helper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 无人机机场接口注册/更新
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<Response<string>> RegistService([FromBody] AirPortRegistReq req)
|
||||
{
|
||||
var result = new Response<string>();
|
||||
try
|
||||
{
|
||||
result = await _app.RegistService(req);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.Message;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 无人机机场设备注册/更新
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<Response<string>> AddDevice([FromBody] AddDeviceReq req)
|
||||
{
|
||||
var result = new Response<string>();
|
||||
try
|
||||
{
|
||||
result = await _app.AddDevice(req);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.Message;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 无人机机场设备授权
|
||||
/// </summary>
|
||||
/// <param name="req"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<Response<string>> Authorization([FromBody] AuthorizationReq req)
|
||||
{
|
||||
var result = new Response<string>();
|
||||
try
|
||||
{
|
||||
result = await _app.Authorization(req);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.Message;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<Response<string>> Test([FromBody] AirPortTaskReq req)
|
||||
{
|
||||
var result = new Response<string>();
|
||||
try
|
||||
{
|
||||
result = await _app.Test(req);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.Message;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 无人机任务添加
|
||||
/// </summary>
|
||||
/// <param name="req"></param>
|
||||
/// <returns></returns>
|
||||
[Route("/zhcfzx/droneAirport/AddTask")]
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<ReciveData<string>> AddTask(string recivedata)
|
||||
{
|
||||
var result = new ReciveData<string>();
|
||||
if(Request.Headers.TryGetValue("x-lc-token", out var tokenValue))
|
||||
{
|
||||
var tokenflag = _helper.Verify(tokenValue);
|
||||
if (tokenflag)
|
||||
{
|
||||
// 获取请求头中的x-lc-secret
|
||||
if (Request.Headers.TryGetValue("x-lc-secret", out var secretValue))
|
||||
{
|
||||
string secret = secretValue.ToString();
|
||||
try
|
||||
{
|
||||
// 1. 从请求体中直接读取原始字符串(即 encryptedData)
|
||||
string req;
|
||||
using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
|
||||
{
|
||||
req = await reader.ReadToEndAsync();
|
||||
}
|
||||
var data = await _app.AddTask(req, secret);
|
||||
result.data = data.Result;
|
||||
result.code=data.Code;
|
||||
result.message = data.Message;
|
||||
Request.Headers.TryGetValue("traceid", out var traceid);
|
||||
result.traceid = traceid;
|
||||
Response.Headers.Add("x-lc-secret", data.Secret);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.code = 200;
|
||||
result.message = "error";
|
||||
Request.Headers.TryGetValue("traceid", out var traceid);
|
||||
result.traceid = traceid;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Missing required header: x-lc-secret");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("unauthorized");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Missing required header: x-lc-token");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
using Infrastructure;
|
||||
using Infrastructure.Cache;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OpenAuth.App.ServiceApp;
|
||||
|
||||
namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 对接
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class TestController: ControllerBase
|
||||
{
|
||||
private readonly TestApp _app;
|
||||
public TestController(TestApp app)
|
||||
{
|
||||
_app = app;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试接口
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<Response<string>> RegistService()
|
||||
{
|
||||
var result = new Response<string>();
|
||||
try
|
||||
{
|
||||
result = await _app.RegistService();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.Message;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -81,5 +81,8 @@
|
|||
"SecretKey": "minioadmin",
|
||||
"BucketName": "test",
|
||||
"limitspeed": 1048576
|
||||
},
|
||||
"DroneDocking": {
|
||||
"Url": "https://wp.tianmu.cloud:5443/zhcfzx"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue