diff --git a/OshimaWebAPI/Controllers/FunGameController.cs b/OshimaWebAPI/Controllers/FunGameController.cs index 57bbee2..219d841 100644 --- a/OshimaWebAPI/Controllers/FunGameController.cs +++ b/OshimaWebAPI/Controllers/FunGameController.cs @@ -13,7 +13,6 @@ using Oshima.Core.Configs; using Oshima.FunGame.OshimaModules.Characters; using Oshima.FunGame.OshimaModules.Items; using Oshima.FunGame.OshimaServers.Service; -using Oshima.FunGame.WebAPI.Models; namespace Oshima.FunGame.WebAPI.Controllers { @@ -4788,17 +4787,5 @@ namespace Oshima.FunGame.WebAPI.Controllers } return NetworkUtility.JsonSerialize("提供的参数不正确。"); } - - [HttpPost("post")] - public string PostName([FromBody] string name) - { - return NetworkUtility.JsonSerialize($"Your Name received successfully: {name}."); - } - - [HttpPost("bind")] - public string Post([FromBody] BindQQ b) - { - return NetworkUtility.JsonSerialize("绑定失败,请稍后再试。"); - } } } diff --git a/OshimaWebAPI/Controllers/QQBotController.cs b/OshimaWebAPI/Controllers/QQBotController.cs index d3c8777..d69c22a 100644 --- a/OshimaWebAPI/Controllers/QQBotController.cs +++ b/OshimaWebAPI/Controllers/QQBotController.cs @@ -1,6 +1,7 @@ using System.Globalization; using System.Text; using System.Text.Json; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -174,5 +175,33 @@ namespace Oshima.FunGame.WebAPI.Controllers return StatusCode(500, "服务器内部错误"); } } + + [Authorize(AuthenticationSchemes = "CustomBearer")] + [HttpPost("thirdparty")] + public async Task ThirdParty([FromBody] ThirdPartyMessage? msg = null) + { + if (msg is null) return ""; + + if (await FungameService.Handler(third: msg)) + { + int time = 0; + int timeout = 8 * 1000; + while (true) + { + await Task.Delay(200); + time += 200; + if (time >= timeout) + { + break; + } + if (msg.IsCompleted) + { + break; + } + } + } + + return NetworkUtility.JsonSerialize(msg.Result); + } } } diff --git a/OshimaWebAPI/Models/QQBot.cs b/OshimaWebAPI/Models/QQBot.cs index d15e2a8..438a268 100644 --- a/OshimaWebAPI/Models/QQBot.cs +++ b/OshimaWebAPI/Models/QQBot.cs @@ -83,6 +83,33 @@ namespace Oshima.FunGame.WebAPI.Models public string OpenId { get; } public string AuthorOpenId { get; } } + + public class ThirdPartyMessage : IBotMessage + { + [JsonPropertyName("id")] + public string Id { get; set; } = ""; + + [JsonPropertyName("isgroup")] + public bool IsGroup { get; set; } = false; + + [JsonPropertyName("detail")] + public string Detail { get; set; } = ""; + + [JsonPropertyName("timestamp")] + public string Timestamp { get; set; } = ""; + + [JsonPropertyName("openid")] + public string OpenId { get; set; } = ""; + + [JsonPropertyName("authoropenid")] + public string AuthorOpenId { get; set; } = ""; + + [JsonIgnore] + public bool IsCompleted { get; set; } = false; + + [JsonIgnore] + public string Result { get; set; } = ""; + } public class C2CMessage : IBotMessage { diff --git a/OshimaWebAPI/Services/RainBOTService.cs b/OshimaWebAPI/Services/RainBOTService.cs index 0e692c0..8ddc528 100644 --- a/OshimaWebAPI/Services/RainBOTService.cs +++ b/OshimaWebAPI/Services/RainBOTService.cs @@ -25,6 +25,12 @@ namespace Oshima.FunGame.WebAPI.Services private async Task SendAsync(IBotMessage msg, string title, string content, int msgType = 0, object? media = null, int? msgSeq = null) { Statics.RunningPlugin?.Controller.WriteLine(title, Milimoe.FunGame.Core.Library.Constant.LogLevel.Debug); + if (msg is ThirdPartyMessage third) + { + third.IsCompleted = true; + third.Result = content; + return; + } if (msg.IsGroup) { await Service.SendGroupMessageAsync(msg.OpenId, content, msgType, media, msg.Id, msgSeq); @@ -36,7 +42,7 @@ namespace Oshima.FunGame.WebAPI.Services } } - public async Task Handler(GroupAtMessage? groupAt = null, C2CMessage? c2c = null) + public async Task Handler(GroupAtMessage? groupAt = null, C2CMessage? c2c = null, ThirdPartyMessage? third = null) { bool result = true; try @@ -100,6 +106,12 @@ namespace Oshima.FunGame.WebAPI.Services // await SendAsync(e, "绑定", msg); //} + if (!e.IsGroup && e.Detail == "获取接入码") + { + await SendAsync(e, "获取接入码", $"你的接入码为 {openid},请妥善保存!"); + return true; + } + if (e.Detail == "帮助" || e.Detail == "帮助1") { await SendAsync(e, "饭给木", @"《饭给木》游戏指令列表(第 1 / 7 页)