mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 18:03:27 +08:00
【升级】升级Asp.Net 6.0.11 到 Asp.Net 7.0.0
【升级】升级所有组建包,移除一些不用或者版本弃用的组建。 【优化】优化升级npoi最新版后,出现导出数据兼容性的问题。 【优化】使用新的【NLog.Database】nlog数据库链接组件,解决nlog升级到5.x以后版本记录到数据库日志失败的问题。
This commit is contained in:
@@ -29,11 +29,6 @@ using CoreCms.Net.WeChat.Service.Options;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SixLabors.Fonts;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Drawing.Processing;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SKIT.FlurlHttpClient.Wechat.Api;
|
||||
using SKIT.FlurlHttpClient.Wechat.Api.Models;
|
||||
|
||||
@@ -113,44 +108,6 @@ namespace CoreCms.Net.Services
|
||||
|
||||
#endregion
|
||||
|
||||
#region 海报分享
|
||||
/// <summary>
|
||||
/// 海报分享
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="userShareCode"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="parameter"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<WebApiCallBack> PosterShare(int client, int page, int userShareCode, string url, JObject parameter)
|
||||
{
|
||||
//获取分享代码
|
||||
var res = GetCode(client, page, userShareCode, url, parameter);
|
||||
if (!res.status)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
//如果不是商品和拼团
|
||||
if (page != (int)GlobalEnumVars.UrlSharePageType.PinTuan &&
|
||||
page != (int)GlobalEnumVars.UrlSharePageType.Goods &&
|
||||
page != (int)GlobalEnumVars.UrlSharePageType.Seckill &&
|
||||
page != (int)GlobalEnumVars.UrlSharePageType.Solitaire &&
|
||||
page != (int)GlobalEnumVars.UrlSharePageType.Group)
|
||||
{
|
||||
//走二维码分享
|
||||
return await getQr(url, res.otherData.ToString(), client);
|
||||
}
|
||||
//生成海报图片
|
||||
|
||||
var userId = UserHelper.GetUserIdByShareCode(userShareCode);
|
||||
var user = await _userServices.QueryByClauseAsync(p => p.id == userId);
|
||||
|
||||
var result = await Poster(url, res.otherData.ToString(), client, user);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 页面分享UrlShare
|
||||
/// <summary>
|
||||
/// 页面分享
|
||||
@@ -790,260 +747,5 @@ namespace CoreCms.Net.Services
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 渲染并生成海报图片
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<WebApiCallBack> Poster(string url, string code, int client, CoreCmsUser user)
|
||||
{
|
||||
var jm = new WebApiCallBack() { status = false, msg = "海报生成失败0" };
|
||||
|
||||
|
||||
var fileNameStr = CommonHelper.Md5For32(url + code + client) + CommonHelper.Msectime();
|
||||
//QrCode 根目录
|
||||
var dir = "/static/poster/";
|
||||
//文件虚拟目录
|
||||
var fileName = dir + fileNameStr + ".jpg";
|
||||
//文件硬地址
|
||||
var qrCodeDir = _webHostEnvironment.WebRootPath + dir;
|
||||
//QrCode 根目录
|
||||
var pathFileName = qrCodeDir + fileNameStr + ".jpg";
|
||||
|
||||
//QrCode 根目录
|
||||
if (File.Exists(pathFileName))
|
||||
{
|
||||
//有这个二维码了
|
||||
jm.status = true;
|
||||
jm.msg = "海报获取成功";
|
||||
jm.data = _appInterFaceUrl + fileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
//去生成
|
||||
var res = de_url(code);
|
||||
if (!res.status)
|
||||
{
|
||||
jm.msg = "海报生成失败1";
|
||||
return res;
|
||||
}
|
||||
|
||||
var qrResult = await getQr(url, code, client);
|
||||
if (!qrResult.status)
|
||||
{
|
||||
jm.msg = "海报生成失败2";
|
||||
return qrResult;
|
||||
}
|
||||
|
||||
var mkResult = await DoMark(res.data, qrResult.otherData.ToString(), fileName, user);
|
||||
if (mkResult)
|
||||
{
|
||||
jm.status = true;
|
||||
jm.msg = "海报生成成功";
|
||||
jm.data = _appInterFaceUrl + fileName;
|
||||
}
|
||||
jm.otherData = mkResult;
|
||||
}
|
||||
return jm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绘制图片
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="otherData">生成的二维码图片地址</param>
|
||||
/// <param name="fileNameStr">海报文件名称</param>
|
||||
/// <param name="user">用户信息</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DoMark(object data, string otherData, string fileNameStr, CoreCmsUser user)
|
||||
{
|
||||
var fileName = fileNameStr;
|
||||
|
||||
//文件硬地址
|
||||
var savePath = _webHostEnvironment.WebRootPath + "/static/poster/";
|
||||
var qrCodeDir = _webHostEnvironment.WebRootPath + "/static/qrCode/weChat/" + otherData;
|
||||
//如果文件夹不存在,则创建文件夹
|
||||
if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath);
|
||||
|
||||
//获取数据来源
|
||||
var dataObj = JObject.FromObject(data);
|
||||
if (!dataObj.ContainsKey("page") || dataObj["page"].ObjectToInt(0) <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//2商品详情页,3拼团详情页
|
||||
var page = dataObj["page"].ObjectToInt(0);
|
||||
if (page is (int)GlobalEnumVars.UrlSharePageType.Goods or (int)GlobalEnumVars.UrlSharePageType.PinTuan or (int)GlobalEnumVars.UrlSharePageType.Seckill)
|
||||
{
|
||||
if (dataObj.ContainsKey("params"))
|
||||
{
|
||||
var paramsObj = JObject.FromObject(dataObj["params"]);
|
||||
if (!paramsObj.ContainsKey("goodsId"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var goodId = paramsObj["goodsId"].ObjectToInt();
|
||||
var goodModel = await _goodsServices.GetGoodsDetail(goodId);
|
||||
if (goodModel != null)
|
||||
{
|
||||
var images = goodModel.images.Split(",");
|
||||
if (images.Any())
|
||||
{
|
||||
var image = images[0];
|
||||
//创建一个背景宽度为400X600的底图
|
||||
using var imageTemple = new SixLabors.ImageSharp.Image<Rgba32>(400, 600);
|
||||
//设置底图的背景色为白色
|
||||
imageTemple.Mutate(x => x.BackgroundColor(SixLabors.ImageSharp.Color.White));
|
||||
//绘制商品图片(网络下载图片)
|
||||
HttpClient client = new HttpClient();
|
||||
HttpResponseMessage response = await client.GetAsync(image);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var stream = await response.Content.ReadAsStreamAsync();
|
||||
//载入下载的图片流2
|
||||
var imageThumbnail = await SixLabors.ImageSharp.Image.LoadAsync(stream);
|
||||
//将下载的图片压缩至400X400
|
||||
imageThumbnail.Mutate(x =>
|
||||
{
|
||||
x.Resize(400, 400);
|
||||
});
|
||||
//将商品大图合并到背景图上
|
||||
imageTemple.Mutate(x => x.DrawImage(imageThumbnail, new SixLabors.ImageSharp.Point(0, 0), 1));
|
||||
//将用户的分享二维码合并大背景图上
|
||||
var imageQrcode = await SixLabors.ImageSharp.Image.LoadAsync(qrCodeDir);
|
||||
//将二维码缩略至120X120
|
||||
imageQrcode.Mutate(x =>
|
||||
{
|
||||
x.Resize(120, 120);
|
||||
});
|
||||
//将二维码图片合并到背景图上
|
||||
imageTemple.Mutate(x => x.DrawImage(imageQrcode, new SixLabors.ImageSharp.Point(275, 420), 1));
|
||||
//构建字体//装载字体(ttf)(而且字体一定要支持简体中文的)
|
||||
var fonts = new FontCollection();
|
||||
SixLabors.Fonts.FontFamily fontFamily = fonts.Install(_webHostEnvironment.WebRootPath + "/fonts/SourceHanSansK-Normal.ttf");
|
||||
//商品名称可能较长,设置为多行文本输出
|
||||
SixLabors.Fonts.Font titleFont = new SixLabors.Fonts.Font(fontFamily, 20, SixLabors.Fonts.FontStyle.Regular);
|
||||
//多行文本输出
|
||||
var textOptions = new TextOptions()
|
||||
{
|
||||
ApplyKerning = true,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
WrapTextWidth = 230
|
||||
};
|
||||
var graphicsOptions = new GraphicsOptions()
|
||||
{
|
||||
Antialias = true
|
||||
};
|
||||
//沿着行尾的绕行路径绘制文本
|
||||
var options = new SixLabors.ImageSharp.Drawing.Processing.DrawingOptions
|
||||
{
|
||||
GraphicsOptions = graphicsOptions,
|
||||
TextOptions = textOptions
|
||||
};
|
||||
//开始绘制商品名称
|
||||
imageTemple.Mutate(ctx => ctx.DrawText(options, goodModel.name, titleFont, SixLabors.ImageSharp.Color.Red, new SixLabors.ImageSharp.PointF(10, 450)));
|
||||
//绘制商品金额
|
||||
SixLabors.Fonts.Font moneyFont = new SixLabors.Fonts.Font(fontFamily, 18);
|
||||
//获取该文件绘制所需的大小
|
||||
imageTemple.Mutate(ctx => ctx.DrawText("¥" + goodModel.price, moneyFont, SixLabors.ImageSharp.Color.Crimson, new SixLabors.ImageSharp.PointF(10, 410)));
|
||||
//绘制提示语
|
||||
SixLabors.Fonts.Font tipsFont = new SixLabors.Fonts.Font(fontFamily, 10);
|
||||
imageTemple.Mutate(ctx => ctx.DrawText("扫描或长按识别二维码", tipsFont, SixLabors.ImageSharp.Color.Black, new SixLabors.ImageSharp.PointF(283, 555)));
|
||||
//载入流存储在到文件
|
||||
await imageTemple.SaveAsync(_webHostEnvironment.WebRootPath + fileName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (page == (int)GlobalEnumVars.UrlSharePageType.Solitaire)
|
||||
{
|
||||
if (dataObj.ContainsKey("params"))
|
||||
{
|
||||
var paramsObj = JObject.FromObject(dataObj["params"]);
|
||||
if (!paramsObj.ContainsKey("id"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var id = paramsObj["id"].ObjectToInt();
|
||||
var solitaireModel = await _solitaireServices.QueryByClauseAsync(p => p.id == id);
|
||||
if (solitaireModel != null && !string.IsNullOrEmpty(solitaireModel.thumbnail))
|
||||
{
|
||||
//创建一个背景宽度为400X600的底图
|
||||
using var imageTemple = new SixLabors.ImageSharp.Image<Rgba32>(400, 600);
|
||||
//设置底图的背景色为白色
|
||||
imageTemple.Mutate(x => x.BackgroundColor(SixLabors.ImageSharp.Color.White));
|
||||
//绘制商品图片(网络下载图片)
|
||||
HttpClient client = new HttpClient();
|
||||
HttpResponseMessage response = await client.GetAsync(solitaireModel.thumbnail);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var stream = await response.Content.ReadAsStreamAsync();
|
||||
//载入下载的图片流
|
||||
var imageThumbnail = await SixLabors.ImageSharp.Image.LoadAsync(stream);
|
||||
//将下载的图片压缩至400X400
|
||||
imageThumbnail.Mutate(x =>
|
||||
{
|
||||
x.Resize(400, 400);
|
||||
});
|
||||
//将商品大图合并到背景图上
|
||||
imageTemple.Mutate(x => x.DrawImage(imageThumbnail, new SixLabors.ImageSharp.Point(0, 0), 1));
|
||||
//将用户的分享二维码合并大背景图上
|
||||
var imageQrcode = await SixLabors.ImageSharp.Image.LoadAsync(qrCodeDir);
|
||||
//将二维码缩略至120X120
|
||||
imageQrcode.Mutate(x =>
|
||||
{
|
||||
x.Resize(120, 120);
|
||||
});
|
||||
//将二维码图片合并到背景图上
|
||||
imageTemple.Mutate(x => x.DrawImage(imageQrcode, new SixLabors.ImageSharp.Point(275, 420), 1));
|
||||
//构建字体//装载字体(ttf)(而且字体一定要支持简体中文的)
|
||||
var fonts = new FontCollection();
|
||||
SixLabors.Fonts.FontFamily fontFamily = fonts.Install(_webHostEnvironment.WebRootPath + "/fonts/SourceHanSansK-Normal.ttf");
|
||||
//绘制商品名称
|
||||
SixLabors.Fonts.Font titleFont = new SixLabors.Fonts.Font(fontFamily, 20, SixLabors.Fonts.FontStyle.Regular);
|
||||
//商品名称可能较长,设置为多行文本输出
|
||||
var textOptions = new TextOptions()
|
||||
{
|
||||
ApplyKerning = true,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
WrapTextWidth = 230
|
||||
};
|
||||
var graphicsOptions = new GraphicsOptions()
|
||||
{
|
||||
Antialias = true
|
||||
};
|
||||
//沿着行尾的绕行路径绘制文本
|
||||
var options = new SixLabors.ImageSharp.Drawing.Processing.DrawingOptions
|
||||
{
|
||||
GraphicsOptions = graphicsOptions,
|
||||
TextOptions = textOptions
|
||||
};
|
||||
//开始绘制商品名称
|
||||
imageTemple.Mutate(ctx => ctx.DrawText(options, solitaireModel.title, titleFont, SixLabors.ImageSharp.Color.Red, new SixLabors.ImageSharp.PointF(10, 450)));
|
||||
//绘制商品金额
|
||||
SixLabors.Fonts.Font moneyFont = new SixLabors.Fonts.Font(fontFamily, 18);
|
||||
//获取该文件绘制所需的大小
|
||||
//var size = TextMeasurer.Measure(moneyText, new RendererOptions(moneyFont));
|
||||
imageTemple.Mutate(ctx => ctx.DrawText("火热接龙中", moneyFont, SixLabors.ImageSharp.Color.Crimson, new SixLabors.ImageSharp.PointF(10, 410)));
|
||||
//绘制提示语
|
||||
SixLabors.Fonts.Font tipsFont = new SixLabors.Fonts.Font(fontFamily, 10);
|
||||
imageTemple.Mutate(ctx => ctx.DrawText("扫描或长按识别二维码", tipsFont, SixLabors.ImageSharp.Color.Black, new SixLabors.ImageSharp.PointF(283, 555)));
|
||||
|
||||
//载入流存储在到文件
|
||||
await imageTemple.SaveAsync(_webHostEnvironment.WebRootPath + fileName);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user