mirror of
https://github.com/oshima-studios/OshimaGameModule.git
synced 2025-04-20 10:59:33 +08:00
新增绑定
This commit is contained in:
parent
bd71391d67
commit
52baf4ecc2
@ -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("绑定失败,请稍后再试。");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<string> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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<bool> Handler(GroupAtMessage? groupAt = null, C2CMessage? c2c = null)
|
||||
public async Task<bool> 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 页)
|
||||
|
Loading…
x
Reference in New Issue
Block a user