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; using Church.Net.DAL.EFCoreDBF.Migrations; using Church.Net.DAL.EFCoreDBF; // 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 LineAutoBotService lineAutoBotService; private readonly ILoggingService loggingService; private readonly ICrudDAL crudDAL; public LineMessageController( LineAutoBotService lineAutoBotService, ILoggingService loggingService, ICrudDAL crudDAL ) { this.lineAutoBotService = lineAutoBotService; this.loggingService = loggingService; this.crudDAL = crudDAL; } //private ChurchNetContext dbContext = new ChurchNetContext(); //// GET: api/ //[HttpGet] //public IEnumerable Get() //{ // return new string[] { "value2222", "value4" }; //} //// GET api//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/ [HttpPost] public async Task PostFromLine(int seq, [FromBody] object jsonData) { //string txtPath = ServerUtils.MapPath("App_Data/LinePostRawLog.txt"); //System.IO.File.AppendAllText(txtPath, JsonConvert.SerializeObject(jsonData.ToString(), Formatting.Indented)); try { LineMessagingAccount lineAccount = crudDAL.GetAll(l => l.Seq == seq).FirstOrDefault(); if (lineAccount != null) { LineWebhookContent content = JsonConvert.DeserializeObject(jsonData.ToString()); await lineAutoBotService.AutoReply(lineAccount,content); } //this.loggingService.Log("PostFromLine"); } 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(groupToken), "#" + command); //} } public class LineMessage { public string To { get; set; } public string Message { get; set; } } }