操控平台后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.2 KiB

// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Utilities.Encoders;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace Admin.NET.Core.Service;
/// <summary>
/// 系统通用服务
/// </summary>
[ApiDescriptionSettings(Order = 101)]
[AllowAnonymous]
public class SysCommonService : IDynamicApiController, ITransient
{
private readonly IApiDescriptionGroupCollectionProvider _apiProvider;
public SysCommonService(IApiDescriptionGroupCollectionProvider apiProvider)
{
_apiProvider = apiProvider;
}
/// <summary>
/// 获取国密公钥私钥对
/// </summary>
/// <returns></returns>
[DisplayName("获取国密公钥私钥对")]
public SmKeyPairOutput GetSmKeyPair()
{
var kp = GM.GenerateKeyPair();
var privateKey = Hex.ToHexString(((ECPrivateKeyParameters)kp.Private).D.ToByteArray()).ToUpper();
var publicKey = Hex.ToHexString(((ECPublicKeyParameters)kp.Public).Q.GetEncoded()).ToUpper();
return new SmKeyPairOutput
{
PrivateKey = privateKey,
PublicKey = publicKey,
};
}
/// <summary>
/// 获取所有接口/动态API
/// </summary>
/// <returns></returns>
[DisplayName("获取所有接口/动态API")]
public List<ApiOutput> GetApiList()
{
var apiList = new List<ApiOutput>();
foreach (var item in _apiProvider.ApiDescriptionGroups.Items)
{
foreach (var apiDescription in item.Items)
{
var displayName = apiDescription.TryGetMethodInfo(out MethodInfo apiMethodInfo) ? apiMethodInfo.GetCustomAttribute<DisplayNameAttribute>(true)?.DisplayName : "";
apiList.Add(new ApiOutput
{
GroupName = item.GroupName,
DisplayName = displayName,
RouteName = apiDescription.RelativePath
});
}
}
return apiList;
}
}