Merge branch 'Test_IRC_Net8' of https://gitea.frp.extimaging.com/XCKJ/irc-netcore-api into Test_IRC_Net8
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
commit
2ce0306311
|
@ -2349,6 +2349,22 @@
|
|||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.HIRActivateService.GetAuthorizationCodeInfo(System.String,Microsoft.Extensions.Options.IOptionsMonitor{IRaCIS.Application.Contracts.SystemHospitalOption})">
|
||||
<summary>
|
||||
获取授权码明文信息
|
||||
</summary>
|
||||
<param name="authorizationCode"></param>
|
||||
<param name="_hospitalOption"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.HIRActivateService.GetTrialActivationCode(System.String,Microsoft.Extensions.Options.IOptionsMonitor{IRaCIS.Core.Domain.Share.ServiceVerifyConfigOption})">
|
||||
<summary>
|
||||
获取项目激活码
|
||||
</summary>
|
||||
<param name="decodedText"></param>
|
||||
<param name="_basicSystemConfigConfig"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.OAuthService.TestClientCredentialsAsync">
|
||||
<summary>
|
||||
测试客户端凭证代码
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
using IRaCIS.Application.Contracts;
|
||||
using IRaCIS.Core.Infrastructure.Encryption;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.Application.Service;
|
||||
|
||||
public class HIRActivateService : ServiceBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 获取授权码明文信息
|
||||
/// </summary>
|
||||
/// <param name="authorizationCode"></param>
|
||||
/// <param name="_hospitalOption"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
public async Task<IResponseOutput> GetAuthorizationCodeInfo(string authorizationCode, [FromServices] IOptionsMonitor<SystemHospitalOption> _hospitalOption)
|
||||
{
|
||||
// 解密 Base64 编码后的数据
|
||||
byte[] base64DecodedBytes = Convert.FromBase64String(authorizationCode);
|
||||
string decodedText = System.Text.Encoding.UTF8.GetString(base64DecodedBytes);
|
||||
|
||||
|
||||
var authInfo = JsonConvert.DeserializeObject<TrialAuthorizationInfo>(decodedText);
|
||||
|
||||
if (authInfo == null)
|
||||
{
|
||||
return ResponseOutput.NotOk("不能解析该项目授权码");
|
||||
}
|
||||
|
||||
return ResponseOutput.Ok(decodedText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取项目激活码
|
||||
/// </summary>
|
||||
/// <param name="_basicSystemConfigConfig"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[RoutePattern(HttpMethod = "get")]
|
||||
public async Task<IResponseOutput> GetTrialActivationCode(TrialAuthorizationInfo authorizationInfo, [FromServices] IOptionsMonitor<ServiceVerifyConfigOption> _basicSystemConfigConfig)
|
||||
{
|
||||
|
||||
|
||||
if (authorizationInfo != null)
|
||||
{
|
||||
//一周内激活
|
||||
authorizationInfo.ActiveDeadLineDate = DateTime.Now.Date.AddDays(8).AddSeconds(-1);
|
||||
|
||||
var info = AesEncryption.Encrypt($"{JsonConvert.SerializeObject(authorizationInfo)}", "HIR_System_AES_Key_Info", "Trial_AuthorizationEncrypt");
|
||||
|
||||
Console.WriteLine("HIR_System_AES_Key_Info".PadRight(32, '0').Substring(0, 32) + " " + "Trial_AuthorizationEncrypt".PadRight(16, '0').Substring(0, 16));
|
||||
|
||||
//var dd = AesEncryption.Decrypt(info, "HIR_System_AES_Key_Info", "Trial_AuthorizationEncrypt");
|
||||
|
||||
return ResponseOutput.Ok(info);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ResponseOutput.NotOk("激活码解密文本信息有误");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class TrialAuthorizationInfo
|
||||
{
|
||||
public Guid TrialId { get; set; }
|
||||
public Guid CreateUserId { get; set; }
|
||||
public string TrialCode { get; set; }
|
||||
|
||||
public string HospitalName { get; set; }
|
||||
|
||||
public string HospitalCode { get; set; }
|
||||
|
||||
public int PurchaseDuration { get; set; }
|
||||
|
||||
|
||||
|
||||
public List<CriterionType> CriterionTypeList { get; set; }
|
||||
|
||||
public DateTime? AuthorizationDeadLineDate { get; set; }
|
||||
|
||||
public DateTime? ActiveDeadLineDate { get; set; }
|
||||
|
||||
public DateTime? ActiveTime { get; set; }
|
||||
|
||||
}
|
||||
|
|
@ -44,10 +44,18 @@ public class AesEncryption
|
|||
}
|
||||
|
||||
// AES 加密(带 IV)
|
||||
/// <summary>
|
||||
/// AES 密钥的长度必须是以下之一:128 位(16 字节)192 位(24 字节)256 位(32 字节)
|
||||
/// IV must be 16 bytes
|
||||
/// </summary>
|
||||
/// <param name="plainText"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="iv"></param>
|
||||
/// <returns></returns>
|
||||
public static string Encrypt(string plainText, string key, string iv)
|
||||
{
|
||||
var keyBytes = Encoding.UTF8.GetBytes(key);
|
||||
var ivBytes = Encoding.UTF8.GetBytes(iv);
|
||||
var keyBytes = Encoding.UTF8.GetBytes(key.PadRight(32, '0').Substring(0, 32));
|
||||
var ivBytes = Encoding.UTF8.GetBytes(iv.PadRight(16, '0').Substring(0, 16));
|
||||
|
||||
// 使用 AES 引擎 + PKCS7 填充 + CBC 模式
|
||||
var engine = new AesEngine();
|
||||
|
@ -64,8 +72,8 @@ public class AesEncryption
|
|||
// AES 解密(带 IV)
|
||||
public static string Decrypt(string encryptedText, string key, string iv)
|
||||
{
|
||||
var keyBytes = Encoding.UTF8.GetBytes(key);
|
||||
var ivBytes = Encoding.UTF8.GetBytes(iv);
|
||||
var keyBytes = Encoding.UTF8.GetBytes(key.PadRight(32, '0').Substring(0, 32));
|
||||
var ivBytes = Encoding.UTF8.GetBytes(iv.PadRight(16, '0').Substring(0, 16));
|
||||
var cipherBytes = Convert.FromBase64String(encryptedText);
|
||||
|
||||
// 使用 AES 引擎 + PKCS7 填充 + CBC 模式
|
||||
|
|
Loading…
Reference in New Issue