diff --git a/vol.api.sqlsugar/VOL.Core/Utilities/VierificationCodeServices.cs b/vol.api.sqlsugar/VOL.Core/Utilities/VierificationCodeServices.cs index 85d66eb83577ed7a977bdcf3e4e6fa5ea9fd4221..bcf996cf3401d53526fb8b2429c68fdde87d7d28 100644 --- a/vol.api.sqlsugar/VOL.Core/Utilities/VierificationCodeServices.cs +++ b/vol.api.sqlsugar/VOL.Core/Utilities/VierificationCodeServices.cs @@ -2,25 +2,11 @@ using System; using System.IO; using System.Linq; -using System.Runtime.InteropServices; namespace VOL.Core.Utilities { public static class VierificationCodeServices - { //验证码字体集合 - private static readonly string[] fonts = null; - - static VierificationCodeServices() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - fonts = new string[] { "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "宋体" }; - } - else - { - fonts = new string[] { "Arial", "Arial", "宋体", "宋体" }; - } - } + { private static readonly SKColor[] colors = { SKColors.Black, SKColors.Green, SKColors.Brown }; @@ -47,8 +33,10 @@ namespace VOL.Core.Utilities for (int i = 0; i < code.Length; i++) { pen.Color = random.GetRandom(colors);//随机颜色索引值 - - pen.Typeface = SKTypeface.FromFamilyName(random.GetRandom(fonts), 700, 20, SKFontStyleSlant.Italic);//配置字体 + //获取字体 + var fontPath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "font", "songti.ttf"); + pen.Typeface = SKTypeface.FromFile(fontPath); + //pen.Typeface = SKTypeface.FromFamilyName(random.GetRandom(fonts), 700, 20, SKFontStyleSlant.Italic);//配置字体 var point = new SKPoint() { X = i * 16, @@ -89,26 +77,5 @@ namespace VOL.Core.Utilities } return bitmap.ToBase64String(SKEncodedImageFormat.Png); } - - //public static T GetRandom(this Random random, T[] tArray) - //{ - // if (random == null) random = new Random(); - // return tArray[random.Next(tArray.Length)]; - //} - - /// - /// SKBitmap转Base64String - /// - /// - /// - /// - //public static string ToBase64String(this SKBitmap bitmap, SKEncodedImageFormat format) - //{ - // using var memStream = new MemoryStream(); - // using var wstream = new SKManagedWStream(memStream); - // bitmap.Encode(wstream, format, 32); - // memStream.TryGetBuffer(out ArraySegment buffer); - // return $"{Convert.ToBase64String(buffer.Array, 0, (int)memStream.Length)}"; - //} } } \ No newline at end of file diff --git a/vol.api.sqlsugar/VOL.WebApi/VOL.WebApi.csproj b/vol.api.sqlsugar/VOL.WebApi/VOL.WebApi.csproj index 7c228344d58ee79713038eb6f5f79002daa47f43..d553867328ccaa0a2e3e86dc55bec5a7f975c40f 100644 --- a/vol.api.sqlsugar/VOL.WebApi/VOL.WebApi.csproj +++ b/vol.api.sqlsugar/VOL.WebApi/VOL.WebApi.csproj @@ -40,5 +40,11 @@ + + + Always + + + diff --git a/vol.api.sqlsugar/VOL.WebApi/wwwroot/font/songti.ttf b/vol.api.sqlsugar/VOL.WebApi/wwwroot/font/songti.ttf new file mode 100644 index 0000000000000000000000000000000000000000..2b0c91f2b93c9e3e2913722c6bd01413c894ba8d Binary files /dev/null and b/vol.api.sqlsugar/VOL.WebApi/wwwroot/font/songti.ttf differ diff --git a/vol.api/VOL.Core/Utilities/VierificationCodeServices.cs b/vol.api/VOL.Core/Utilities/VierificationCodeServices.cs index 85d66eb83577ed7a977bdcf3e4e6fa5ea9fd4221..bcf996cf3401d53526fb8b2429c68fdde87d7d28 100644 --- a/vol.api/VOL.Core/Utilities/VierificationCodeServices.cs +++ b/vol.api/VOL.Core/Utilities/VierificationCodeServices.cs @@ -2,25 +2,11 @@ using System; using System.IO; using System.Linq; -using System.Runtime.InteropServices; namespace VOL.Core.Utilities { public static class VierificationCodeServices - { //验证码字体集合 - private static readonly string[] fonts = null; - - static VierificationCodeServices() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - fonts = new string[] { "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "宋体" }; - } - else - { - fonts = new string[] { "Arial", "Arial", "宋体", "宋体" }; - } - } + { private static readonly SKColor[] colors = { SKColors.Black, SKColors.Green, SKColors.Brown }; @@ -47,8 +33,10 @@ namespace VOL.Core.Utilities for (int i = 0; i < code.Length; i++) { pen.Color = random.GetRandom(colors);//随机颜色索引值 - - pen.Typeface = SKTypeface.FromFamilyName(random.GetRandom(fonts), 700, 20, SKFontStyleSlant.Italic);//配置字体 + //获取字体 + var fontPath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "font", "songti.ttf"); + pen.Typeface = SKTypeface.FromFile(fontPath); + //pen.Typeface = SKTypeface.FromFamilyName(random.GetRandom(fonts), 700, 20, SKFontStyleSlant.Italic);//配置字体 var point = new SKPoint() { X = i * 16, @@ -89,26 +77,5 @@ namespace VOL.Core.Utilities } return bitmap.ToBase64String(SKEncodedImageFormat.Png); } - - //public static T GetRandom(this Random random, T[] tArray) - //{ - // if (random == null) random = new Random(); - // return tArray[random.Next(tArray.Length)]; - //} - - /// - /// SKBitmap转Base64String - /// - /// - /// - /// - //public static string ToBase64String(this SKBitmap bitmap, SKEncodedImageFormat format) - //{ - // using var memStream = new MemoryStream(); - // using var wstream = new SKManagedWStream(memStream); - // bitmap.Encode(wstream, format, 32); - // memStream.TryGetBuffer(out ArraySegment buffer); - // return $"{Convert.ToBase64String(buffer.Array, 0, (int)memStream.Length)}"; - //} } } \ No newline at end of file diff --git a/vol.api/VOL.WebApi/VOL.WebApi.csproj b/vol.api/VOL.WebApi/VOL.WebApi.csproj index 1f12e77fa98259cd0807aefe0816749c622765a0..387a7e2aaf3ec19298c85b88307bd51a5a6852d8 100644 --- a/vol.api/VOL.WebApi/VOL.WebApi.csproj +++ b/vol.api/VOL.WebApi/VOL.WebApi.csproj @@ -46,5 +46,11 @@ + + + Always + + + diff --git a/vol.api/VOL.WebApi/wwwroot/font/songti.ttf b/vol.api/VOL.WebApi/wwwroot/font/songti.ttf new file mode 100644 index 0000000000000000000000000000000000000000..2b0c91f2b93c9e3e2913722c6bd01413c894ba8d Binary files /dev/null and b/vol.api/VOL.WebApi/wwwroot/font/songti.ttf differ