using System; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; namespace SimApi.Helpers { public static class SimApiUtil { /// /// 检测手机号是否正确 /// /// 手机号码 /// public static bool CheckCell(string cell) { var regex = new Regex("^1[34578]\\d{9}$"); return regex.IsMatch(cell); } /// /// MD5加密字符串 /// /// 源字符串 /// 加密结果"x2"结果为32位,"x3"结果为48位,"x4"结果为64位 /// public static string Md5(string source, string mode = "x2") { byte[] sor = Encoding.UTF8.GetBytes(source); MD5 md5 = MD5.Create(); byte[] result = md5.ComputeHash(sor); StringBuilder strbul = new StringBuilder(40); for (int i = 0; i < result.Length; i++) { strbul.Append(result[i].ToString(mode)); } return strbul.ToString(); } public static void Log(string message, string type = "Information") { Console.WriteLine($"[ SimApi ][ {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff")} ][ {type} ]"); Console.WriteLine(message); Console.WriteLine(""); } } }