update:去除生成二维码图片验证添加二维码跳转时间戳和签名参数

This commit is contained in:
2021-03-02 17:36:10 +08:00
parent d6617f47c0
commit 8214973184
6 changed files with 50 additions and 61 deletions

View File

@@ -11,6 +11,11 @@ using MediatR;
using QRCodeService.Application.Queries;
using QRCodeService.Application.Commands;
using QRCodeService.Infrastructure.Middlewares;
using QRCodeService.Options;
using QRCoder;
using System.Drawing;
using System.IO;
using Microsoft.Extensions.Options;
namespace QRCodeService.Controllers.Api
{
@@ -20,22 +25,31 @@ namespace QRCodeService.Controllers.Api
{
readonly IMediator mediator;
readonly ILinkQueries linkQueries;
readonly IOptions<ServiceOption> option;
public LinkController(IMediator mediator, ILinkQueries queries)
public LinkController(IMediator mediator, ILinkQueries queries, IOptions<ServiceOption> option)
{
this.mediator = mediator;
this.linkQueries = queries;
this.option = option;
}
[Route("{shortCode}")]
[Route("i/{shortCode}/")]
[HttpGet]
public async Task<IActionResult> Get(string shortCode)
public async Task<IActionResult> GetQrCode(string shortCode,int img=0)
{
var link = await linkQueries.GetLinkAsync(shortCode);
if (link == null)
{
return NotFound();
}
return Ok(link);
var qrCodeGenerator = new QRCodeGenerator();
var data = qrCodeGenerator.CreateQrCode($"{option.Value.BaseUrl}r/{link.ShortCode}", QRCodeGenerator.ECCLevel.Q);
var qrCode = new QRCode(data);
using (var stream = new MemoryStream())
{
qrCode.GetGraphic(10, Color.Black, Color.White, null, 15, 6, false).Save(stream, System.Drawing.Imaging.ImageFormat.Png);
return File(stream.ToArray(), "image/png");
}
}
[CheckSign(typeof(CreateLinkModel))]