2024-05-24 10:22:01 +00:00
|
|
|
|
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
|
|
|
|
|
//
|
|
|
|
|
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
|
|
|
|
|
|
|
|
|
|
using Admin.NET.Application.Entity;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Admin.NET.Application.Utils;
|
|
|
|
|
internal class CodeHelper
|
|
|
|
|
{
|
|
|
|
|
// '序号',
|
|
|
|
|
//'随机数',
|
|
|
|
|
//'固定字符串',
|
|
|
|
|
//'随机字母数字',
|
|
|
|
|
//'随机大小写字母',
|
|
|
|
|
//'随机大写字母',
|
|
|
|
|
//'随机小写字母',
|
|
|
|
|
public static string GetCodeRandom(int codeLen)
|
|
|
|
|
{
|
|
|
|
|
var result = "";
|
|
|
|
|
var format = "";
|
|
|
|
|
var max = "";
|
|
|
|
|
for (int i = 0; i < codeLen; i++)
|
|
|
|
|
{
|
|
|
|
|
format += "0";
|
|
|
|
|
max += "9";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var random = new Random();
|
|
|
|
|
result = random.Next(Convert.ToInt32(max)).ToString(format);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
public static string GetCodeLetterNum(int codeLen)
|
|
|
|
|
{
|
|
|
|
|
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < codeLen; i++)
|
|
|
|
|
{
|
|
|
|
|
stringBuilder.Append(chars[random.Next(chars.Length)]);
|
|
|
|
|
}
|
|
|
|
|
return stringBuilder.ToString();
|
|
|
|
|
}
|
|
|
|
|
public static string GetCodeLetter(int codeLen)
|
|
|
|
|
{
|
|
|
|
|
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < codeLen; i++)
|
|
|
|
|
{
|
|
|
|
|
stringBuilder.Append(chars[random.Next(chars.Length)]);
|
|
|
|
|
}
|
|
|
|
|
return stringBuilder.ToString();
|
|
|
|
|
}
|
2024-06-24 10:21:52 +00:00
|
|
|
|
|
|
|
|
|
public static string GetCode(string? barCode, string? qrCode)
|
|
|
|
|
{
|
|
|
|
|
var code = string.IsNullOrEmpty(barCode) ? qrCode : barCode;
|
2024-06-26 10:33:33 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(code) && code.Contains("?code="))
|
2024-06-24 10:21:52 +00:00
|
|
|
|
{
|
|
|
|
|
code = code.Split('=').LastOrDefault();
|
|
|
|
|
}
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2024-05-24 10:22:01 +00:00
|
|
|
|
public static string GetCodeUpLetter(int codeLen)
|
|
|
|
|
{
|
|
|
|
|
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < codeLen; i++)
|
|
|
|
|
{
|
|
|
|
|
stringBuilder.Append(chars[random.Next(chars.Length)]);
|
|
|
|
|
}
|
|
|
|
|
return stringBuilder.ToString();
|
|
|
|
|
}
|
|
|
|
|
public static string GetCodeDownLetter(int codeLen)
|
|
|
|
|
{
|
|
|
|
|
const string chars = "abcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < codeLen; i++)
|
|
|
|
|
{
|
|
|
|
|
stringBuilder.Append(chars[random.Next(chars.Length)]);
|
|
|
|
|
}
|
|
|
|
|
return stringBuilder.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|