120 lines
3.8 KiB
C#
120 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
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 LineMessaging;
|
|
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json;
|
|
using System.Text;
|
|
using WebAPI.Services;
|
|
using Jint.Native;
|
|
using WebAPI.Services.Interfaces;
|
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
|
|
|
namespace WebAPI.Controllers
|
|
{
|
|
//[Route("[controller]")]
|
|
[ApiController]
|
|
[Route("[controller]/[action]")]
|
|
public class LineMessageController : ControllerBase
|
|
{
|
|
private readonly ChurchNetContext dbContext;
|
|
private readonly LineAutoBotService lineAutoBotService;
|
|
private readonly ILoggingService loggingService;
|
|
|
|
|
|
public LineMessageController(ChurchNetContext dbContext,
|
|
LineAutoBotService lineAutoBotService,
|
|
ILoggingService loggingService
|
|
)
|
|
{
|
|
this.dbContext = dbContext;
|
|
this.lineAutoBotService = lineAutoBotService;
|
|
this.loggingService = loggingService;
|
|
}
|
|
//private ChurchNetContext dbContext = new ChurchNetContext();
|
|
//// GET: api/<BestController>
|
|
//[HttpGet]
|
|
//public IEnumerable<string> Get()
|
|
//{
|
|
// return new string[] { "value2222", "value4" };
|
|
//}
|
|
|
|
//// GET api/<BestController>/5
|
|
//[HttpGet("{id}")]
|
|
//public HappinessBEST Get(string id)
|
|
//{
|
|
// var best = dbContext.HappinessBESTs.Include(b => b.HappinessGroup).ThenInclude(b => b.Weeks).FirstOrDefault(b => b.BestId == id);
|
|
|
|
// best.HappinessGroup.Weeks = best.HappinessGroup.Weeks.OrderBy(w => w.SEQ).ToList();
|
|
|
|
// return best;
|
|
//}
|
|
|
|
|
|
// POST api/<BestController>
|
|
[HttpPost]
|
|
public async Task PostFromLine([FromBody] object jsonData)
|
|
{
|
|
//string txtPath = ServerUtils.MapPath("App_Data/LinePostRawLog.txt");
|
|
|
|
//System.IO.File.AppendAllText(txtPath, JsonConvert.SerializeObject(jsonData.ToString(), Formatting.Indented));
|
|
try
|
|
{
|
|
|
|
LineWebhookContent content = JsonConvert.DeserializeObject<LineWebhookContent>(jsonData.ToString());
|
|
await lineAutoBotService.AutoReply(content);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.loggingService.Error(ex);
|
|
}
|
|
//Cac4ac5a8d7fc52daa444d71dc7c360a9 方舟小組 GroupID
|
|
//Ca20e3b65aa58e676815eb13c3222591a 方舟小組同工 GroupID
|
|
|
|
|
|
|
|
//var test = new LineMessaging.();
|
|
//var test = new LineMessagingClient("WFAyMvMEZ86cfMJIAzE+yklUZGpeS/jFYTeL9a9O35QR83oNMmwaUJfyEe48Kegadz0BArDdBoySxs479U1pwTHtlyH+Sm4jqlz8BwukX/Hsa4D1fX03Qn4zFu7TwPFKWFXnZbWq89Yg0iNzjpfTNwdB04t89/1O/w1cDnyilFU=");
|
|
//test.PushMessage(value.To, new LineTextMessage() { Text = value.Message });
|
|
|
|
}
|
|
|
|
|
|
[HttpPut("{id}")]
|
|
public async void PushTextMessage(string id, [FromBody] LineMessage value)
|
|
{
|
|
var test = new LineMessagingClient();
|
|
await test.PushMessage(id, new LineTextMessage() { Text = value.Message });
|
|
|
|
}
|
|
|
|
[HttpGet]
|
|
public Task PushCommandMessage(string groupToken,string command)
|
|
{
|
|
return lineAutoBotService.PushCommandMessage(EnumHelper.GetEnumValueFromDescription<LineGroup>(groupToken), "#"+ command);
|
|
}
|
|
|
|
}
|
|
|
|
public class LineMessage{
|
|
public string To { get; set; }
|
|
public string Message { get; set; }
|
|
}
|
|
|
|
|
|
}
|