using System; using System.Data; using System.Web; using System.Drawing; using System.Drawing.Imaging; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Net.Mail; using System.Net; using LitJson; using Microsoft.AspNetCore.Http; using ThoughtWorks.QRCode.Codec; using System.Linq; using System.IO; using SkiaSharp.QrCode; using SkiaSharp; namespace Common { public class Function { /// /// hmacSha1算法加密(生成长度40) /// /// 加密明文 /// 加密密钥 /// public static string hmacSha1(string encryptText, string encryptKey) { HMACSHA1 myHMACSHA1 = new HMACSHA1(Encoding.UTF8.GetBytes(encryptKey)); byte[] RstRes = myHMACSHA1.ComputeHash(Encoding.UTF8.GetBytes(encryptText)); StringBuilder EnText = new StringBuilder(); foreach (byte Byte in RstRes) { EnText.AppendFormat("{0:x2}", Byte); } return EnText.ToString(); } public static string hmacmd5(string encryptText, string encryptKey) { HMACMD5 myHMACSHA1 = new HMACMD5(Encoding.UTF8.GetBytes(encryptKey)); byte[] RstRes = myHMACSHA1.ComputeHash(Encoding.UTF8.GetBytes(encryptText)); StringBuilder EnText = new StringBuilder(); foreach (byte Byte in RstRes) { EnText.AppendFormat("{0:x2}", Byte); } return EnText.ToString(); } /// /// MD5 32位加密字符串 /// /// /// public static string MD5_32(string str) { string cl = str + "@$1212#"; string pwd = ""; MD5 md5 = MD5.Create();//实例化一个md5对像 // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择  byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl)); // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得 for (int i = 0; i < s.Length; i++) { // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符 pwd = pwd + s[i].ToString("X").ToLower().PadLeft(2, '0'); } return pwd; } public static string MD532(string str) { string cl = str; string pwd = ""; MD5 md5 = MD5.Create();//实例化一个md5对像 // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择  byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl)); // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得 for (int i = 0; i < s.Length; i++) { // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符 pwd = pwd + s[i].ToString("X").ToLower().PadLeft(2, '0'); } return pwd; } /// /// 获取MD5值 /// /// 加密的字符串 /// 返回MD5值 public static string MD5_16(string str) { return MD5_32(str).Substring(8, 16); } /// /// 写日志(错误报告) /// /// public static void WriteLog(string str) { try { string path = getPath("/log/message/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Day.ToString() + "/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } StreamWriter sw = File.AppendText(path + "content.log"); sw.WriteLine(str); sw.Flush(); sw.Dispose(); } catch { } } /// /// 写日志(错误报告) /// /// public static void WriteLog(string str, string filename) { try { string path = getPath("/log/" + filename + "/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Day.ToString() + "/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } StreamWriter sw = File.AppendText(path + "content.log"); sw.WriteLine(str); sw.Flush(); sw.Dispose(); } catch { } } public static void WriteLog(string path_str, string file_name, string page_content) { try { string path = getPath(path_str); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } StreamWriter sw = File.AppendText(path + "/" + file_name); sw.WriteLine(page_content); sw.Flush(); sw.Dispose(); } catch { } } /// /// 过滤html代码 /// /// public static string NoHTML(string Htmlstring) //去除HTML标记 { if (Htmlstring == null || Htmlstring == string.Empty) { return ""; } Htmlstring = Regex.Replace(Htmlstring, @"]*?>.*?", "", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase); //Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"