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.
iot/projects/IoT/IdGen/Program.cs

37 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Infrastructure.Extensions;
using System;
namespace IdGen
{
internal class Program
{
private static void Main(string[] args)
{
Console.WriteLine("物联网设备程序授权码生成工具:");
Console.WriteLine($"当前设备编号:{(Helper.Instance.GetCPUNumber() + Helper.Instance.GetMacAddress()).Md5()}");
var message = "请输入以空格分隔的设备编号、有效天数有效天数为0则不限制使用期限";
Console.WriteLine(message);
while (true)
{
var input = Console.ReadLine();
try
{
if (input == "q")
{
break;
}
var values = input.Split(' ');
var sn = values[0];
var days = Convert.ToInt32(values[1]);
var endTime = days == 0 ? 0 : new DateTimeOffset(DateTime.UtcNow.Date.AddDays(days + 1).AddSeconds(-1)).ToUnixTimeMilliseconds();
Console.WriteLine($"{sn}-{endTime}".DESEncrypt(sn));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(message);
}
}
}
}
}