92 lines
2.8 KiB
C#
92 lines
2.8 KiB
C#
// 大名科技(天津)有限公司版权所有 电话: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();
|
||
}
|
||
|
||
public static string GetCode(string? barCode, string? qrCode)
|
||
{
|
||
var code = string.IsNullOrEmpty(barCode) ? qrCode : barCode;
|
||
if (!string.IsNullOrEmpty(code) && code.Contains("?code="))
|
||
{
|
||
code = code.Split('=').LastOrDefault();
|
||
}
|
||
return code;
|
||
}
|
||
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();
|
||
}
|
||
}
|