From 5234d3358b223be0e5217866b13459f1eaf16b5f Mon Sep 17 00:00:00 2001 From: zhangqi <2794379662@qq.com> Date: Wed, 3 Mar 2021 16:53:55 +0800 Subject: [PATCH] =?UTF-8?q?update:=E7=AE=80=E5=8C=96=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QRCodeService/Controllers/Api/LinkController.cs | 4 ++-- QRCodeService/Controllers/RedirectController.cs | 5 +++-- .../Middlewares/CheckSignAttribute.cs | 5 +---- .../Middlewares/CheckSignMiddleware.cs | 11 +++++------ QRCodeService/QRCodeService.csproj | 1 + QRCodeService/Startup.cs | 2 +- QRCodeService/Views/Redirect/Index.cshtml | 17 ++++++++++++++--- 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/QRCodeService/Controllers/Api/LinkController.cs b/QRCodeService/Controllers/Api/LinkController.cs index 27da907..b904eb3 100644 --- a/QRCodeService/Controllers/Api/LinkController.cs +++ b/QRCodeService/Controllers/Api/LinkController.cs @@ -52,7 +52,7 @@ namespace QRCodeService.Controllers.Api } } - [CheckSign(typeof(CreateLinkModel))] + [CheckSign] [HttpPost] public async Task Create(CreateLinkModel input) { @@ -62,7 +62,7 @@ namespace QRCodeService.Controllers.Api { return BadRequest(); } - return Ok(link.ShortCode); + return Created($"{option.Value.BaseUrl}r/{link.ShortCode}",link.ShortCode); } } } diff --git a/QRCodeService/Controllers/RedirectController.cs b/QRCodeService/Controllers/RedirectController.cs index 1dfb0d5..7da6f51 100644 --- a/QRCodeService/Controllers/RedirectController.cs +++ b/QRCodeService/Controllers/RedirectController.cs @@ -37,11 +37,12 @@ namespace QRCodeService.Controllers } var t = DateTime.Now.ToString("yyyyMMddHHmmss"); var sign = BitConverter.ToString($"{t}{app.Appkey}".ToMD5()).Replace("-", ""); - link.FullUrl = QueryHelpers.AddQueryString(link.FullUrl, new Dictionary { + ViewBag.FullUrl = QueryHelpers.AddQueryString(link.FullUrl, new Dictionary { { "s",sign }, { "t",t} }); - return View(link); + + return View(); } } } diff --git a/QRCodeService/Infrastructure/Middlewares/CheckSignAttribute.cs b/QRCodeService/Infrastructure/Middlewares/CheckSignAttribute.cs index 11f01f3..68900eb 100644 --- a/QRCodeService/Infrastructure/Middlewares/CheckSignAttribute.cs +++ b/QRCodeService/Infrastructure/Middlewares/CheckSignAttribute.cs @@ -8,11 +8,8 @@ namespace QRCodeService.Infrastructure.Middlewares { public class CheckSignAttribute:Attribute { - public Type ModelType { get; set; } - - public CheckSignAttribute(Type type) + public CheckSignAttribute() { - ModelType = type; } } } diff --git a/QRCodeService/Infrastructure/Middlewares/CheckSignMiddleware.cs b/QRCodeService/Infrastructure/Middlewares/CheckSignMiddleware.cs index 6b5feef..d0d3570 100644 --- a/QRCodeService/Infrastructure/Middlewares/CheckSignMiddleware.cs +++ b/QRCodeService/Infrastructure/Middlewares/CheckSignMiddleware.cs @@ -40,11 +40,10 @@ namespace QRCodeService.Infrastructure.Middlewares var requestReader = new StreamReader(context.Request.Body); var requestContent = await requestReader.ReadToEndAsync(); - var param = JsonSerializer.Deserialize(requestContent,attribute.ModelType); - var props = attribute.ModelType.GetProperties(); - var appid = (int)props.Single(p=>p.Name=="AppId").GetValue(param); - var time = props.Single(p => p.Name == "Time").GetValue(param) as string; - var sign = props.Single(p => p.Name == "Sign").GetValue(param) as string; + var param = JsonSerializer.Deserialize>(requestContent); + var appid = param.Where(kv=>kv.Key.ToLower()=="appid").Single().Value.GetInt32(); + var time = param.Where(kv=>kv.Key.ToLower()=="time").Single().Value.GetString(); + var sign = param.Where(kv=>kv.Key.ToLower()== "sign").Single().Value.GetString(); var timeDate = time.ToDate("yyyyMMddHHmmss"); if (timeDate == null||Math.Abs((timeDate.Value - DateTime.Now).TotalSeconds) > 60)//时间不同步 { @@ -60,7 +59,7 @@ namespace QRCodeService.Infrastructure.Middlewares return; } var appKey = app.Appkey; - var signStr = string.Join(null, props.Where(p => p.Name != "Sign").OrderBy(p => p.Name).Select(p => p.GetValue(param).ToString())); + var signStr = string.Join(null, param.Where(kv =>kv.Key.ToLower() != "sign").OrderBy(kv => kv.Key).Select(kv => kv.Value.ToString())); var checkSign = BitConverter.ToString( (signStr + appKey).ToMD5()).Replace("-",""); if(checkSign.ToLower() != sign.ToLower()) { diff --git a/QRCodeService/QRCodeService.csproj b/QRCodeService/QRCodeService.csproj index f641906..aa566e7 100644 --- a/QRCodeService/QRCodeService.csproj +++ b/QRCodeService/QRCodeService.csproj @@ -20,6 +20,7 @@ + all diff --git a/QRCodeService/Startup.cs b/QRCodeService/Startup.cs index 8a4f39a..058d576 100644 --- a/QRCodeService/Startup.cs +++ b/QRCodeService/Startup.cs @@ -45,7 +45,7 @@ namespace QRCodeService public void ConfigureServices(IServiceCollection services) { //ṩȴŻû - services.AddControllersWithViews(); + services.AddControllersWithViews().AddRazorRuntimeCompilation(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "QRCodeService", Version = "v1" }); diff --git a/QRCodeService/Views/Redirect/Index.cshtml b/QRCodeService/Views/Redirect/Index.cshtml index 74e80a7..86e1f8d 100644 --- a/QRCodeService/Views/Redirect/Index.cshtml +++ b/QRCodeService/Views/Redirect/Index.cshtml @@ -3,18 +3,29 @@ *@ @{ } -@model QRCodeService.Application.Queries.Link - +
loading...
\ No newline at end of file