Update API
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Entity.Interface;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@@ -7,6 +8,7 @@ using WebAPI.Logics.Interface;
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
public class ApiControllerBase<T> : ControllerBase where T : IEntity
|
||||
{
|
||||
protected readonly ICrudLogic<T> logic;
|
||||
@@ -74,6 +76,7 @@ namespace WebAPI.Controllers
|
||||
}
|
||||
|
||||
}
|
||||
[Authorize]
|
||||
public class CombinedKeyApiControllerBase<T> : ControllerBase where T : ICombinedKeyEntity
|
||||
{
|
||||
protected readonly ICombinedKeyCrudLogic<T> logic;
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using Church.Net.DAL.EF;
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Utility;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using QRCoder;
|
||||
using SixLabors.Fonts;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Drawing.Processing;
|
||||
using SixLabors.ImageSharp.Formats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using WebAPI.Logics.Interface;
|
||||
|
||||
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
@@ -61,13 +59,15 @@ namespace WebAPI.Controllers
|
||||
public async Task<IActionResult> GetInvitationQRcode(string id)
|
||||
{
|
||||
|
||||
QRCodeGenerator gen = new QRCodeGenerator();
|
||||
QRCodeGenerator qrGenerator = new QRCodeGenerator();
|
||||
QRCodeData qrCodeData = qrGenerator.CreateQrCode($"http://happiness.tours/invitation/{id}", QRCodeGenerator.ECCLevel.Q);
|
||||
|
||||
QRCodeData qrCodeData = qrGenerator.CreateQrCode($"https://happiness.tours/invitation/{id}", QRCodeGenerator.ECCLevel.Q);
|
||||
QRCode qrCode = new QRCode(qrCodeData);
|
||||
Bitmap qrCodeImage = qrCode.GetGraphic(3);
|
||||
string qrCodeImagePath = ServerUtils.MapPath("App_Data/ScaneMeQrCode.png");
|
||||
var backgroundBitmap = (Bitmap)Bitmap.FromFile(qrCodeImagePath);
|
||||
var qrCodeImage = qrCode.GetGraphic(3);
|
||||
string qrCodeImagePath = "/App_Data/ScaneMeQrCode.png";
|
||||
|
||||
|
||||
var backgroundBitmap = SixLabors.ImageSharp.Image.Load(qrCodeImagePath);
|
||||
//string qrCodeImagePath = Environment.GetEnvironmentVariable("AppData");
|
||||
//HttpContext.Current.Server.MapPath("~/App_Data/");
|
||||
//var fullPath = System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/ScaneMeQrCode.png");
|
||||
@@ -81,9 +81,9 @@ namespace WebAPI.Controllers
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
//fileStream.CopyTo(memoryStream);
|
||||
Bitmap image = Superimpose(best.Name, backgroundBitmap, qrCodeImage, 10, 32);
|
||||
image.Scalling(75).Save(memoryStream, ImageFormat.Png);
|
||||
|
||||
var image = Superimpose(best.Name, backgroundBitmap, qrCodeImage, 10, 32);
|
||||
image.Scalling(75);
|
||||
image.SaveAsPng(memoryStream);
|
||||
byte[] byteImage = memoryStream.ToArray();
|
||||
return File(byteImage, "image/png");
|
||||
}
|
||||
@@ -91,12 +91,16 @@ namespace WebAPI.Controllers
|
||||
|
||||
return this.NotFound();
|
||||
}
|
||||
private Font arialFont;
|
||||
[NonAction]
|
||||
public Bitmap Superimpose(string bestName, Bitmap largeBmp, Bitmap smallBmp, int? x = null, int? y = null)
|
||||
public Image Superimpose(string bestName, Image largeBmp, Image smallBmp, int? x = null, int? y = null)
|
||||
{
|
||||
Graphics g = Graphics.FromImage(largeBmp);
|
||||
g.CompositingMode = CompositingMode.SourceOver;
|
||||
smallBmp.MakeTransparent();
|
||||
FontCollection collection = new();
|
||||
FontFamily family = collection.Add("/App_Data/arial.ttf");
|
||||
arialFont = family.CreateFont(12, FontStyle.Italic);
|
||||
//Graphics g = Graphics.FromImage(largeBmp);
|
||||
//g.CompositingMode = CompositingMode.SourceOver;
|
||||
//smallBmp.MakeTransparent();
|
||||
int margin = 5;
|
||||
if (!x.HasValue)
|
||||
{
|
||||
@@ -109,9 +113,13 @@ namespace WebAPI.Controllers
|
||||
var scale = 0.8;
|
||||
var scaleWidth = (int)(smallBmp.Width * scale);
|
||||
var scaleHeight = (int)(smallBmp.Height * scale);
|
||||
g.DrawImage(smallBmp, new Rectangle(x.Value, y.Value, scaleWidth, scaleHeight));
|
||||
|
||||
g.DrawString(bestName, new Font(new FontFamily("Arial"), 12), new SolidBrush(System.Drawing.Color.Black), 10, 0);
|
||||
|
||||
largeBmp.Mutate(x => x.DrawText(bestName, arialFont, Color.Black, new PointF(10, 10)));
|
||||
|
||||
smallBmp.Scalling(80);
|
||||
|
||||
largeBmp.Mutate(ctx => ctx.DrawImage(smallBmp, new Point(x.Value, y.Value),1f));
|
||||
return largeBmp;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,17 +31,15 @@ namespace WebAPI.Controllers
|
||||
[Route("[controller]/[action]")]
|
||||
public class LineMessageController : ControllerBase
|
||||
{
|
||||
private readonly ChurchNetContext dbContext;
|
||||
private readonly LineAutoBotService lineAutoBotService;
|
||||
private readonly ILoggingService loggingService;
|
||||
|
||||
|
||||
public LineMessageController(ChurchNetContext dbContext,
|
||||
public LineMessageController(
|
||||
LineAutoBotService lineAutoBotService,
|
||||
ILoggingService loggingService
|
||||
)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
this.lineAutoBotService = lineAutoBotService;
|
||||
this.loggingService = loggingService;
|
||||
}
|
||||
@@ -67,7 +65,9 @@ namespace WebAPI.Controllers
|
||||
|
||||
// POST api/<BestController>
|
||||
[HttpPost]
|
||||
public async Task PostFromLine([FromBody] object jsonData)
|
||||
//[Route("[controller]/[action]")]
|
||||
//[Route("[controller]/[action]/{id?}")]
|
||||
public async Task PostFromLine(string id, [FromBody] object jsonData)
|
||||
{
|
||||
//string txtPath = ServerUtils.MapPath("App_Data/LinePostRawLog.txt");
|
||||
|
||||
@@ -76,7 +76,9 @@ namespace WebAPI.Controllers
|
||||
{
|
||||
|
||||
LineWebhookContent content = JsonConvert.DeserializeObject<LineWebhookContent>(jsonData.ToString());
|
||||
await lineAutoBotService.AutoReply(content);
|
||||
|
||||
//this.loggingService.Log("PostFromLine");
|
||||
await lineAutoBotService.AutoReply(content);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -103,14 +105,15 @@ namespace WebAPI.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Task PushCommandMessage(string groupToken,string command)
|
||||
public Task PushCommandMessage(string groupToken, string command)
|
||||
{
|
||||
return lineAutoBotService.PushCommandMessage(EnumHelper.GetEnumValueFromDescription<LineGroup>(groupToken), "#"+ command);
|
||||
return lineAutoBotService.PushCommandMessage(EnumHelper.GetEnumValueFromDescription<LineGroup>(groupToken), "#" + command);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class LineMessage{
|
||||
public class LineMessage
|
||||
{
|
||||
public string To { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using Church.Net.Entity;
|
||||
using LineMessaging;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WebAPI.Logics;
|
||||
using WebAPI.Logics.Interface;
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
{
|
||||
[Route("[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class LineMessagingAccountController : ApiControllerBase<LineMessagingAccount>
|
||||
{
|
||||
public LineMessagingAccountController(LineMessagingAccountLogic logic) : base(logic)
|
||||
{
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public void RefreshAllQuota()
|
||||
{
|
||||
|
||||
foreach (var item in logic.GetAll())
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(item.ChatToken))
|
||||
{
|
||||
var lineMessegeClient = new LineMessagingClient(item.ChatToken);
|
||||
item.TotalUsage = lineMessegeClient.GetTotalUsage().Result;
|
||||
logic.Update(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
using Church.Net.Entity;
|
||||
using Microsoft.AspNetCore.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WebAPI.Logics.Interface;
|
||||
using WebAPI.Services.Interfaces;
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
{
|
||||
@@ -12,13 +15,46 @@ namespace WebAPI.Controllers
|
||||
[ApiController]
|
||||
public class LogController : ApiControllerBase<LogInfo>
|
||||
{
|
||||
public LogController(ICrudLogic<LogInfo> logic) : base(logic)
|
||||
private readonly ILoggingService loggingService;
|
||||
|
||||
public LogController(
|
||||
ICrudLogic<LogInfo> logic,
|
||||
ILoggingService loggingService
|
||||
) : base(logic)
|
||||
{
|
||||
this.loggingService = loggingService;
|
||||
}
|
||||
[HttpPost]
|
||||
public void PurgeBefore([FromBody] DateTime date)
|
||||
{
|
||||
logic.Delete(l => l.Time <= date.ToUniversalTime());
|
||||
}
|
||||
|
||||
[Route("/error-development")]
|
||||
public IActionResult HandleErrorDevelopment(
|
||||
[FromServices] IHostEnvironment hostEnvironment)
|
||||
{
|
||||
if (!hostEnvironment.IsDevelopment())
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var exceptionHandlerFeature =
|
||||
HttpContext.Features.Get<IExceptionHandlerFeature>()!;
|
||||
this.loggingService.Error(exceptionHandlerFeature.Error, exceptionHandlerFeature.Path);
|
||||
return Problem(
|
||||
detail: exceptionHandlerFeature.Error.StackTrace,
|
||||
title: exceptionHandlerFeature.Error.Message);
|
||||
}
|
||||
|
||||
[Route("/error")]
|
||||
public IActionResult HandleError()
|
||||
{
|
||||
|
||||
var exceptionHandlerFeature =
|
||||
HttpContext.Features.Get<IExceptionHandlerFeature>()!;
|
||||
this.loggingService.Error(exceptionHandlerFeature.Error, exceptionHandlerFeature.Path);
|
||||
return Problem();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Church.Net.DAL.EF;
|
||||
using Church.Net.DAL.EFCoreDBF;
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Utility;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -28,17 +29,16 @@ namespace WebAPI.Controllers
|
||||
|
||||
// POST api/<PasswordLoginController>
|
||||
public PasswordLoginController(
|
||||
ChurchNetContext churchNetContext,
|
||||
ICrudLogic<FamilyMember> crudLogic,
|
||||
ICombinedKeyCrudLogic<PastoralDomainMembers> relationLogic,
|
||||
ICrudLogic<PastoralDomain> domainLogic
|
||||
|
||||
ICrudLogic<PastoralDomain> domainLogic,
|
||||
DatabaseOptions databaseOptions
|
||||
)
|
||||
{
|
||||
this.churchNetContext = churchNetContext;
|
||||
this.crudLogic = crudLogic;
|
||||
this.relationLogic = relationLogic;
|
||||
this.domainLogic = domainLogic;
|
||||
churchNetContext = databaseOptions.GetDbContext();
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("auth/login")]
|
||||
|
||||
@@ -68,14 +68,14 @@ namespace WebAPI.Controllers
|
||||
bool isGet = methodInfo.GetCustomAttributes(typeof(HttpGetAttribute), false).Length > 0;
|
||||
bool isPost = methodInfo.GetCustomAttributes(typeof(HttpPostAttribute), false).Length > 0;
|
||||
bool isDelete = methodInfo.GetCustomAttributes(typeof(HttpDeleteAttribute), false).Length > 0;
|
||||
if(isGet|| isPost|| isDelete)
|
||||
if (isGet || isPost || isDelete)
|
||||
{
|
||||
|
||||
Endpoint _endpoint = new Endpoint
|
||||
{
|
||||
Name = methodInfo.Name,
|
||||
Method = isGet ? "GET" : (isPost ? "POST" : (isDelete ? "DELETE" : "UNKNOWN")),
|
||||
Inputs = methodInfo.GetParameters().Select(m=>new Input() { Name=m.Name}).ToArray(),
|
||||
Inputs = methodInfo.GetParameters().Select(m => new Input() { Name = m.Name }).ToArray(),
|
||||
ReturnType = methodInfo.ReturnType,
|
||||
//MethodInfo = methodInfo,
|
||||
};
|
||||
@@ -92,7 +92,7 @@ namespace WebAPI.Controllers
|
||||
}
|
||||
return _controllers;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public async void TestMessage()
|
||||
{
|
||||
@@ -112,7 +112,7 @@ namespace WebAPI.Controllers
|
||||
Uri = "https://happiness.tours/CellGroup/prayer?openExternalBrowser=1",
|
||||
Label = "Prayer"
|
||||
};
|
||||
templateMessage.AltText= "代禱事項";
|
||||
templateMessage.AltText = "代禱事項";
|
||||
|
||||
templateMessage.Template.DefaultAction = addPrayerBtn;
|
||||
templateMessage.Template.ThumbnailImageUrl = "https://dailyverses.net/images/tc/cuv/matthew-21-22-3.jpg";
|
||||
@@ -120,11 +120,11 @@ namespace WebAPI.Controllers
|
||||
templateMessage.Template.Title = "代禱事項";
|
||||
|
||||
templateMessage.Template.Text = "Chris" + Environment.NewLine + "Testwerewiorjowerjiowejiro, erjaiworjweiorjioawereaw";
|
||||
|
||||
|
||||
|
||||
templateMessage.Template.Actions = new List<ILineAction>();
|
||||
templateMessage.Template.Actions.Add(addPrayerBtn);
|
||||
await test.PushMessage(EnumHelper.EnumToDescriptionString(LineGroup.Chris), textMessage);
|
||||
await test.PushMessage(EnumHelper.EnumToDescriptionString(LineGroup.Chris), textMessage);
|
||||
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace WebAPI.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
// ReplyTextMessage(replyToken, autoReply.ReplyMessage);
|
||||
// ReplyTextMessage(replyToken, autoReply.ReplyMessage);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -162,6 +162,14 @@ namespace WebAPI.Controllers
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public string[] GetFiles(string path)
|
||||
{
|
||||
return Directory.GetFiles("/App_Data/" + path);
|
||||
}
|
||||
public class Controller
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user